Spaces:
Sleeping
Sleeping
kevin
commited on
Commit
·
0fd5c22
1
Parent(s):
b4a3e27
使用 uvicorn配置 实现实时发送
Browse files
app.py
CHANGED
|
@@ -362,8 +362,10 @@ async def chat_completions(request: Request, auth_headers: dict = Depends(get_op
|
|
| 362 |
'Connection': 'keep-alive',
|
| 363 |
'X-Accel-Buffering': 'no', # 禁用 Nginx 缓冲
|
| 364 |
'Content-Type': 'text/event-stream',
|
|
|
|
| 365 |
},
|
| 366 |
-
|
|
|
|
| 367 |
)
|
| 368 |
else:
|
| 369 |
return Response(content=response.content, status_code=response.status_code, headers=response.headers)
|
|
@@ -406,4 +408,15 @@ async def redirect_all(path: str, request: Request):
|
|
| 406 |
|
| 407 |
# 主程序入口
|
| 408 |
if __name__ == "__main__":
|
| 409 |
-
uvicorn.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
'Connection': 'keep-alive',
|
| 363 |
'X-Accel-Buffering': 'no', # 禁用 Nginx 缓冲
|
| 364 |
'Content-Type': 'text/event-stream',
|
| 365 |
+
'Transfer-Encoding': 'chunked'
|
| 366 |
},
|
| 367 |
+
status_code=200,
|
| 368 |
+
background=None # 确保不会在后台处理
|
| 369 |
)
|
| 370 |
else:
|
| 371 |
return Response(content=response.content, status_code=response.status_code, headers=response.headers)
|
|
|
|
| 408 |
|
| 409 |
# 主程序入口
|
| 410 |
if __name__ == "__main__":
|
| 411 |
+
uvicorn.run(
|
| 412 |
+
app,
|
| 413 |
+
host="0.0.0.0",
|
| 414 |
+
port=8080,
|
| 415 |
+
loop="asyncio",
|
| 416 |
+
timeout_keep_alive=65,
|
| 417 |
+
access_log=True,
|
| 418 |
+
log_level="debug",
|
| 419 |
+
http="h11",
|
| 420 |
+
limit_concurrency=1000,
|
| 421 |
+
backlog=2048
|
| 422 |
+
)
|