mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 16:14:21 +00:00
Fix-up Search Actor GPT's response for decoding it as valid JSON
This commit is contained in:
parent
f63fd0995e
commit
939d7731da
1 changed files with 7 additions and 1 deletions
|
@ -167,7 +167,13 @@ Q: {text}
|
|||
# Extract, Clean Message from GPT's Response
|
||||
response_text = response["choices"][0]["text"]
|
||||
try:
|
||||
questions = json.loads(response_text.strip(empty_escape_sequences))
|
||||
questions = json.loads(
|
||||
# Clean response to increase likelihood of valid JSON. E.g replace ' with " to enclose strings
|
||||
response_text.strip(empty_escape_sequences)
|
||||
.replace("['", '["')
|
||||
.replace("']", '"]')
|
||||
.replace("', '", '", "')
|
||||
)
|
||||
except json.decoder.JSONDecodeError:
|
||||
logger.warn(f"GPT returned invalid JSON. Set question to empty list.\n{response_text}")
|
||||
questions = [text]
|
||||
|
|
Loading…
Add table
Reference in a new issue