Aluode commited on
Commit
07fbe8c
Β·
verified Β·
1 Parent(s): 01dc2f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -120,9 +120,11 @@ def stream_response(client, model, messages):
120
  temperature=0.3,
121
  )
122
  for chunk in stream:
123
- delta = chunk.choices[0].delta.content
124
- if delta:
125
- yield delta
 
 
126
  except Exception as e:
127
  # Try fallback model
128
  if model != FALLBACK_MODEL:
@@ -135,15 +137,16 @@ def stream_response(client, model, messages):
135
  temperature=0.3,
136
  )
137
  for chunk in stream:
138
- delta = chunk.choices[0].delta.content
139
- if delta:
140
- yield delta
 
 
141
  return
142
  except Exception:
143
  pass
144
  yield f"\n\n⚠️ Generation error: {e}\n\nTip: Add a HuggingFace token in Settings for better rate limits."
145
 
146
-
147
  # ── Retrieval helpers ─────────────────────────────────────────────────────────
148
 
149
  def best_sentence(chunk: str, q_tokens: set) -> tuple:
 
120
  temperature=0.3,
121
  )
122
  for chunk in stream:
123
+ # FIX: Check if choices exists before accessing [0]
124
+ if chunk.choices and len(chunk.choices) > 0:
125
+ delta = chunk.choices[0].delta.content
126
+ if delta:
127
+ yield delta
128
  except Exception as e:
129
  # Try fallback model
130
  if model != FALLBACK_MODEL:
 
137
  temperature=0.3,
138
  )
139
  for chunk in stream:
140
+ # FIX: Check if choices exists before accessing [0]
141
+ if chunk.choices and len(chunk.choices) > 0:
142
+ delta = chunk.choices[0].delta.content
143
+ if delta:
144
+ yield delta
145
  return
146
  except Exception:
147
  pass
148
  yield f"\n\n⚠️ Generation error: {e}\n\nTip: Add a HuggingFace token in Settings for better rate limits."
149
 
 
150
  # ── Retrieval helpers ─────────────────────────────────────────────────────────
151
 
152
  def best_sentence(chunk: str, q_tokens: set) -> tuple: