Introduced a static method to compact identifiers for improved fuzzy matching of tool names, allowing for more flexible user input. Updated the tool name extraction logic to support matching without underscores or dots, enhancing the tool invocation capabilities. Added a corresponding test to validate the new functionality.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""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
|