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,8 +1,13 @@
"""Define workflow state for compliance workflow."""
from typing import TypedDict, List
from langgraph.graph import StateGraph, END
# Keep workflow state definitions compact so transitions stay easy to audit.
class ComplianceState(TypedDict):
"""Track workflow state for compliance state."""
document_path: str
raw_text: str
segments: List[dict]
@@ -12,7 +17,7 @@ class ComplianceState(TypedDict):
def parse_document(state: ComplianceState) -> dict:
"""解析文档"""
"""Parse document."""
from app.services import get_document_service
doc_service = get_document_service(
"/airegulation/demo-mao/backend/data/raw",
@@ -23,7 +28,7 @@ def parse_document(state: ComplianceState) -> dict:
def segment_document(state: ComplianceState) -> dict:
"""AI语义分段"""
"""Handle segment document."""
from app.services import llm_service
prompt = f"""请分析以下设计方案文档,按照设计意图将其分成若干语义段落。
@@ -39,7 +44,7 @@ def segment_document(state: ComplianceState) -> dict:
输出格式:
[{{"intent": "...", "startPos": 0, "endPos": 100, "keywords": [...]}}]"""
# 简化处理:返回基本分段
# Keep workflow state definitions compact so transitions stay easy to audit.
segments = [
{
"id": 1,
@@ -53,7 +58,7 @@ def segment_document(state: ComplianceState) -> dict:
def match_regulations(state: ComplianceState) -> dict:
"""法规匹配"""
"""Handle match regulations."""
from app.services import embedding_service, milvus_service
matched = []
@@ -83,7 +88,7 @@ def match_regulations(state: ComplianceState) -> dict:
def calculate_risk(state: ComplianceState) -> dict:
"""计算风险等级"""
"""Handle calculate risk."""
segments = state["matched_regulations"]
high_count = 0
@@ -133,7 +138,7 @@ def calculate_risk(state: ComplianceState) -> dict:
def generate_suggestions(state: ComplianceState) -> dict:
"""生成优先建议"""
"""Handle generate suggestions."""
actions = []
for segment in state["segments"]:
@@ -149,7 +154,7 @@ def generate_suggestions(state: ComplianceState) -> dict:
return {"priority_actions": actions}
# 构建工作流图
# Keep workflow state definitions compact so transitions stay easy to audit.
compliance_graph = StateGraph(ComplianceState)
compliance_graph.add_node("parse", parse_document)
@@ -169,7 +174,7 @@ compliance_workflow = compliance_graph.compile()
async def run_compliance_workflow(document_path: str) -> ComplianceState:
"""运行合规分析工作流"""
"""Handle run compliance workflow."""
initial_state: ComplianceState = {"document_path": document_path}
result = compliance_workflow.invoke(initial_state)
return result