Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -120,9 +120,11 @@ def stream_response(client, model, messages):
|
|
| 120 |
temperature=0.3,
|
| 121 |
)
|
| 122 |
for chunk in stream:
|
| 123 |
-
|
| 124 |
-
if
|
| 125 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 139 |
-
if
|
| 140 |
-
|
|
|
|
|
|
|
| 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:
|