Files
QQbot/tests/test_ai_client_forced_tool.py
Mimikko-zeus 726d41ad79 Enhance AIClient with skill document processing capabilities
Added a new method to run a skill document pipeline, allowing for enhanced processing of user messages based on specified skill documents. Implemented logic to extract relevant text from user messages and improved error handling during processing. Updated message handling to strip URLs from responses to prevent issues with message delivery. Added tests to validate the new processing functionality and ensure robustness.
2026-03-03 14:57:26 +08:00

74 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tests for AIClient forced tool name extraction."""
from src.ai.client import AIClient
def test_extract_forced_tool_name_full_name():
tools = [
"humanizer_zh.read_skill_doc",
"skills_creator.create_skill",
]
message = "please call tool humanizer_zh.read_skill_doc and return first 100 chars"
forced = AIClient._extract_forced_tool_name(message, tools)
assert forced == "humanizer_zh.read_skill_doc"
def test_extract_forced_tool_name_unique_prefix():
tools = [
"humanizer_zh.read_skill_doc",
"skills_creator.create_skill",
]
message = "please call tool humanizer_zh only"
forced = AIClient._extract_forced_tool_name(message, tools)
assert forced == "humanizer_zh.read_skill_doc"
def test_extract_forced_tool_name_compact_prefix_without_underscore():
tools = [
"humanizer_zh.read_skill_doc",
"skills_creator.create_skill",
]
message = "调用humanizerzh人性化处理以下文本"
forced = AIClient._extract_forced_tool_name(message, tools)
assert forced == "humanizer_zh.read_skill_doc"
def test_extract_forced_tool_name_ambiguous_prefix_returns_none():
tools = [
"skills_creator.create_skill",
"skills_creator.reload_skill",
]
message = "please call tool skills_creator"
forced = AIClient._extract_forced_tool_name(message, tools)
assert forced is None
def test_extract_prefix_limit_from_user_message():
assert AIClient._extract_prefix_limit("直接返回前100字") == 100
assert AIClient._extract_prefix_limit("前 256 字") == 256
assert AIClient._extract_prefix_limit("返回全文") is None
def test_extract_processing_payload_with_marker():
message = "调用humanizer_zh.read_skill_doc人性化处理以下文本\n第一段。\n第二段。"
payload = AIClient._extract_processing_payload(message)
assert payload == "第一段。\n第二段。"
def test_extract_processing_payload_with_generic_pattern():
message = "请按技能规则优化如下:\n这是待处理文本。"
payload = AIClient._extract_processing_payload(message)
assert payload == "这是待处理文本。"
def test_extract_processing_payload_returns_none_when_absent():
assert AIClient._extract_processing_payload("请调用工具 humanizer_zh.read_skill_doc") is None