FHIR边聊
一个结构化的Python应用程序,使用PydanticAI和一个Aidbox kubectl MCP服务器。
配置
您将需要:
- 辅助箱许可证
- OpenAI访问
- 端点 - 钥匙 - 模型(目前正在使用gpt-5-mini进行测试) - API版本(目前正在测试2024-12-01预览版)
看 env-sample.txt
用法
先决条件
- 后端: Python 3.13+,
uv包管理器 - 前端: Node.js 18+和npm
- 服务: Docker和Docker Compose
快速开始
- 启动服务:
docker compose up -d- 启动API后端:
uv run uvicorn src:app --host 0.0.0.0 --port 8000 --reload- 启动前端(在新终端中):
cd frontend
npm install # First time only
npm run dev- 打开聊天界面:
访问http://localhost:5173在浏览器中
前端开发
前端是用Vite构建的React+TypeScript应用程序。
可用脚本:
npm run dev-启动开发服务器(http://localhost:5173)npm run build-生产建设(产出frontend/dist/)npm run preview-预览生产构建npm run lint-运行ESLint
特征:
- 实时WebSocket聊天通信
- 具有本地存储持久性的会话管理
- 自动滚动聊天界面
- 支持带打字机效果的流媒体消息
- 实时遥测面板显示OpenAI和MCP/Aidbox轨迹(延迟\
**消息格式:**
所有消息均为JSON格式,并带有 `type` 路由字段。
**客户端→ 服务器(用户消息):**
{ "type": "message", "session_id": "your-session-id", "content": "What is quintin cole's diagnosis?" }
**服务器→ 客户:**
*助理回应:*
{ "type": "assistant", "session_id": "your-session-id", "content": "Based on the clinical data...", "streaming": false }
*OpenAI呼叫事件:*
{ "type": "openai_call", "session_id": "your-session-id", "model": "gpt-4", "timestamp": "2025-11-20T22:00:00Z" }
*OpenAI响应事件:*
{ "type": "openai_response", "session_id": "your-session-id", "model": "gpt-4", "duration_ms": 1234, "prompt_tokens": 150, "completion_tokens": 50, "total_tokens": 200, "timestamp": "2025-11-20T22:00:01Z" }
*错误消息:*
{ "type": "error", "session_id": "your-session-id", "error": "Invalid message format" }
**使用wscat进行测试:**
npm install -g wscat wscat -c "ws://localhost:8000/ws?session_id=test123"
{"type": "message", "session_id": "test123", "content": "Hello"}
**遥测:**
- WebSocket流中出现实时事件(延迟\"}'示例响应(截断):
{
"patient_id": "123e4567-e89b-12d3-a456-426614174000",
"patient_name": "Jane Doe",
"clinical_summary": "Patient with a history of hypertension and diabetes, currently stable.",
"key_conditions": ["Hypertension", "Type 2 Diabetes Mellitus"],
"active_medications": ["Lisinopril", "Metformin"],
"recent_encounters": ["2025-11-01: Routine follow-up", "2025-10-10: Lab work"],
"generated_at": "2025-11-14T20:00:00Z"
}⚠️ 安全警告: WebSocket遥测事件可能包含敏感数据,包括:
- OpenAI提示和完成
- MCP Contoso查询和响应
- 潜在PHI(受保护的健康信息)
当前配置:
- WebSocket连接接受任何session_id(无身份验证)
- CORS已启用
localhost:3000和localhost:5173(前端开发服务器) - 仅限开发 -无身份验证或加密
- 生产要求: 使用
wss://(TLS),实现JWT身份验证,添加速率限制,从遥测中过滤PHI
API 文档
交互式API文档可在以下网址获取:
- Swagger用户界面:http://localhost:8000/docs
- 重新记录:http://localhost:8000/redoc
备注
- 仅限记忆会话;替换
ChatService为了坚持。 - 确保Aidbox健康检查通过;SSE端点为
http://localhost:8080/sse.
