mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 16:14:21 +00:00
Search should return user message if GPT response is not valid JSON
Previously would throw if GPT response is not valid JSON. Better to return original message to use for search instead
This commit is contained in:
parent
08f5fb315f
commit
10836dedee
1 changed files with 6 additions and 1 deletions
|
@ -165,7 +165,12 @@ Q: {text}
|
|||
)
|
||||
|
||||
# Extract, Clean Message from GPT's Response
|
||||
questions = json.loads(response["choices"][0]["text"].strip(empty_escape_sequences))
|
||||
response_text = response["choices"][0]["text"]
|
||||
try:
|
||||
questions = json.loads(response_text.strip(empty_escape_sequences))
|
||||
except json.decoder.JSONDecodeError:
|
||||
logger.warn(f"GPT returned invalid JSON. Set question to empty list.\n{response_text}")
|
||||
questions = [text]
|
||||
logger.debug(f"Extracted Questions by GPT: {questions}")
|
||||
return questions
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue