Spaces:
Running
Running
Germano Cavalcante
commited on
Commit
•
1eaad00
1
Parent(s):
f0d9ee1
Function Calls: Handle Malformed JSON Errors
Browse files- routers/tool_calls.py +18 -8
routers/tool_calls.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import json
|
|
|
2 |
from .tool_gpu_checker import gpu_checker_get_message
|
3 |
from .tool_bpy_doc import bpy_doc_get_documentation
|
4 |
from fastapi import APIRouter, Body
|
@@ -21,15 +22,24 @@ router = APIRouter()
|
|
21 |
|
22 |
|
23 |
def process_tool_call(tool_call: ToolCallInput) -> Dict:
|
24 |
-
function_name = tool_call.function.name
|
25 |
-
function_args = json.loads(tool_call.function.arguments)
|
26 |
output = {"tool_call_id": tool_call.id, "output": ""}
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
return output
|
34 |
|
35 |
|
|
|
1 |
import json
|
2 |
+
import logging
|
3 |
from .tool_gpu_checker import gpu_checker_get_message
|
4 |
from .tool_bpy_doc import bpy_doc_get_documentation
|
5 |
from fastapi import APIRouter, Body
|
|
|
22 |
|
23 |
|
24 |
def process_tool_call(tool_call: ToolCallInput) -> Dict:
|
|
|
|
|
25 |
output = {"tool_call_id": tool_call.id, "output": ""}
|
26 |
+
function_name = tool_call.function.name
|
27 |
+
|
28 |
+
try:
|
29 |
+
function_args = json.loads(tool_call.function.arguments)
|
30 |
+
if function_name == "get_bpy_api_info":
|
31 |
+
output["output"] = bpy_doc_get_documentation(
|
32 |
+
function_args.get("api", ""))
|
33 |
+
elif function_name == "check_gpu":
|
34 |
+
output["output"] = gpu_checker_get_message(
|
35 |
+
function_args.get("gpu", ""))
|
36 |
+
except json.JSONDecodeError as e:
|
37 |
+
error_message = f"Malformed JSON encountered at position {e.pos}: {e.msg}\n {tool_call.function.arguments}"
|
38 |
+
output["output"] = error_message
|
39 |
+
|
40 |
+
# Logging the error for further investigation
|
41 |
+
logging.error(f"JSONDecodeError in process_tool_call: {error_message}")
|
42 |
+
|
43 |
return output
|
44 |
|
45 |
|