This commit is contained in:
Tachyu 2025-03-21 13:44:59 +08:00 committed by GitHub
commit 54db8b790d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -341,7 +341,27 @@ class FunctionCallAgentRunner(BaseAgentRunner):
for prompt_message in llm_result_chunk.delta.message.tool_calls:
args = {}
if prompt_message.function.arguments != "":
args = json.loads(prompt_message.function.arguments)
try_load_str = prompt_message.function.arguments
while True:
if len(try_load_str) == 0:
break
try:
args = json.loads(try_load_str)
break
except Exception as e:
logging.error("error try_load_str: " + try_load_str)
first_left_brace_index = try_load_str.find("{")
if len(try_load_str) >= first_left_brace_index + 1:
try_load_str = try_load_str[try_load_str.find("{") + 1 :]
# find next left brace
next_left_brace_index = try_load_str.find("{")
if next_left_brace_index == -1:
logging.error("error try_load_str not found next left brace: " + try_load_str)
break
try_load_str = try_load_str[next_left_brace_index:]
else:
logging.error("error try_load_str not found next left brace: " + try_load_str)
break
tool_calls.append(
(