feat:优化流式输出,增加临时多轮对话记录
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""会话创建与历史查询接口"""
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
|
||||
from app.common.response import ApiResponse, success_response
|
||||
from app.core.exceptions import BizException
|
||||
from app.schemas.conversation import ConversationCreated, ConversationDetail
|
||||
|
||||
router = APIRouter(prefix="/conversations", tags=["Conversation"])
|
||||
|
||||
|
||||
@router.post("")
|
||||
async def create_conversation(
|
||||
request: Request,
|
||||
) -> ApiResponse[ConversationCreated]:
|
||||
store = request.app.state.conversation_store
|
||||
return success_response(ConversationCreated(conversation_id=await store.create()))
|
||||
|
||||
|
||||
@router.get("/{conversation_id}")
|
||||
async def get_conversation(
|
||||
conversation_id: str, request: Request
|
||||
) -> ApiResponse[ConversationDetail]:
|
||||
store = request.app.state.conversation_store
|
||||
if not await store.exists(conversation_id):
|
||||
raise BizException(404, "会话不存在或已过期")
|
||||
turns = await store.load_turns(conversation_id, None)
|
||||
return success_response(
|
||||
ConversationDetail(conversation_id=conversation_id, turns=turns)
|
||||
)
|
||||
Reference in New Issue
Block a user