Skip to content

Commit

Permalink
improving error catching for openai result
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDietzMorris committed Oct 28, 2024
1 parent aaf6b2c commit 09aff44
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions parsers/LitCoin/src/bagel/bagel_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def query(prompt, requests_session):
print(f'openai json did not contain expected key {k}: {response.json()}')
raise k

chunk = content[content.index("["):(content.rindex("]") + 1)]
try:
chunk = content[content.index("["):(content.rindex("]") + 1)]
output = json.loads(chunk)
except json.JSONDecodeError as e:
print(f'openai results not contain valid json chunk, chunk: {chunk}')
output = []
except (json.JSONDecodeError, ValueError) as e:
print(f'openai results did not contain valid json chunk: {content}')
raise e
return output

0 comments on commit 09aff44

Please sign in to comment.