Skip to content

Commit

Permalink
[Improvement] Allow tool calls without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
amidabuddha committed Feb 28, 2025
1 parent d964dfe commit 4953721
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions console_gpt/unichat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,19 @@ def handle_streaming_response(model_name, response_stream, conversation):
if current_assistant_message.get("tool_calls"):
for tool_call in current_assistant_message["tool_calls"]:
tool_name = tool_call["function"]["name"]
function_arguments = tool_call["function"]["arguments"]
if function_arguments:
tool_arguments = json.loads(function_arguments)
else:
tool_arguments = {}
print(tool_name, tool_arguments)
markdown_print(f"> Triggered: `{tool_name}`.")
try:
with MCPClient() as mcp:
result = {
"role": "tool",
"content": str(
mcp.call_tool(tool_call["function"]["name"], json.loads(tool_call["function"]["arguments"]))
mcp.call_tool(tool_name, tool_arguments)
),
"tool_call_id": tool_call["id"],
}
Expand Down Expand Up @@ -163,13 +169,18 @@ def handle_non_streaming_response(model_name, response, conversation):
if tool_calls:
for tool_call in assistant_response.get("tool_calls"):
tool_name = tool_call["function"]["name"]
function_arguments = tool_call["function"]["arguments"]
if function_arguments:
tool_arguments = json.loads(function_arguments)
else:
tool_arguments = {}
markdown_print(f"> Triggered: `{tool_name}`.")
try:
with MCPClient() as mcp:
result = {
"role": "tool",
"content": str(
mcp.call_tool(tool_call["function"]["name"], json.loads(tool_call["function"]["arguments"]))
mcp.call_tool(tool_name, tool_arguments)
),
"tool_call_id": tool_call["id"],
}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unichat~=3.5.3
unichat~=3.5.4
pillow~=10.3.0
questionary~=2.0.1
rich~=13.7.0
Expand Down

0 comments on commit 4953721

Please sign in to comment.