Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

handle none type in llm.py

Namanc5695975c710
diff --git a/backend/llm.py b/backend/llm.py
index e5410463..44f97e19 100644
--- a/backend/llm.py
+++ b/backend/llm.py
@@ -59,9 +59,10 @@ async def stream_openai_response(
full_response = ""
async for chunk in stream: # type: ignore
assert isinstance(chunk, ChatCompletionChunk)
- content = chunk.choices[0].delta.content or ""
- full_response += content
- await callback(content)
+ if chunk.choices and chunk.choices[0].delta.content:
+ content = chunk.choices[0].delta.content or ""
+ full_response += content
+ await callback(content)
await client.close()