acc
This commit is contained in:
@@ -11,14 +11,5 @@
|
||||
"model_type": "\u5927\u8bed\u8a00\u6a21\u578b",
|
||||
"base_model": "glm-4-7-251222",
|
||||
"protocol_type": "OpenAI"
|
||||
},
|
||||
{
|
||||
"id": "deny1",
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o",
|
||||
"api_key": null,
|
||||
"api_base": "https://api.openai.com/v1",
|
||||
"extra_headers": null,
|
||||
"is_active": false
|
||||
}
|
||||
]
|
||||
+5
-4
@@ -4,7 +4,6 @@ from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import StreamingResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
import asyncio
|
||||
import json
|
||||
import re
|
||||
from datetime import datetime
|
||||
@@ -42,6 +41,8 @@ app.include_router(projects.router, prefix="/api/v1")
|
||||
app.include_router(datasources.router, prefix="/api/v1")
|
||||
app.include_router(semantic.router, prefix="/api/v1")
|
||||
|
||||
STREAM_DELTA_CHUNK_SIZE = 48
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
# Initialize nanobot in background
|
||||
@@ -243,9 +244,9 @@ async def nanobot_chat_stream(request: ChatRequest):
|
||||
model_id=request.model_id,
|
||||
)
|
||||
text = response or ""
|
||||
for ch in text:
|
||||
yield f"data: {json.dumps({'type': 'delta', 'content': ch}, ensure_ascii=False)}\n\n"
|
||||
await asyncio.sleep(0.008)
|
||||
for idx in range(0, len(text), STREAM_DELTA_CHUNK_SIZE):
|
||||
chunk = text[idx: idx + STREAM_DELTA_CHUNK_SIZE]
|
||||
yield f"data: {json.dumps({'type': 'delta', 'content': chunk}, ensure_ascii=False)}\n\n"
|
||||
yield f"data: {json.dumps({'type': 'final', 'content': text}, ensure_ascii=False)}\n\n"
|
||||
yield f"data: {json.dumps({'type': 'done'}, ensure_ascii=False)}\n\n"
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user