From 09aff441b6d9ce9e3681c45d276f799fc820efe4 Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Mon, 28 Oct 2024 15:18:45 -0400 Subject: [PATCH] improving error catching for openai result --- parsers/LitCoin/src/bagel/bagel_gpt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parsers/LitCoin/src/bagel/bagel_gpt.py b/parsers/LitCoin/src/bagel/bagel_gpt.py index 11c0bee7..ad64697f 100644 --- a/parsers/LitCoin/src/bagel/bagel_gpt.py +++ b/parsers/LitCoin/src/bagel/bagel_gpt.py @@ -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