mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-10 05:39:11 +00:00
Gracefully close thread when there's an exception in the openai llm thread. Closes #894.
This commit is contained in:
@@ -100,6 +100,7 @@ def chat_completion_with_backoff(
|
||||
|
||||
|
||||
def llm_thread(g, messages, model_name, temperature, openai_api_key=None, api_base_url=None, model_kwargs=None):
|
||||
try:
|
||||
client_key = f"{openai_api_key}--{api_base_url}"
|
||||
if client_key not in openai_clients:
|
||||
client: openai.OpenAI = openai.OpenAI(
|
||||
@@ -129,5 +130,7 @@ def llm_thread(g, messages, model_name, temperature, openai_api_key=None, api_ba
|
||||
g.send(delta_chunk)
|
||||
elif delta_chunk.content:
|
||||
g.send(delta_chunk.content)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in llm_thread: {e}")
|
||||
finally:
|
||||
g.close()
|
||||
|
||||
Reference in New Issue
Block a user