mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 13:23:15 +00:00
Fix-up Search Actor GPT's response for decoding it as valid JSON
This commit is contained in:
@@ -167,7 +167,13 @@ Q: {text}
|
|||||||
# Extract, Clean Message from GPT's Response
|
# Extract, Clean Message from GPT's Response
|
||||||
response_text = response["choices"][0]["text"]
|
response_text = response["choices"][0]["text"]
|
||||||
try:
|
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:
|
except json.decoder.JSONDecodeError:
|
||||||
logger.warn(f"GPT returned invalid JSON. Set question to empty list.\n{response_text}")
|
logger.warn(f"GPT returned invalid JSON. Set question to empty list.\n{response_text}")
|
||||||
questions = [text]
|
questions = [text]
|
||||||
|
|||||||
Reference in New Issue
Block a user