Skip to content

Commit ed762ad

Browse files
committedFeb 15, 2025·
fix prod grouped chunks with nginx and server config
1 parent 008c4d2 commit ed762ad

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed
 

‎backend/app/routers/generate.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ async def event_generator():
346346
reasoning_effort="medium",
347347
):
348348
explanation += chunk
349-
print("sending explanation chunk", chunk)
350349
yield f"data: {json.dumps({'status': 'explanation_chunk', 'chunk': chunk})}\n\n"
351350

352351
if "BAD_INSTRUCTIONS" in explanation:
@@ -416,6 +415,14 @@ async def event_generator():
416415
except Exception as e:
417416
yield f"data: {json.dumps({'error': str(e)})}\n\n"
418417

419-
return StreamingResponse(event_generator(), media_type="text/event-stream")
418+
return StreamingResponse(
419+
event_generator(),
420+
media_type="text/event-stream",
421+
headers={
422+
"X-Accel-Buffering": "no", # Hint to Nginx
423+
"Cache-Control": "no-cache",
424+
"Connection": "keep-alive",
425+
},
426+
)
420427
except Exception as e:
421428
return {"error": str(e)}

‎backend/entrypoint.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ if [ "$ENVIRONMENT" = "development" ]; then
77
exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
88
elif [ "$ENVIRONMENT" = "production" ]; then
99
echo "Starting in production mode with multiple workers..."
10-
exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --timeout-keep-alive 300 --workers 2
10+
exec uvicorn app.main:app \
11+
--host 0.0.0.0 \
12+
--port 8000 \
13+
--timeout-keep-alive 300 \
14+
--workers 2 \
15+
--loop uvloop \
16+
--http httptools
1117
else
1218
echo "ENVIRONMENT must be set to either 'development' or 'production'"
1319
exit 1

‎backend/nginx/api.conf

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ server {
1515
proxy_pass http://127.0.0.1:8000;
1616
include proxy_params;
1717
proxy_redirect off;
18+
19+
# Disable buffering for SSE
20+
proxy_buffering off;
21+
proxy_cache off;
22+
23+
# Required headers for SSE
24+
proxy_set_header Connection '';
25+
proxy_http_version 1.1;
1826
}
1927

2028
# Return 444 for everything else (no response, just close connection)

‎src/hooks/useDiagram.ts

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export function useDiagram(username: string, repo: string) {
125125
}));
126126
break;
127127
case "explanation_chunk":
128-
console.log("received explanation chunk:", data.chunk);
129128
if (data.chunk) {
130129
explanation += data.chunk;
131130
setState((prev) => ({ ...prev, explanation }));

0 commit comments

Comments
 (0)
Please sign in to comment.