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:
parent
99eec5395e
commit
19aa91cf48
1 changed files with 1 additions and 1 deletions
|
@ -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"]
|
||||
|
|
Loading…
Reference in a new issue