Fix SSE route dependency and align architecture docs

This commit is contained in:
ash66
2026-05-18 16:32:42 +08:00
parent 86b9ac806a
commit 3f69cad404
149 changed files with 4786 additions and 5957 deletions

View File

@@ -1,12 +1,12 @@
"""
Mock数据服务 - 提供预设假数据供前后端对接测试
"""
"""Provide service-layer logic for mock data."""
from datetime import datetime
from typing import Dict, List, Any
import uuid
# Keep service responsibilities explicit so downstream behavior stays predictable.
# 预设法规文档列表
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_DOCUMENTS: List[Dict[str, Any]] = [
{
"id": "doc-001",
@@ -45,7 +45,7 @@ MOCK_DOCUMENTS: List[Dict[str, Any]] = [
},
]
# 预设快捷问题
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_QUICK_QUESTIONS: List[Dict[str, str]] = [
{"id": "q1", "question": "电动自行车需要上牌照吗?", "category": "车辆登记"},
{"id": "q2", "question": "新能源汽车有哪些补贴政策?", "category": "新能源"},
@@ -53,7 +53,7 @@ MOCK_QUICK_QUESTIONS: List[Dict[str, str]] = [
{"id": "q4", "question": "驾驶证过期了怎么处理?", "category": "驾驶证"},
]
# 预设检索结果
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_RETRIEVAL_RESULTS: List[Dict[str, Any]] = [
{
"id": "chunk-001",
@@ -97,7 +97,7 @@ MOCK_RETRIEVAL_RESULTS: List[Dict[str, Any]] = [
},
]
# 预设RAG问答答案模板按关键词匹配
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_RAG_ANSWERS: Dict[str, Dict[str, Any]] = {
"电动自行车": {
"text": "根据《道路交通安全法》及相关规范,电动自行车上路需满足以下条件:\n\n1. 符合国家标准 GB17761-2018\n2. 经公安机关交通管理部门登记\n3. 最高设计车速不超过 25km/h\n4. 整车质量不超过 55kg\n5. 具有脚踏骑行能力\n6. 蓄电池标称电压不超过 48V\n\n行驶时还需佩戴安全头盔,不得逆向行驶或在机动车道内行驶。",
@@ -133,7 +133,7 @@ MOCK_RAG_ANSWERS: Dict[str, Dict[str, Any]] = {
},
}
# 预设合规分析结果
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_COMPLIANCE_RESULT: Dict[str, Any] = {
"task_id": "task-001",
"dashboard": {
@@ -310,7 +310,7 @@ MOCK_COMPLIANCE_RESULT: Dict[str, Any] = {
],
}
# 预设合规对话响应模板
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_COMPLIANCE_CHAT_RESPONSES: Dict[str, Dict[str, str]] = {
"车身结构设计": {
"compliance": "根据当前分析,车身结构设计部分存在以下合规问题:\n\n1. GB 26112-2010要求车顶承受1.5倍整备质量载荷,目前设计声明满足要求但缺少测试数据\n2. C-NCAP正面碰撞后车门应能打开需提供碰撞测试报告\n\n建议补充相关测试数据以提升合规评分。",
@@ -329,7 +329,7 @@ MOCK_COMPLIANCE_CHAT_RESPONSES: Dict[str, Dict[str, str]] = {
},
}
# 预设系统统计数据
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_SYSTEM_STATS: Dict[str, int] = {
"docs": 5,
"chunks": 510,
@@ -337,7 +337,7 @@ MOCK_SYSTEM_STATS: Dict[str, int] = {
"segments": 0,
}
# 预设系统配置
# Keep service responsibilities explicit so downstream behavior stays predictable.
MOCK_SYSTEM_CONFIG: Dict[str, Any] = {
"llm": {
"model": "qwen-max",
@@ -358,17 +358,17 @@ MOCK_SYSTEM_CONFIG: Dict[str, Any] = {
def get_mock_documents() -> List[Dict[str, Any]]:
"""获取预设法规文档列表"""
"""Return mock documents."""
return MOCK_DOCUMENTS
def get_mock_quick_questions() -> List[Dict[str, str]]:
"""获取预设快捷问题"""
"""Return mock quick questions."""
return MOCK_QUICK_QUESTIONS
def get_mock_retrieval(query: str, top_k: int = 5) -> List[Dict[str, Any]]:
"""根据查询关键词返回预设检索结果"""
"""Return mock retrieval."""
results = []
for keyword, data in MOCK_RAG_ANSWERS.items():
if keyword in query:
@@ -389,7 +389,7 @@ def get_mock_retrieval(query: str, top_k: int = 5) -> List[Dict[str, Any]]:
def get_mock_rag_answer(query: str) -> str:
"""根据查询关键词返回预设答案"""
"""Return mock rag answer."""
for keyword, data in MOCK_RAG_ANSWERS.items():
if keyword in query:
return data["text"]
@@ -397,14 +397,14 @@ def get_mock_rag_answer(query: str) -> str:
def get_mock_compliance_result(task_id: str) -> Dict[str, Any]:
"""获取预设合规分析结果"""
"""Return mock compliance result."""
result = MOCK_COMPLIANCE_RESULT.copy()
result["task_id"] = task_id
return result
def get_mock_compliance_chat_response(intent: str, query: str) -> str:
"""获取预设合规对话响应"""
"""Return mock compliance chat response."""
responses = MOCK_COMPLIANCE_CHAT_RESPONSES.get(intent, {})
if "合规" in query or "符合" in query:
return responses.get("compliance", "根据相关法规分析,该段落的合规性需进一步评估。")
@@ -416,10 +416,10 @@ def get_mock_compliance_chat_response(intent: str, query: str) -> str:
def generate_task_id() -> str:
"""生成任务ID"""
"""Handle generate task id."""
return f"task-{uuid.uuid4().hex[:8]}"
def generate_doc_id() -> str:
"""生成文档ID"""
"""Handle generate doc id."""
return f"doc-{uuid.uuid4().hex[:8]}"