Files
backend/docs/chat.md
yahaozhang 8962943123 聊天
2025-07-20 16:55:23 +08:00

129 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

好的,以下是 简化版的智能问答接口设计,聚焦两个核心问答模式:
• ✅ 普通聊天chat
• ✅ 深度研究research
省略了 history_limit、model、parameters、metadata 等高级控制参数,仅保留核心功能字段。
✅ 请求接口设计
POST /api/qa/ask
📥 请求体JSON
{
"mode": "chat", // chat | research问答模式
"conversation_id": "12345", // 可选会话ID用于上下文关联
"message": "什么是RAG" // 用户输入的问题
}
📌 字段说明
字段名 类型 必填 说明
mode string 是 chat 普通聊天research 深度研究
conversation_id string 否 可选;为空则创建新会话
message string 是 用户发送的问题内容
✅ 响应数据设计
📤 响应体JSON
{
"success": true,
"conversation_id": "12345",
"message_id": "msg_001",
"answer": "RAG 是一种结合检索与生成的问答系统架构...",
"references": [], // chat 模式为空research 模式可能返回引用资料
"report_id": null, // 仅在 research 模式中,若已触发报告生成
"tokens_used": 198,
"time_ms": 732
}
📌 字段说明
字段名 类型 说明
success boolean 是否成功
conversation_id string 当前所属会话 ID
message_id string 当前返回消息的唯一标识
answer string 模型生成的回答内容
references array 若为 research 模式,可能包含引用资料;否则为空
report_id string | null 若生成报告返回报告ID否则为 null
tokens_used number 生成过程使用的 token 数量(可用于统计/计费)
time_ms number 模型生成耗时(毫秒)
✅ 示例
📌 普通聊天模式
请求
{
"mode": "chat",
"message": "你好,帮我解释一下 LLM 是什么?"
}
响应
{
"success": true,
"conversation_id": "abc123",
"message_id": "msg_1001",
"answer": "LLMLarge Language Model是指大型语言模型...",
"references": [],
"report_id": null,
"tokens_used": 154,
"time_ms": 645
}
📌 深度研究模式
请求
{
"mode": "research",
"conversation_id": "r20240718_001",
"message": "请详细说明 RAG 在金融领域的应用。"
}
响应
{
"success": true,
"conversation_id": "r20240718_001",
"message_id": "msg_2009",
"answer": "在金融领域RAG 可用于增强问答系统...",
"references": [
{
"title": "RAG 应用于金融智能问答",
"url": "https://example.com/rag-finance",
"quote": "金融领域中的RAG系统能显著提升精确率..."
}
],
"report_id": "report_84928",
"tokens_used": 341,
"time_ms": 1024
}
✅ 结构总结(精简版)
模式 关键差异
chat 只返回回答,无引用、无报告
research 返回引用资料、可返回 report_id
如需下一步生成 Swagger/OpenAPI 接口文档、接口校验 Schema、数据库如何存储这些内容欢迎继续提问。