fix: llmcore工具调用正则兼容tool_call标签,最小长度改为0
This commit is contained in:
2
ga.py
2
ga.py
@@ -388,7 +388,7 @@ class GenericAgentHandler(BaseHandler):
|
|||||||
|
|
||||||
blocks = extract_robust_content(response.content)
|
blocks = extract_robust_content(response.content)
|
||||||
if not blocks:
|
if not blocks:
|
||||||
yield f"[Status] ❌ 失败: 未在回复中找到代码块内容\n"
|
yield f"[Status] ❌ 失败: 未在回复中找到<file_content>代码块内容\n"
|
||||||
return StepOutcome({"status": "error", "msg": "No content found, if you want a blank, you should use code_run"}, next_prompt="\n")
|
return StepOutcome({"status": "error", "msg": "No content found, if you want a blank, you should use code_run"}, next_prompt="\n")
|
||||||
try:
|
try:
|
||||||
new_content = expand_file_refs(blocks, base_dir=self.cwd)
|
new_content = expand_file_refs(blocks, base_dir=self.cwd)
|
||||||
|
|||||||
@@ -748,7 +748,7 @@ class ToolClient:
|
|||||||
remaining_text = re.sub(think_pattern, "", remaining_text, flags=re.DOTALL)
|
remaining_text = re.sub(think_pattern, "", remaining_text, flags=re.DOTALL)
|
||||||
|
|
||||||
tool_calls = []; json_strs = []; errors = []
|
tool_calls = []; json_strs = []; errors = []
|
||||||
tool_pattern = r"<tool_use>((?:(?!<tool_use>).){15,}?)</tool_use>"
|
tool_pattern = r"<(?:tool_use|tool_call)>((?:(?!<(?:tool_use|tool_call)>).){0,}?)</(?:tool_use|tool_call)>"}
|
||||||
tool_all = re.findall(tool_pattern, remaining_text, re.DOTALL)
|
tool_all = re.findall(tool_pattern, remaining_text, re.DOTALL)
|
||||||
|
|
||||||
if tool_all:
|
if tool_all:
|
||||||
@@ -764,9 +764,9 @@ class ToolClient:
|
|||||||
json_strs.append(json_str)
|
json_strs.append(json_str)
|
||||||
remaining_text = remaining_text.replace('<tool_use>'+weaktoolstr, "")
|
remaining_text = remaining_text.replace('<tool_use>'+weaktoolstr, "")
|
||||||
elif '"name":' in remaining_text and '"arguments":' in remaining_text:
|
elif '"name":' in remaining_text and '"arguments":' in remaining_text:
|
||||||
json_match = re.search(r"(\{.*\"name\":.*?\})", remaining_text, re.DOTALL | re.MULTILINE)
|
json_match = re.search(r'\{.*"name":.*\}', remaining_text, re.DOTALL)
|
||||||
if json_match:
|
if json_match:
|
||||||
json_str = json_match.group(1).strip()
|
json_str = json_match.group(0).strip()
|
||||||
json_strs.append(json_str)
|
json_strs.append(json_str)
|
||||||
remaining_text = remaining_text.replace(json_str, "").strip()
|
remaining_text = remaining_text.replace(json_str, "").strip()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user