Enoughappens commited on
Commit
1734a7e
·
unverified ·
1 Parent(s): 4dff00d

fix streaming "list index out of range"

Browse files
Files changed (1) hide show
  1. lightrag/llm/openai.py +9 -0
lightrag/llm/openai.py CHANGED
@@ -200,6 +200,15 @@ async def openai_complete_if_cache(
200
  async def inner():
201
  try:
202
  async for chunk in response:
 
 
 
 
 
 
 
 
 
203
  content = chunk.choices[0].delta.content
204
  if content is None:
205
  continue
 
200
  async def inner():
201
  try:
202
  async for chunk in response:
203
+ # Check if choices exists and is not empty
204
+ if not hasattr(chunk, 'choices') or not chunk.choices:
205
+ logger.warning(f"Received chunk without choices: {chunk}")
206
+ continue
207
+
208
+ # Check if delta exists and has content
209
+ if not hasattr(chunk.choices[0], 'delta') or not hasattr(chunk.choices[0].delta, 'content'):
210
+ logger.warning(f"Received chunk without delta content: {chunk.choices[0]}")
211
+ continue
212
  content = chunk.choices[0].delta.content
213
  if content is None:
214
  continue