feat: 项目初始化、完成基本流式传输和语音识别功能

This commit is contained in:
2025-06-28 19:21:46 +08:00
commit d6f9cd7aed
91 changed files with 7827 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
from fastapi import APIRouter
from fastapi.responses import StreamingResponse
from app.constants.model_data import base_url, headers, tip_message
from app.services.llm_request import stream_post_request
from app.schemas import ChatRequest
router = APIRouter()
@router.post("/completions")
async def chat(data: ChatRequest):
all_messages = [tip_message] + data.messages
all_messages_dict = [
m.model_dump() if hasattr(m, "model_dump") else m.dict() if hasattr(m, "dict") else m
for m in all_messages
]
payload = {"model": data.model, "messages": all_messages_dict, "stream": True}
print(payload)
return StreamingResponse(
stream_post_request(
url=base_url,
headers=headers,
json=payload,
),
media_type="text/event-stream"
)