Spaces:
Paused
Paused
Adibvafa commited on
Commit ·
530a475
1
Parent(s): 31c8268
Dont directly eval tool call
Browse files- interface.py +8 -7
interface.py
CHANGED
|
@@ -184,18 +184,19 @@ class ChatInterface:
|
|
| 184 |
pending_call = self.pending_tool_calls.pop(tool_call_id)
|
| 185 |
tool_name = pending_call["name"]
|
| 186 |
tool_args = pending_call["args"]
|
| 187 |
-
|
| 188 |
# Parse content
|
| 189 |
try:
|
| 190 |
-
# Try
|
| 191 |
-
|
| 192 |
-
result = content_tuple[0]
|
| 193 |
tool_output_str = json.dumps(result, indent=2)
|
| 194 |
-
except
|
| 195 |
try:
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
tool_output_str = json.dumps(result, indent=2)
|
| 198 |
-
except
|
|
|
|
| 199 |
result = msg.content
|
| 200 |
tool_output_str = str(msg.content)
|
| 201 |
|
|
|
|
| 184 |
pending_call = self.pending_tool_calls.pop(tool_call_id)
|
| 185 |
tool_name = pending_call["name"]
|
| 186 |
tool_args = pending_call["args"]
|
|
|
|
| 187 |
# Parse content
|
| 188 |
try:
|
| 189 |
+
# Try JSON parsing first
|
| 190 |
+
result = json.loads(msg.content)
|
|
|
|
| 191 |
tool_output_str = json.dumps(result, indent=2)
|
| 192 |
+
except json.JSONDecodeError:
|
| 193 |
try:
|
| 194 |
+
# Use ast.literal_eval as safe fallback for Python literals
|
| 195 |
+
content_tuple = ast.literal_eval(msg.content)
|
| 196 |
+
result = content_tuple[0]
|
| 197 |
tool_output_str = json.dumps(result, indent=2)
|
| 198 |
+
except (ValueError, SyntaxError):
|
| 199 |
+
# Fall back to treating as plain string
|
| 200 |
result = msg.content
|
| 201 |
tool_output_str = str(msg.content)
|
| 202 |
|