fix(openai response handling): narrow down exception handling

Refined exception handling in the OpenAI response parsing by specifying `Exception` instead of using a bare except. This change improves code reliability and maintainability by clearly defining the scope of exceptions we anticipate, leading to more precise error handling and easier debugging processes. It aligns with best practices for Python error handling, avoiding the catch-all approach that might inadvertently suppress unrelated errors, thus enhancing the overall robustness of the error management strategy.
This commit is contained in:
Kumi 2024-05-18 21:38:17 +02:00
parent 99eec5395e
commit 19aa91cf48
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -549,7 +549,7 @@ Only the event_types mentioned above are allowed, you must not respond in any ot
try:
result = json.loads(response.choices[0].message["content"])
except:
except Exception:
result = {"type": "chat", "prompt": query}
tokens_used = response.usage["total_tokens"]