mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Avoid unbound chunk variable error in ai api call from completion func
This commit is contained in:
@@ -159,6 +159,7 @@ def completion_with_backoff(
|
|||||||
tool_calls: list[ToolCall] = []
|
tool_calls: list[ToolCall] = []
|
||||||
thoughts = ""
|
thoughts = ""
|
||||||
aggregated_response = ""
|
aggregated_response = ""
|
||||||
|
chunk = None
|
||||||
if stream:
|
if stream:
|
||||||
with client.beta.chat.completions.stream(
|
with client.beta.chat.completions.stream(
|
||||||
messages=formatted_messages, # type: ignore
|
messages=formatted_messages, # type: ignore
|
||||||
@@ -966,6 +967,8 @@ async def astream_thought_processor(
|
|||||||
chunk_data = chunk.model_dump()
|
chunk_data = chunk.model_dump()
|
||||||
|
|
||||||
# Skip chunks that don't have the required object field or have invalid values
|
# Skip chunks that don't have the required object field or have invalid values
|
||||||
|
if "object" in chunk_data and chunk_data.get("object") == "":
|
||||||
|
chunk_data["object"] = "chat.completion.chunk"
|
||||||
if not chunk_data.get("object") or chunk_data.get("object") != "chat.completion.chunk":
|
if not chunk_data.get("object") or chunk_data.get("object") != "chat.completion.chunk":
|
||||||
logger.warning(f"Skipping invalid chunk with object field: {chunk_data.get('object', 'missing')}")
|
logger.warning(f"Skipping invalid chunk with object field: {chunk_data.get('object', 'missing')}")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user