Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tool_inputs parse error in message that in CoT(ReAct) agent mode #2949

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/core/features/assistant_base_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,11 @@ def organize_agent_history(self, prompt_messages: list[PromptMessage]) -> list[P
tools = tools.split(';')
tool_calls: list[AssistantPromptMessage.ToolCall] = []
tool_call_response: list[ToolPromptMessage] = []
tool_inputs = json.loads(agent_thought.tool_input)
try:
tool_inputs = json.loads(agent_thought.tool_input)
except Exception as e:
logging.warning("tool execution error: {}, tool_input: {}.".format(str(e), agent_thought.tool_input))
tool_inputs = { agent_thought.tool: agent_thought.tool_input }
for tool in tools:
# generate a uuid for tool call
tool_call_id = str(uuid.uuid4())
Expand Down Expand Up @@ -599,4 +603,4 @@ def organize_agent_history(self, prompt_messages: list[PromptMessage]) -> list[P

db.session.close()

return result
return result
4 changes: 2 additions & 2 deletions api/core/features/assistant_cot_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def increase_usage(final_llm_usage_dict: dict[str, LLMUsage], usage: LLMUsage):
delta=LLMResultChunkDelta(
index=0,
message=AssistantPromptMessage(
content=json.dumps(chunk)
content=json.dumps(chunk, ensure_ascii=False) # if ensure_ascii=True, the text in webui maybe garbled text
),
usage=None
)
Expand Down Expand Up @@ -667,4 +667,4 @@ def _jsonify_tool_prompt_messages(self, tools: list[PromptMessageTool]) -> str:
try:
return json.dumps(tools, ensure_ascii=False)
except json.JSONDecodeError:
return json.dumps(tools)
return json.dumps(tools)