Adibvafa
commited on
Commit
·
5f1cf99
1
Parent(s):
91834f9
Fix interface bugs
Browse files- interface.py +25 -10
interface.py
CHANGED
|
@@ -193,12 +193,17 @@ class ChatInterface:
|
|
| 193 |
|
| 194 |
# Parse content
|
| 195 |
try:
|
|
|
|
| 196 |
content_tuple = eval(msg.content)
|
| 197 |
result = content_tuple[0]
|
| 198 |
tool_output_str = json.dumps(result, indent=2)
|
| 199 |
-
except (
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
# Display tool usage card
|
| 204 |
tool_args_str = json.dumps(tool_args, indent=2)
|
|
@@ -217,14 +222,24 @@ class ChatInterface:
|
|
| 217 |
)
|
| 218 |
|
| 219 |
# Special handling for image_visualizer
|
| 220 |
-
if tool_name == "image_visualizer"
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
)
|
| 227 |
-
)
|
| 228 |
|
| 229 |
# Yield a single update for this tool event
|
| 230 |
yield chat_history, self.display_file_path, ""
|
|
|
|
| 193 |
|
| 194 |
# Parse content
|
| 195 |
try:
|
| 196 |
+
# Try eval first for Python tuples
|
| 197 |
content_tuple = eval(msg.content)
|
| 198 |
result = content_tuple[0]
|
| 199 |
tool_output_str = json.dumps(result, indent=2)
|
| 200 |
+
except (ValueError, NameError):
|
| 201 |
+
try:
|
| 202 |
+
result = json.loads(msg.content)
|
| 203 |
+
tool_output_str = json.dumps(result, indent=2)
|
| 204 |
+
except json.JSONDecodeError:
|
| 205 |
+
result = msg.content
|
| 206 |
+
tool_output_str = str(msg.content)
|
| 207 |
|
| 208 |
# Display tool usage card
|
| 209 |
tool_args_str = json.dumps(tool_args, indent=2)
|
|
|
|
| 222 |
)
|
| 223 |
|
| 224 |
# Special handling for image_visualizer
|
| 225 |
+
if tool_name == "image_visualizer":
|
| 226 |
+
image_path = None
|
| 227 |
+
try:
|
| 228 |
+
image_path = result["image_path"]
|
| 229 |
+
except (TypeError, KeyError):
|
| 230 |
+
try:
|
| 231 |
+
image_path = result[0]["image_path"]
|
| 232 |
+
except (TypeError, KeyError, IndexError):
|
| 233 |
+
pass
|
| 234 |
+
|
| 235 |
+
if image_path:
|
| 236 |
+
self.display_file_path = image_path
|
| 237 |
+
chat_history.append(
|
| 238 |
+
ChatMessage(
|
| 239 |
+
role="assistant",
|
| 240 |
+
content={"path": self.display_file_path},
|
| 241 |
+
)
|
| 242 |
)
|
|
|
|
| 243 |
|
| 244 |
# Yield a single update for this tool event
|
| 245 |
yield chat_history, self.display_file_path, ""
|