chore: finalize backend feature scope
This commit is contained in:
+19
-3
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -37,6 +38,21 @@ from app.services.session_service import SessionService
|
||||
from scripts.init_demo_db import init_database
|
||||
|
||||
|
||||
async def collect_stream_reply(session_service: SessionService, ctx: UserContext, session_id: int, message: str) -> str:
|
||||
"""测试辅助:消费流式问诊 SSE,提取 AI 病人增量文本。"""
|
||||
stream = await session_service.stream_chat(ctx, session_id, message)
|
||||
reply = ""
|
||||
done = False
|
||||
async for event in stream:
|
||||
if event.startswith("event: message_delta"):
|
||||
payload_text = event.split("data:", 1)[1].strip()
|
||||
reply += json.loads(payload_text)["delta"]
|
||||
if event.startswith("event: message_done"):
|
||||
done = True
|
||||
assert done is True
|
||||
return reply
|
||||
|
||||
|
||||
async def run_demo_flow() -> None:
|
||||
"""完整闭环:验证第一版 Demo 的核心训练链路可跑通。"""
|
||||
init_database()
|
||||
@@ -69,9 +85,9 @@ async def run_demo_flow() -> None:
|
||||
assert created.status == "inquiry"
|
||||
assert created.patient_config["labels"]["visit_environment"] == "门诊"
|
||||
|
||||
chat = await session_service.chat(ctx, created.session_id, ChatRequest(message="孩子最高体温多少?").message)
|
||||
chat_reply = await collect_stream_reply(session_service, ctx, created.session_id, ChatRequest(message="孩子最高体温多少?").message)
|
||||
db.commit()
|
||||
assert chat.reply
|
||||
assert chat_reply
|
||||
|
||||
order = order_service.create_order(created.session_id, ctx.user_id, CreateOrderRequest(item_code="chest_xray").item_code)
|
||||
db.commit()
|
||||
@@ -136,7 +152,7 @@ async def run_demo_flow() -> None:
|
||||
assert treatment.status == "evaluating"
|
||||
|
||||
try:
|
||||
await session_service.chat(ctx, created.session_id, "治疗后还能问诊吗?")
|
||||
await session_service.stream_chat(ctx, created.session_id, "治疗后还能问诊吗?")
|
||||
except AppError as exc:
|
||||
assert exc.code == "SESSION_STATUS_INVALID"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user