From 2c9f33868e89e0d1d6b9565488f31fe665cb9f9c Mon Sep 17 00:00:00 2001 From: Rune Olsen Date: Wed, 7 Jan 2026 09:58:58 +0100 Subject: [PATCH] More bugfixes --- oai.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/oai.py b/oai.py index be8c1b7..f64a7fe 100644 --- a/oai.py +++ b/oai.py @@ -5034,9 +5034,18 @@ All queries are read-only. INSERT/UPDATE/DELETE are not allowed.""" try: if hasattr(response, 'close'): response.close() + elif hasattr(response, '__exit__'): + response.__exit__(None, None, None) except: pass + # Recreate client to be safe + try: + client = OpenRouter(api_key=API_KEY) + app_logger.info("Client recreated after stream interruption") + except: + pass + continue # Now it's safe to continue else: full_response = response.choices[0].message.content if response.choices else ""