Open HELIOPOTELICKI opened 1 month ago
Hey there, @HELIOPOTELICKI! I'm here to help you with your bug report. I'm a bot that can assist with solving bugs, answering questions, and becoming a contributor. Let's get to the bottom of this together!
You are encountering a JSONDecodeError
when using the QuivrAPI
class to interact with the endpoint {base_url}/chat/{chat_id}/question?brain_id={brain_id}
because the code attempts to parse a string that is not valid JSON. Specifically, the error occurs in the make_recursive_tool_calls
method when it tries to parse the function.arguments
field of a tool_call
object.
Here is the relevant code snippet:
function_args = json.loads(tool_call.function.arguments)
If tool_call.function.arguments
is not a valid JSON string, json.loads
will raise a JSONDecodeError
.
To fix this issue, ensure that tool_call.function.arguments
is a valid JSON string before attempting to parse it. You can add error handling to catch and log the error, or validate the string before parsing.
Here is an example of how you can add error handling:
import json
def safe_json_loads(json_string):
try:
return json.loads(json_string)
except json.JSONDecodeError as e:
logger.error(f"JSONDecodeError: {e}")
return None
# Usage in make_recursive_tool_calls
function_args = safe_json_loads(tool_call.function.arguments)
if function_args is None:
# Handle the error appropriately, e.g., skip this tool call or return an error response
continue
By adding this error handling, you can avoid the JSONDecodeError
and handle invalid JSON strings more gracefully [1].
To continue talking to Dosu, mention @dosu.
What happened?
I uploaded the containers locally, and using Python, I implemented the functions to interact with Quivr. I have used this class that I implemented a few months ago, and it worked well (before having the notifier, by the way).
I updated Quivr, and now I encounter this JSONDecode error.
The error occurs using my implementation and through the Swagger UI as well.
Error:
On swagger:
OS: Windows 11 Pro Python: 3.11.9 Quivr: 0.0.300
Relevant log output
No response
Twitter / LinkedIn details
No response