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