from fastapi import APIRouter, HTTPException, status, WebSocket from ..controllers.chat_controller import * from fastapi import Depends from ..dependencies.database import get_db from ..dependencies.redis import get_redis router = APIRouter() #创建新聊天接口 @router.post("/chats", response_model=ChatCreateResponse) async def create_chat(chat: ChatCreateRequest, db=Depends(get_db), redis=Depends(get_redis)): response = await create_chat_handler(chat, db, redis) return response #删除聊天接口 @router.delete("/chats/{user_character_id}", response_model=ChatDeleteResponse) async def delete_chat(user_character_id: int, db=Depends(get_db), redis=Depends(get_redis)): response = await delete_chat_handler(user_character_id, db, redis) return response #非流式聊天 @router.post("/chats/non-streaming", response_model=ChatNonStreamResponse) async def non_streaming_chat(chat: ChatNonStreamRequest,db=Depends(get_db), redis=Depends(get_redis)): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,detail="this api is not available") response = await non_streaming_chat_handler(chat, db, redis) return response #流式聊天_单次 @router.websocket("/chat/streaming/temporary") async def streaming_chat(ws: WebSocket,db=Depends(get_db), redis=Depends(get_redis)): await ws.accept() await streaming_chat_temporary_handler(ws,db,redis) #流式聊天_持续 @router.websocket("/chat/streaming/lasting") async def streaming_chat(ws: WebSocket,db=Depends(get_db), redis=Depends(get_redis)): await ws.accept() await streaming_chat_lasting_handler(ws,db,redis) #语音通话 @router.websocket("/chat/voice_call") async def voice_chat(ws: WebSocket,db=Depends(get_db), redis=Depends(get_redis)): await ws.accept() await voice_call_handler(ws,db,redis)