chore: finalize backend feature scope

This commit is contained in:
刘金宝
2026-06-11 16:19:07 +08:00
parent d855ecab82
commit ec515d5453
43 changed files with 680 additions and 712 deletions
+1 -30
View File
@@ -15,7 +15,6 @@ from app.models.training import SessionSubmission, TrainingSession
from app.repositories.case_repository import CaseRepository
from app.repositories.session_repository import SessionRepository
from app.schemas.session import (
ChatResponse,
CreateSessionRequest,
CreateSessionResponse,
SessionStatusResponse,
@@ -80,34 +79,6 @@ class SessionService:
patient_config=patient_config,
)
async def chat(self, ctx: UserContext, session_id: int, message: str) -> ChatResponse:
"""问诊对话:拼接病例上下文、短期记忆和用户输入后调用 Patient Agent。"""
session = self._get_session(session_id, ctx.user_id)
if session.status != "inquiry":
raise AppError("SESSION_STATUS_INVALID", "chat is only allowed in inquiry status", 400)
case = self.case_repo.get_active_case(session.case_id)
if not case:
raise AppError("CASE_NOT_FOUND", "case not found or inactive", 404)
start = time.perf_counter()
memory_messages = runtime_memory.get_messages(session.memory_key)
runtime_memory.add_message(session.memory_key or "", "doctor", message)
try:
response = await asyncio.wait_for(
self.orchestrator.patient_reply(session, case, memory_messages, message),
timeout=settings.llm_chat_timeout_seconds,
)
except TimeoutError as exc:
raise AppError("LLM_CALL_TIMEOUT", "AI 病人回复超时,请稍后重试或切换为普通问诊", 504) from exc
runtime_memory.add_message(session.memory_key or "", "patient", response.content)
self.audit.log(ctx, "session.chat", "training_session", str(session.id), session.id)
return ChatResponse(
reply=response.content,
latency_ms=response.latency_ms or int((time.perf_counter() - start) * 1000),
model=response.model,
fallback_used=response.model.startswith("mock-fallback"),
)
async def stream_chat(self, ctx: UserContext, session_id: int, message: str) -> AsyncIterator[str]:
"""流式问诊:返回 SSE 格式的 AI 病人回复。"""
session = self._get_session(session_id, ctx.user_id)
@@ -214,7 +185,7 @@ class SessionService:
return f"event: error\ndata: {payload}\n\n"
async def generate_hints(self, ctx: UserContext, session_id: int, payload: HintRequest) -> HintResponse:
"""新手提示:基于当前会话上下文、已申请检查和病例信息生成提醒。"""
"""练习提示:基于当前会话上下文、已申请检查和病例信息生成提醒。"""
session = self._get_session(session_id, ctx.user_id)
if session.mode != "practice":
raise AppError("SESSION_STATUS_INVALID", "hints are only available in practice mode", 400)