Spaces:
Running
Running
Update tools_service.py
Browse files- tools_service.py +21 -2
tools_service.py
CHANGED
|
@@ -86,10 +86,29 @@ QUAN TR峄孨G:
|
|
| 86 |
|
| 87 |
tool_call = json.loads(json_str)
|
| 88 |
|
| 89 |
-
# Handle
|
|
|
|
|
|
|
| 90 |
# {"name": "tool_call", "arguments": {"tool_call": true, ...}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
if "name" in tool_call and "arguments" in tool_call:
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Validate tool call structure
|
| 95 |
if not tool_call.get("tool_call"):
|
|
|
|
| 86 |
|
| 87 |
tool_call = json.loads(json_str)
|
| 88 |
|
| 89 |
+
# Handle multiple JSON formats from LLM
|
| 90 |
+
|
| 91 |
+
# Format 1: HF API nested wrapper
|
| 92 |
# {"name": "tool_call", "arguments": {"tool_call": true, ...}}
|
| 93 |
+
if "name" in tool_call and "arguments" in tool_call and isinstance(tool_call["arguments"], dict):
|
| 94 |
+
if "tool_call" in tool_call["arguments"]:
|
| 95 |
+
tool_call = tool_call["arguments"] # Unwrap
|
| 96 |
+
|
| 97 |
+
# Format 2: Direct tool name format
|
| 98 |
+
# {"name": "tool.get_event_details", "arguments": {"event_code": "..."}}
|
| 99 |
if "name" in tool_call and "arguments" in tool_call:
|
| 100 |
+
function_name = tool_call["name"]
|
| 101 |
+
# Remove "tool." prefix if exists
|
| 102 |
+
if function_name.startswith("tool."):
|
| 103 |
+
function_name = function_name.replace("tool.", "")
|
| 104 |
+
|
| 105 |
+
# Convert to standard format
|
| 106 |
+
tool_call = {
|
| 107 |
+
"tool_call": True,
|
| 108 |
+
"function_name": function_name,
|
| 109 |
+
"arguments": tool_call["arguments"],
|
| 110 |
+
"reason": "Converted from alternate format"
|
| 111 |
+
}
|
| 112 |
|
| 113 |
# Validate tool call structure
|
| 114 |
if not tool_call.get("tool_call"):
|