Andrew McCracken
Claude
commited on
Commit
·
c53e66f
1
Parent(s):
2f6841c
Fix f-string syntax error in streaming endpoint
Browse files- Extract dict construction outside f-string
- Fixes SyntaxError with nested braces in json.dumps
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
main.py
CHANGED
|
@@ -428,7 +428,14 @@ async def chat_stream(request: ChatRequest):
|
|
| 428 |
|
| 429 |
# Send initial metadata with pool stats
|
| 430 |
pool_stats = model_pool.get_stats()
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
# Stream tokens
|
| 434 |
for token in model.generate_stream(
|
|
@@ -436,7 +443,8 @@ async def chat_stream(request: ChatRequest):
|
|
| 436 |
max_tokens=request.max_tokens
|
| 437 |
):
|
| 438 |
full_response += token
|
| 439 |
-
|
|
|
|
| 440 |
await asyncio.sleep(0)
|
| 441 |
|
| 442 |
# Log interaction
|
|
|
|
| 428 |
|
| 429 |
# Send initial metadata with pool stats
|
| 430 |
pool_stats = model_pool.get_stats()
|
| 431 |
+
start_data = {
|
| 432 |
+
'type': 'start',
|
| 433 |
+
'session_id': session_id,
|
| 434 |
+
'model': MODEL_REPO,
|
| 435 |
+
'interaction_count': count,
|
| 436 |
+
'pool_available': pool_stats['available']
|
| 437 |
+
}
|
| 438 |
+
yield f"data: {json.dumps(start_data)}\n\n"
|
| 439 |
|
| 440 |
# Stream tokens
|
| 441 |
for token in model.generate_stream(
|
|
|
|
| 443 |
max_tokens=request.max_tokens
|
| 444 |
):
|
| 445 |
full_response += token
|
| 446 |
+
token_data = {'type': 'token', 'content': token}
|
| 447 |
+
yield f"data: {json.dumps(token_data)}\n\n"
|
| 448 |
await asyncio.sleep(0)
|
| 449 |
|
| 450 |
# Log interaction
|