可以解析更多的tool call模式
This commit is contained in:
@@ -1005,12 +1005,11 @@ def parse_react_to_tool_call(text, available_tools, skill_manager, messages=None
|
||||
if match:
|
||||
skip_react = True
|
||||
tool_call = match.group(1)
|
||||
arguments = match.group(2)
|
||||
arguments = json.loads(match.group(2))
|
||||
tool_name = tool_call
|
||||
print(f"Tool Call: {tool_call}")
|
||||
print(f"Arguments: {arguments}")
|
||||
tmp = {tool_call: arguments}
|
||||
tool_input_str = json.dumps(tmp)
|
||||
tool_input_str = json.dumps(arguments)
|
||||
# skip_react = False
|
||||
except Exception as e:
|
||||
print(f" JSON parsing error: {e}")
|
||||
@@ -1252,7 +1251,9 @@ def parse_react_to_tool_call(text, available_tools, skill_manager, messages=None
|
||||
|
||||
# ========== 8. 检查是否是技能调用 ==========
|
||||
|
||||
installed_skills = skill_manager
|
||||
installed_skills = []
|
||||
for skill in skill_manager:
|
||||
installed_skills.append(skill['name'])
|
||||
|
||||
print(f" Installed skills: {installed_skills}")
|
||||
|
||||
@@ -1418,15 +1419,26 @@ def build_system_prompt(tools, skill_manager):
|
||||
desc = desc[:200] + "..."
|
||||
tool_descriptions.append(f"- {name}: {desc}")
|
||||
|
||||
|
||||
|
||||
# 获取已安装的 Skills(使用文件系统检查)
|
||||
|
||||
# 构建技能说明
|
||||
|
||||
skill_list = []
|
||||
for skill in skill_manager:
|
||||
skill_list.append(skill['name'])
|
||||
|
||||
description = skill['description']
|
||||
if len(description) > 200:
|
||||
description = description[:200] + '...'
|
||||
|
||||
tool_descriptions.append(f"- {skill['name']}: {description}")
|
||||
|
||||
skills_instruction = f"""
|
||||
**How to use installed skills:**
|
||||
You have access to the following installed skills:
|
||||
{chr(10).join(skill_manager)}
|
||||
{chr(10).join(skill_list)}
|
||||
|
||||
To use a skill, you MUST use the 'invoke_skill' tool with this exact format:
|
||||
Action: invoke_skill
|
||||
@@ -1592,7 +1604,7 @@ def chat_completions():
|
||||
print(f"Installed skills: {installed_skills}")
|
||||
|
||||
# ========== 构建系统提示 ==========
|
||||
system_prompt = build_system_prompt(tools, installed_skills)
|
||||
system_prompt = build_system_prompt(tools, ready_skills)
|
||||
|
||||
# ========== 构建输入 Prompt(带 token 管理) ==========
|
||||
input_prompt = conv_manager.build_prompt(messages, system_prompt, safe_get_content)
|
||||
@@ -1659,7 +1671,7 @@ def chat_completions():
|
||||
skill_list.append(skill['name'])
|
||||
|
||||
# ========== 解析响应 ==========
|
||||
parsed = parse_react_to_tool_call(accumulated_text, available_tools, skill_list)
|
||||
parsed = parse_react_to_tool_call(accumulated_text, available_tools, ready_skills)
|
||||
|
||||
# 检查是否模型输出了说明文字而不是工具调用
|
||||
if "以下是修正后的正确调用方式" in accumulated_text or "正确的工具调用应包含" in accumulated_text:
|
||||
|
||||
Reference in New Issue
Block a user