Spaces:
Sleeping
Sleeping
Fix IndexError: skip empty-choices chunks from HF Router streaming
Browse files- backend/api/demo.py +4 -0
- backend/env/sql_env.py +2 -0
backend/api/demo.py
CHANGED
|
@@ -211,6 +211,8 @@ async def execute_query_stream(req: ExecuteQueryRequest):
|
|
| 211 |
temperature=0.1,
|
| 212 |
)
|
| 213 |
async for chunk in stream:
|
|
|
|
|
|
|
| 214 |
delta = chunk.choices[0].delta.content
|
| 215 |
if delta:
|
| 216 |
chunks.append(delta)
|
|
@@ -280,6 +282,8 @@ async def execute_query_stream(req: ExecuteQueryRequest):
|
|
| 280 |
temperature=0.3,
|
| 281 |
)
|
| 282 |
async for chunk in diag_stream:
|
|
|
|
|
|
|
| 283 |
delta = chunk.choices[0].delta.content
|
| 284 |
if delta:
|
| 285 |
yield {"data": json.dumps({"type": "diagnosis_chunk", "chunk": delta})}
|
|
|
|
| 211 |
temperature=0.1,
|
| 212 |
)
|
| 213 |
async for chunk in stream:
|
| 214 |
+
if not chunk.choices:
|
| 215 |
+
continue # HF Router sends empty-choices chunks (ping/final)
|
| 216 |
delta = chunk.choices[0].delta.content
|
| 217 |
if delta:
|
| 218 |
chunks.append(delta)
|
|
|
|
| 282 |
temperature=0.3,
|
| 283 |
)
|
| 284 |
async for chunk in diag_stream:
|
| 285 |
+
if not chunk.choices:
|
| 286 |
+
continue
|
| 287 |
delta = chunk.choices[0].delta.content
|
| 288 |
if delta:
|
| 289 |
yield {"data": json.dumps({"type": "diagnosis_chunk", "chunk": delta})}
|
backend/env/sql_env.py
CHANGED
|
@@ -113,6 +113,8 @@ async def _call_llm(
|
|
| 113 |
temperature=0.1,
|
| 114 |
)
|
| 115 |
async for chunk in resp:
|
|
|
|
|
|
|
| 116 |
delta = chunk.choices[0].delta.content
|
| 117 |
if delta:
|
| 118 |
yield delta
|
|
|
|
| 113 |
temperature=0.1,
|
| 114 |
)
|
| 115 |
async for chunk in resp:
|
| 116 |
+
if not chunk.choices:
|
| 117 |
+
continue
|
| 118 |
delta = chunk.choices[0].delta.content
|
| 119 |
if delta:
|
| 120 |
yield delta
|