Procházet zdrojové kódy

v0.0.2-协同开发节点

wandaan před 3 měsíci
rodič
revize
cfd1cfc3bb

+ 1 - 1
.gitignore

@@ -51,7 +51,7 @@ coverage.xml
 
 # Django stuff:
 *.log
-
+langfuse/
 # Sphinx documentation
 docs/_build/
 

+ 16 - 0
core/construction_review/component/reviewers/__init__.py

@@ -0,0 +1,16 @@
+"""
+审查器模块
+负责具体的AI审查逻辑实现
+"""
+
+from .base_reviewer import BaseReviewer
+from .basic_reviewers import BasicComplianceReviewer
+from .technical_reviewers import TechnicalComplianceReviewer
+from .rag_reviewers import RAGEnhancedReviewer
+
+__all__ = [
+    'BaseReviewer',
+    'BasicComplianceReviewer',
+    'TechnicalComplianceReviewer',
+    'RAGEnhancedReviewer'
+]

+ 181 - 0
core/construction_review/component/reviewers/base_reviewer.py

@@ -0,0 +1,181 @@
+"""
+审查器基类
+定义模型调用、提示词设定的基础接口
+"""
+
+from abc import ABC, abstractmethod
+from typing import Dict, Any, Optional
+from dataclasses import dataclass
+import uuid
+
+from foundation.agent.generate.model_generate import test_generate_model_client
+from foundation.logger.loggering import server_logger as logger
+
+
+@dataclass
+class ReviewResult:
+    """审查结果基类"""
+    success: bool
+    score: float
+    details: Dict[str, Any]
+    suggestions: list
+    error_message: Optional[str] = None
+    execution_time: Optional[float] = None
+
+
+class BaseReviewer(ABC):
+    """审查器基类"""
+
+    def __init__(self, name: str):
+        self.name = name
+        self.model_client = test_generate_model_client
+
+    @abstractmethod
+    def get_system_prompt(self) -> str:
+        """获取系统提示词"""
+        pass
+
+    @abstractmethod
+    def get_user_prompt_template(self) -> str:
+        """获取用户提示词模板"""
+        pass
+
+    @abstractmethod
+    def format_result(self, model_response: str, **kwargs) -> ReviewResult:
+        """格式化模型返回结果"""
+        pass
+
+    async def review(self, content: str, context: Optional[Dict[str, Any]] = None) -> ReviewResult:
+        """
+        执行审查
+
+        Args:
+            content: 待审查内容
+            context: 额外的上下文信息
+
+        Returns:
+            ReviewResult: 审查结果
+        """
+        import time
+        start_time = time.time()
+        trace_id = str(uuid.uuid4())
+
+        try:
+            logger.info(f"开始执行 {self.name} 审查,trace_id: {trace_id}")
+
+            # 构建任务提示信息
+            task_prompt_info = {
+                "task_prompt": self.get_system_prompt(),
+                "task_name": self.name
+            }
+
+            # 构建用户提示词
+            user_prompt = self.get_user_prompt_template().format(
+                content=content,
+                context=context or {}
+            )
+
+            # 调用模型
+            model_response = self.model_client.get_model_generate_invoke(
+                trace_id=trace_id,
+                task_prompt_info=task_prompt_info,
+                input_query=user_prompt,
+                context=str(context) if context else None
+            )
+
+            # 格式化结果
+            result = self.format_result(model_response, content=content, context=context)
+            result.execution_time = time.time() - start_time
+
+            logger.info(f"{self.name} 审查完成,score: {result.score}, 耗时: {result.execution_time:.2f}s")
+            return result
+
+        except Exception as e:
+            execution_time = time.time() - start_time
+            error_msg = f"{self.name} 审查失败: {str(e)}"
+            logger.error(error_msg, exc_info=True)
+
+            return ReviewResult(
+                success=False,
+                score=0.0,
+                details={},
+                suggestions=[],
+                error_message=error_msg,
+                execution_time=execution_time
+            )
+
+    def validate_input(self, content: str) -> bool:
+        """验证输入内容"""
+        if not content or not content.strip():
+            return False
+        return len(content.strip()) > 10  # 至少10个字符
+
+    def get_model_config(self) -> Dict[str, Any]:
+        """获取模型配置(可被子类重写)"""
+        return {
+            "temperature": 0.1,  # 审查任务要求低温度
+            "max_tokens": 2000,
+            "top_p": 0.9
+        }
+
+
+class BaseComplianceReviewer(BaseReviewer):
+    """合规性审查器基类"""
+
+    def format_result(self, model_response: str, **kwargs) -> ReviewResult:
+        """
+        格式化合规性审查结果
+        子类可以根据需要重写此方法
+        """
+        try:
+            # 尝试解析JSON响应
+            import json
+            response_data = json.loads(model_response)
+
+            return ReviewResult(
+                success=True,
+                score=response_data.get('score', 0.0),
+                details=response_data.get('details', {}),
+                suggestions=response_data.get('suggestions', [])
+            )
+        except (json.JSONDecodeError, KeyError):
+            # 如果解析失败,使用简单格式
+            return ReviewResult(
+                success=True,
+                score=75.0,  # 默认分数
+                details={"raw_response": model_response},
+                suggestions=["需要进一步人工审查"]
+            )
+
+
+class BaseRAGReviewer(BaseReviewer):
+    """RAG增强审查器基类"""
+
+    def __init__(self, name: str, vector_store=None):
+        super().__init__(name)
+        self.vector_store = vector_store
+
+    async def search_relevant_docs(self, content: str, top_k: int = 5) -> list:
+        """
+        搜索相关文档
+        子类需要实现具体的检索逻辑
+        """
+        # 这里是占位实现,具体逻辑在子类中实现
+        return []
+
+    def get_enhanced_context(self, content: str, relevant_docs: list) -> str:
+        """
+        构建增强的上下文
+        """
+        context_parts = [
+            "以下是相关的标准规范和案例:",
+            ""
+        ]
+
+        for i, doc in enumerate(relevant_docs, 1):
+            context_parts.append(f"{i}. {doc.get('content', '')}")
+            if doc.get('source'):
+                context_parts.append(f"   来源:{doc['source']}")
+            context_parts.append("")
+
+        return "\n".join(context_parts)

+ 233 - 0
core/construction_review/component/reviewers/basic_reviewers.py

@@ -0,0 +1,233 @@
+"""
+基础合规性审查器
+负责语法检查、语义逻辑检查、完整性检查等基础审查功能
+"""
+
+import json
+from typing import Dict, Any, Optional
+from .base_reviewer import BaseComplianceReviewer, ReviewResult
+
+
+class GrammarCheckReviewer(BaseComplianceReviewer):
+    """语法检查审查器"""
+
+    def __init__(self):
+        super().__init__("语法检查")
+
+    def get_system_prompt(self) -> str:
+        return """你是一个专业的中文语法检查专家,专门负责检查施工方案文档中的语法问题。
+
+你的任务是:
+1. 检查语法错误、标点符号使用
+2. 识别语句不通顺的地方
+3. 发现用词不当的问题
+4. 检查专业术语使用是否规范
+
+请对给定的施工方案内容进行语法检查,并以JSON格式返回结果:
+{
+    "score": 85.5,
+    "details": {
+        "grammar_errors": [{"text": "错误内容", "position": "位置", "suggestion": "修改建议"}],
+        "punctuation_errors": [{"text": "错误内容", "position": "位置", "suggestion": "修改建议"}],
+        "word_choice_issues": [{"text": "用词问题", "position": "位置", "suggestion": "修改建议"}],
+        "total_errors": 3
+    },
+    "suggestions": ["建议1", "建议2"]
+}
+
+评分标准:
+- 90-100分:语法优秀,基本无错误
+- 80-89分:语法良好,少量小错误
+- 70-79分:语法一般,有一些错误
+- 60-69分:语法较差,错误较多
+- 0-59分:语法很差,需要重写
+"""
+
+    def get_user_prompt_template(self) -> str:
+        return """请对以下施工方案内容进行语法检查:
+
+待检查内容:
+{content}
+
+请仔细检查上述内容的语法、标点符号和用词,并以JSON格式返回检查结果。"""
+
+
+class SemanticLogicReviewer(BaseComplianceReviewer):
+    """语义逻辑检查审查器"""
+
+    def __init__(self):
+        super().__init__("语义逻辑检查")
+
+    def get_system_prompt(self) -> str:
+        return """你是一个专业的施工方案语义逻辑检查专家,负责检查施工方案中的逻辑一致性和语义合理性。
+
+你的任务是:
+1. 检查前后内容是否矛盾
+2. 验证技术参数的逻辑一致性
+3. 检查施工流程的合理性
+4. 识别语义不清晰或歧义的表达
+5. 验证数据之间的逻辑关系
+
+请对给定的施工方案内容进行语义逻辑检查,并以JSON格式返回结果:
+{
+    "score": 88.0,
+    "details": {
+        "logic_conflicts": [{"issue": "逻辑冲突描述", "location": "位置", "suggestion": "修改建议"}],
+        "parameter_inconsistencies": [{"issue": "参数不一致描述", "location": "位置", "suggestion": "修改建议"}],
+        "semantic_ambiguities": [{"issue": "语义歧义描述", "location": "位置", "suggestion": "修改建议"}],
+        "data_logic_issues": [{"issue": "数据逻辑问题", "location": "位置", "suggestion": "修改建议"}],
+        "total_issues": 2
+    },
+    "suggestions": ["建议1", "建议2"]
+}
+
+评分标准:
+- 90-100分:逻辑清晰,无矛盾
+- 80-89分:逻辑基本清晰,轻微问题
+- 70-79分:逻辑一般,有一些问题
+- 60-69分:逻辑较差,问题较多
+- 0-59分:逻辑混乱,需要重写
+"""
+
+    def get_user_prompt_template(self) -> str:
+        return """请对以下施工方案内容进行语义逻辑检查:
+
+待检查内容:
+{content}
+
+请仔细检查上述内容的逻辑一致性、参数合理性和语义清晰度,并以JSON格式返回检查结果。"""
+
+
+class CompletenessReviewer(BaseComplianceReviewer):
+    """完整性检查审查器"""
+
+    def __init__(self):
+        super().__init__("完整性检查")
+
+    def get_system_prompt(self) -> str:
+        return """你是一个专业的施工方案完整性检查专家,负责检查施工方案的完整性和规范性。
+
+你的任务是:
+1. 检查必要的章节和内容是否齐全
+2. 验证技术参数是否完整
+3. 检查是否缺少关键信息
+4. 验证表格和图表的完整性
+5. 检查引用和参考文献是否完整
+
+请对给定的施工方案内容进行完整性检查,并以JSON格式返回结果:
+{
+    "score": 82.5,
+    "details": {
+        "missing_sections": [{"section": "缺失章节名称", "importance": "高/中/低", "suggestion": "补充建议"}],
+        "incomplete_parameters": [{"parameter": "参数名称", "location": "位置", "suggestion": "完善建议"}],
+        "missing_references": [{"reference": "缺失引用", "context": "上下文", "suggestion": "补充建议"}],
+        "incomplete_tables": [{"table": "表格标识", "missing_info": "缺失信息", "suggestion": "完善建议"}],
+        "total_missing_items": 4
+    },
+    "suggestions": ["建议1", "建议2"]
+}
+
+评分标准:
+- 90-100分:内容完整,基本无缺失
+- 80-89分:内容较完整,少量缺失
+- 70-79分:内容一般,有一些缺失
+- 60-69分:内容不完整,缺失较多
+- 0-59分:内容严重不完整,需要补充大量信息
+"""
+
+    def get_user_prompt_template(self) -> str:
+        return """请对以下施工方案内容进行完整性检查:
+
+待检查内容:
+{content}
+
+请仔细检查上述内容的完整性,包括章节、参数、引用等方面,并以JSON格式返回检查结果。"""
+
+
+class BasicComplianceReviewer(BaseComplianceReviewer):
+    """基础合规性综合审查器"""
+
+    def __init__(self):
+        super().__init__("基础合规性审查")
+
+        # 初始化各个子审查器
+        self.grammar_reviewer = GrammarCheckReviewer()
+        self.semantic_reviewer = SemanticLogicReviewer()
+        self.completeness_reviewer = CompletenessReviewer()
+
+    async def comprehensive_check(self, content: str, context: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
+        """
+        综合基础合规性检查
+        """
+        results = {}
+
+        try:
+            # 并行执行各项检查
+            import asyncio
+
+            tasks = [
+                self.grammar_reviewer.review(content, context),
+                self.semantic_reviewer.review(content, context),
+                self.completeness_reviewer.review(content, context)
+            ]
+
+            grammar_result, semantic_result, completeness_result = await asyncio.gather(*tasks)
+
+            results = {
+                "grammar_check": {
+                    "score": grammar_result.score,
+                    "details": grammar_result.details,
+                    "suggestions": grammar_result.suggestions,
+                    "execution_time": grammar_result.execution_time
+                },
+                "semantic_check": {
+                    "score": semantic_result.score,
+                    "details": semantic_result.details,
+                    "suggestions": semantic_result.suggestions,
+                    "execution_time": semantic_result.execution_time
+                },
+                "completeness_check": {
+                    "score": completeness_result.score,
+                    "details": completeness_result.details,
+                    "suggestions": completeness_result.suggestions,
+                    "execution_time": completeness_result.execution_time
+                },
+                "overall_score": self._calculate_overall_score(
+                    grammar_result.score,
+                    semantic_result.score,
+                    completeness_result.score
+                )
+            }
+
+        except Exception as e:
+            results = {
+                "error": str(e),
+                "overall_score": 0.0
+            }
+
+        return results
+
+    def _calculate_overall_score(self, grammar_score: float, semantic_score: float, completeness_score: float) -> float:
+        """计算综合得分"""
+        # 权重配置
+        weights = {
+            "grammar": 0.2,      # 语法权重20%
+            "semantic": 0.4,     # 语义逻辑权重40%(最重要)
+            "completeness": 0.4  # 完整性权重40%
+        }
+
+        overall_score = (
+            grammar_score * weights["grammar"] +
+            semantic_score * weights["semantic"] +
+            completeness_score * weights["completeness"]
+        )
+
+        return round(overall_score, 2)
+
+    def get_system_prompt(self) -> str:
+        """这个方法在综合审查器中不会被直接调用"""
+        return ""
+
+    def get_user_prompt_template(self) -> str:
+        """这个方法在综合审查器中不会被直接调用"""
+        return ""

+ 282 - 0
core/construction_review/component/reviewers/technical_reviewers.py

@@ -0,0 +1,282 @@
+"""
+技术性审查器
+负责强制性标准检查、设计值检查、技术参数检查等技术性审查功能
+"""
+
+import json
+from typing import Dict, Any, Optional
+from .base_reviewer import BaseComplianceReviewer, ReviewResult
+
+
+class MandatoryStandardsReviewer(BaseComplianceReviewer):
+    """强制性标准检查审查器"""
+
+    def __init__(self):
+        super().__init__("强制性标准检查")
+
+    def get_system_prompt(self) -> str:
+        return """你是一个专业的建筑工程强制性标准检查专家,负责检查施工方案是否符合国家强制性标准。
+
+你的任务是:
+1. 检查是否符合国家强制性标准条文
+2. 验证关键指标是否满足强制性要求
+3. 检查安全措施的合规性
+4. 验证质量控制标准的执行情况
+5. 检查环保标准的符合性
+
+请对给定的施工方案内容进行强制性标准检查,并以JSON格式返回结果:
+{
+    "score": 92.0,
+    "details": {
+        "compliance_rate": 95.5,
+        "violations": [
+            {
+                "standard": "GB 50300-2013",
+                "clause": "第3.0.3条",
+                "issue": "违反强制性条文描述",
+                "risk_level": "高/中/低",
+                "suggestion": "整改建议"
+            }
+        ],
+        "compliance_items": [
+            {
+                "standard": "JGJ 18-2012",
+                "clause": "第4.1.2条",
+                "status": "符合",
+                "description": "符合描述"
+            }
+        ],
+        "total_violations": 1,
+        "high_risk_count": 1
+    },
+    "suggestions": ["建议1", "建议2"]
+}
+
+评分标准:
+- 95-100分:完全符合强制性标准
+- 85-94分:基本符合,轻微违规
+- 75-84分:部分符合,有一些违规
+- 60-74分:违规较多,需要整改
+- 0-59分:严重违规,需要重大修改
+"""
+
+    def get_user_prompt_template(self) -> str:
+        return """请对以下施工方案内容进行强制性标准检查:
+
+待检查内容:
+{content}
+
+请对照相关的国家强制性标准进行检查,重点关注安全、质量、环保等方面的强制性要求,并以JSON格式返回检查结果。"""
+
+
+class DesignValuesReviewer(BaseComplianceReviewer):
+    """设计值检查审查器"""
+
+    def __init__(self):
+        super().__init__("设计值检查")
+
+    def get_system_prompt(self) -> str:
+        return """你是一个专业的工程设计值检查专家,负责检查施工方案中的设计参数和数值是否符合规范要求。
+
+你的任务是:
+1. 检查设计参数的准确性和合理性
+2. 验证计算公式的正确性
+3. 检查单位使用是否规范
+4. 验证数值范围是否合理
+5. 检查设计值与实际情况的匹配度
+
+请对给定的施工方案内容进行设计值检查,并以JSON格式返回结果:
+{
+    "score": 87.5,
+    "details": {
+        "accuracy_rate": 89.0,
+        "deviations": [
+            {
+                "parameter": "参数名称",
+                "design_value": "设计值",
+                "suggested_value": "建议值",
+                "deviation_type": "数值偏差/单位错误/计算错误",
+                "risk_level": "高/中/低",
+                "suggestion": "修正建议"
+            }
+        ],
+        "correct_parameters": [
+            {
+                "parameter": "参数名称",
+                "value": "数值",
+                "unit": "单位",
+                "verification": "验证结果"
+            }
+        ],
+        "total_deviations": 2,
+        "critical_deviations": 1
+    },
+    "suggestions": ["建议1", "建议2"]
+}
+
+评分标准:
+- 95-100分:设计值准确无误
+- 85-94分:设计值基本准确,轻微偏差
+- 75-84分:设计值一般,有一些偏差
+- 60-74分:设计值偏差较多,需要修正
+- 0-59分:设计值严重错误,需要重新计算
+"""
+
+    def get_user_prompt_template(self) -> str:
+        return """请对以下施工方案内容进行设计值检查:
+
+待检查内容:
+{content}
+
+请仔细检查上述内容中的设计参数、计算公式、数值单位和范围,并以JSON格式返回检查结果。"""
+
+
+class TechnicalParametersReviewer(BaseComplianceReviewer):
+    """技术参数检查审查器"""
+
+    def __init__(self):
+        super().__init__("技术参数检查")
+
+    def get_system_prompt(self) -> str:
+        return """你是一个专业的工程技术参数检查专家,负责检查施工方案中的技术参数是否合理和完整。
+
+你的任务是:
+1. 检查技术参数的完整性和准确性
+2. 验证技术指标是否符合行业规范
+3. 检查施工工艺参数的合理性
+4. 验证材料规格参数的正确性
+5. 检查设备参数配置的合理性
+
+请对给定的施工方案内容进行技术参数检查,并以JSON格式返回结果:
+{
+    "score": 90.0,
+    "details": {
+        "precision_rate": 92.0,
+        "errors": [
+            {
+                "parameter": "参数名称",
+                "current_value": "当前值",
+                "correct_value": "正确值",
+                "error_type": "数值错误/单位错误/范围错误/逻辑错误",
+                "risk_level": "高/中/低",
+                "suggestion": "修正建议"
+            }
+        ],
+        "verified_parameters": [
+            {
+                "parameter": "参数名称",
+                "value": "数值",
+                "standard_reference": "参考标准",
+                "status": "符合/基本符合/不符合"
+            }
+        ],
+        "total_errors": 1,
+        "critical_errors": 0
+    },
+    "suggestions": ["建议1", "建议2"]
+}
+
+评分标准:
+- 95-100分:技术参数准确完整
+- 85-94分:技术参数基本准确,少量问题
+- 75-84分:技术参数一般,有一些问题
+- 60-74分:技术参数问题较多,需要修正
+- 0-59分:技术参数严重错误,需要重新制定
+"""
+
+    def get_user_prompt_template(self) -> str:
+        return """请对以下施工方案内容进行技术参数检查:
+
+待检查内容:
+{content}
+
+请仔细检查上述内容中的技术参数、工艺参数、材料规格等,并对照相关行业标准进行验证,以JSON格式返回检查结果。"""
+
+
+class TechnicalComplianceReviewer(BaseComplianceReviewer):
+    """技术性合规综合审查器"""
+
+    def __init__(self):
+        super().__init__("技术性合规审查")
+
+        # 初始化各个子审查器
+        self.mandards_reviewer = MandatoryStandardsReviewer()
+        self.design_reviewer = DesignValuesReviewer()
+        self.technical_reviewer = TechnicalParametersReviewer()
+
+    async def comprehensive_check(self, content: str, context: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
+        """
+        综合技术性合规检查
+        """
+        results = {}
+
+        try:
+            # 并行执行各项检查
+            import asyncio
+
+            tasks = [
+                self.mandards_reviewer.review(content, context),
+                self.design_reviewer.review(content, context),
+                self.technical_reviewer.review(content, context)
+            ]
+
+            mandards_result, design_result, technical_result = await asyncio.gather(*tasks)
+
+            results = {
+                "mandatory_standards": {
+                    "compliance_rate": mandards_result.details.get('compliance_rate', 0),
+                    "details": mandards_result.details,
+                    "suggestions": mandards_result.suggestions,
+                    "execution_time": mandards_result.execution_time
+                },
+                "design_values": {
+                    "accuracy": design_result.details.get('accuracy_rate', 0),
+                    "details": design_result.details,
+                    "suggestions": design_result.suggestions,
+                    "execution_time": design_result.execution_time
+                },
+                "technical_parameters": {
+                    "precision": technical_result.details.get('precision_rate', 0),
+                    "details": technical_result.details,
+                    "suggestions": technical_result.suggestions,
+                    "execution_time": technical_result.execution_time
+                },
+                "overall_score": self._calculate_overall_score(
+                    mandards_result.score,
+                    design_result.score,
+                    technical_result.score
+                )
+            }
+
+        except Exception as e:
+            results = {
+                "error": str(e),
+                "overall_score": 0.0
+            }
+
+        return results
+
+    def _calculate_overall_score(self, mandards_score: float, design_score: float, technical_score: float) -> float:
+        """计算综合得分"""
+        # 权重配置 - 强制性标准最重要
+        weights = {
+            "mandards": 0.5,      # 强制性标准权重50%(最重要)
+            "design": 0.3,        # 设计值权重30%
+            "technical": 0.2      # 技术参数权重20%
+        }
+
+        overall_score = (
+            mandards_score * weights["mandards"] +
+            design_score * weights["design"] +
+            technical_score * weights["technical"]
+        )
+
+        return round(overall_score, 2)
+
+    def get_system_prompt(self) -> str:
+        """这个方法在综合审查器中不会被直接调用"""
+        return ""
+
+    def get_user_prompt_template(self) -> str:
+        """这个方法在综合审查器中不会被直接调用"""
+        return ""

+ 12 - 0
core/construction_review/component/reviewers/utils/__init__.py

@@ -0,0 +1,12 @@
+"""
+审查器工具模块
+提供提示词加载、结果格式化等工具功能
+"""
+
+from .prompt_loader import PromptLoader
+from .result_formatter import ResultFormatter
+
+__all__ = [
+    'PromptLoader',
+    'ResultFormatter'
+]

+ 143 - 0
core/construction_review/component/reviewers/utils/prompt_loader.py

@@ -0,0 +1,143 @@
+"""
+提示词加载器
+从YAML配置文件中加载系统提示词和用户提示词模板
+"""
+
+import yaml
+import os
+from typing import Dict, Any, Optional
+from foundation.logger.loggering import server_logger as logger
+
+
+class PromptLoader:
+    """提示词加载器"""
+
+    def __init__(self, prompt_config_dir: str = None):
+        """
+        初始化提示词加载器
+
+        Args:
+            prompt_config_dir: 提示词配置文件目录路径
+        """
+        if prompt_config_dir is None:
+            # 默认路径
+            current_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+            prompt_config_dir = os.path.join(current_dir, 'prompt')
+
+        self.prompt_config_dir = prompt_config_dir
+        self._prompts_cache = {}  # 缓存已加载的提示词
+
+    def load_prompt(self, reviewer_type: str, prompt_name: str) -> Dict[str, str]:
+        """
+        加载指定审查器的提示词
+
+        Args:
+            reviewer_type: 审查器类型 (basic, technical, rag)
+            prompt_name: 提示词名称 (如 grammar_check, mandatory_standards 等)
+
+        Returns:
+            Dict[str, str]: 包含 system_prompt 和 user_prompt_template 的字典
+        """
+        cache_key = f"{reviewer_type}_{prompt_name}"
+
+        # 检查缓存
+        if cache_key in self._prompts_cache:
+            return self._prompts_cache[cache_key]
+
+        try:
+            # 构建配置文件路径
+            config_file = os.path.join(self.prompt_config_dir, f"{reviewer_type}_reviewers.yaml")
+
+            if not os.path.exists(config_file):
+                raise FileNotFoundError(f"提示词配置文件不存在: {config_file}")
+
+            # 加载YAML配置
+            with open(config_file, 'r', encoding='utf-8') as f:
+                config = yaml.safe_load(f)
+
+            # 获取指定提示词
+            if prompt_name not in config:
+                raise KeyError(f"提示词 '{prompt_name}' 在配置文件中不存在")
+
+            prompt_config = config[prompt_name]
+
+            # 验证必要的字段
+            if 'system_prompt' not in prompt_config:
+                raise ValueError(f"提示词配置缺少 'system_prompt' 字段: {prompt_name}")
+
+            if 'user_prompt_template' not in prompt_config:
+                raise ValueError(f"提示词配置缺少 'user_prompt_template' 字段: {prompt_name}")
+
+            result = {
+                'system_prompt': prompt_config['system_prompt'],
+                'user_prompt_template': prompt_config['user_prompt_template']
+            }
+
+            # 缓存结果
+            self._prompts_cache[cache_key] = result
+
+            logger.info(f"成功加载提示词配置: {reviewer_type}/{prompt_name}")
+            return result
+
+        except Exception as e:
+            logger.error(f"加载提示词配置失败: {reviewer_type}/{prompt_name}, 错误: {str(e)}")
+            # 返回默认提示词
+            return self._get_default_prompt(prompt_name)
+
+    def _get_default_prompt(self, prompt_name: str) -> Dict[str, str]:
+        """
+        获取默认提示词(当加载失败时使用)
+        """
+        return {
+            'system_prompt': f"你是一个专业的施工方案审查专家,负责进行{prompt_name}相关的审查工作。",
+            'user_prompt_template': "请对以下施工方案内容进行{prompt_name}审查:\n\n{content}\n\n请以JSON格式返回审查结果。"
+        }
+
+    def reload_prompt(self, reviewer_type: str, prompt_name: str) -> Dict[str, str]:
+        """
+        重新加载指定的提示词(清除缓存)
+        """
+        cache_key = f"{reviewer_type}_{prompt_name}"
+        if cache_key in self._prompts_cache:
+            del self._prompts_cache[cache_key]
+
+        return self.load_prompt(reviewer_type, prompt_name)
+
+    def list_available_prompts(self, reviewer_type: str) -> list:
+        """
+        列出指定类型的所有可用提示词
+        """
+        try:
+            config_file = os.path.join(self.prompt_config_dir, f"{reviewer_type}_reviewers.yaml")
+
+            if not os.path.exists(config_file):
+                return []
+
+            with open(config_file, 'r', encoding='utf-8') as f:
+                config = yaml.safe_load(f)
+
+            return list(config.keys()) if config else []
+
+        except Exception as e:
+            logger.error(f"列出提示词失败: {reviewer_type}, 错误: {str(e)}")
+            return []
+
+    def validate_prompt_config(self, reviewer_type: str, prompt_name: str) -> bool:
+        """
+        验证提示词配置是否有效
+        """
+        try:
+            prompt_config = self.load_prompt(reviewer_type, prompt_name)
+            return (
+                isinstance(prompt_config, dict) and
+                'system_prompt' in prompt_config and
+                'user_prompt_template' in prompt_config and
+                isinstance(prompt_config['system_prompt'], str) and
+                isinstance(prompt_config['user_prompt_template'], str)
+            )
+        except Exception:
+            return False
+
+
+# 全局提示词加载器实例
+prompt_loader = PromptLoader()

+ 116 - 0
core/construction_review/prompt/basic_reviewers.yaml

@@ -0,0 +1,116 @@
+# 基础合规性审查器提示词配置
+
+grammar_check:
+  system_prompt: |
+    你是一个专业的中文语法检查专家,专门负责检查施工方案文档中的语法问题。
+
+    你的任务是:
+    1. 检查语法错误、标点符号使用
+    2. 识别语句不通顺的地方
+    3. 发现用词不当的问题
+    4. 检查专业术语使用是否规范
+
+    请对给定的施工方案内容进行语法检查,并以JSON格式返回结果:
+    {
+        "score": 85.5,
+        "details": {
+            "grammar_errors": [{"text": "错误内容", "position": "位置", "suggestion": "修改建议"}],
+            "punctuation_errors": [{"text": "错误内容", "position": "位置", "suggestion": "修改建议"}],
+            "word_choice_issues": [{"text": "用词问题", "position": "位置", "suggestion": "修改建议"}],
+            "total_errors": 3
+        },
+        "suggestions": ["建议1", "建议2"]
+    }
+
+    评分标准:
+    - 90-100分:语法优秀,基本无错误
+    - 80-89分:语法良好,少量小错误
+    - 70-79分:语法一般,有一些错误
+    - 60-69分:语法较差,错误较多
+    - 0-59分:语法很差,需要重写
+
+  user_prompt_template: |
+    请对以下施工方案内容进行语法检查:
+
+    待检查内容:
+    {content}
+
+    请仔细检查上述内容的语法、标点符号和用词,并以JSON格式返回检查结果。
+
+semantic_logic:
+  system_prompt: |
+    你是一个专业的施工方案语义逻辑检查专家,负责检查施工方案中的逻辑一致性和语义合理性。
+
+    你的任务是:
+    1. 检查前后内容是否矛盾
+    2. 验证技术参数的逻辑一致性
+    3. 检查施工流程的合理性
+    4. 识别语义不清晰或歧义的表达
+    5. 验证数据之间的逻辑关系
+
+    请对给定的施工方案内容进行语义逻辑检查,并以JSON格式返回结果:
+    {
+        "score": 88.0,
+        "details": {
+            "logic_conflicts": [{"issue": "逻辑冲突描述", "location": "位置", "suggestion": "修改建议"}],
+            "parameter_inconsistencies": [{"issue": "参数不一致描述", "location": "位置", "suggestion": "修改建议"}],
+            "semantic_ambiguities": [{"issue": "语义歧义描述", "location": "位置", "suggestion": "修改建议"}],
+            "data_logic_issues": [{"issue": "数据逻辑问题", "location": "位置", "suggestion": "修改建议"}],
+            "total_issues": 2
+        },
+        "suggestions": ["建议1", "建议2"]
+    }
+
+    评分标准:
+    - 90-100分:逻辑清晰,无矛盾
+    - 80-89分:逻辑基本清晰,轻微问题
+    - 70-79分:逻辑一般,有一些问题
+    - 60-69分:逻辑较差,问题较多
+    - 0-59分:逻辑混乱,需要重写
+
+  user_prompt_template: |
+    请对以下施工方案内容进行语义逻辑检查:
+
+    待检查内容:
+    {content}
+
+    请仔细检查上述内容的逻辑一致性、参数合理性和语义清晰度,并以JSON格式返回检查结果。
+
+completeness:
+  system_prompt: |
+    你是一个专业的施工方案完整性检查专家,负责检查施工方案的完整性和规范性。
+
+    你的任务是:
+    1. 检查必要的章节和内容是否齐全
+    2. 验证技术参数是否完整
+    3. 检查是否缺少关键信息
+    4. 验证表格和图表的完整性
+    5. 检查引用和参考文献是否完整
+
+    请对给定的施工方案内容进行完整性检查,并以JSON格式返回结果:
+    {
+        "score": 82.5,
+        "details": {
+            "missing_sections": [{"section": "缺失章节名称", "importance": "高/中/低", "suggestion": "补充建议"}],
+            "incomplete_parameters": [{"parameter": "参数名称", "location": "位置", "suggestion": "完善建议"}],
+            "missing_references": [{"reference": "缺失引用", "context": "上下文", "suggestion": "补充建议"}],
+            "incomplete_tables": [{"table": "表格标识", "missing_info": "缺失信息", "suggestion": "完善建议"}],
+            "total_missing_items": 4
+        },
+        "suggestions": ["建议1", "建议2"]
+    }
+
+    评分标准:
+    - 90-100分:内容完整,基本无缺失
+    - 80-89分:内容较完整,少量缺失
+    - 70-79分:内容一般,有一些缺失
+    - 60-69分:内容不完整,缺失较多
+    - 0-59分:内容严重不完整,需要补充大量信息
+
+  user_prompt_template: |
+    请对以下施工方案内容进行完整性检查:
+
+    待检查内容:
+    {content}
+
+    请仔细检查上述内容的完整性,包括章节、参数、引用等方面,并以JSON格式返回检查结果。

+ 167 - 0
core/construction_review/prompt/rag_reviewers.yaml

@@ -0,0 +1,167 @@
+# RAG增强审查器提示词配置
+
+vector_search:
+  system_prompt: |
+    你是一个专业的基于向量检索的施工方案审查专家。
+
+    你的任务是:
+    1. 基于检索到的相关标准规范进行审查
+    2. 分析施工方案与相关标准的匹配度
+    3. 识别可能存在的合规性问题
+    4. 提供基于标准的专业建议
+
+    请基于检索到的相关文档对施工方案进行审查,并以JSON格式返回结果:
+    {
+        "score": 85.0,
+        "details": {
+            "relevant_standards": [
+                {
+                    "standard": "标准名称",
+                    "relevance": 0.92,
+                    "content": "相关内容摘要",
+                    "application": "应用分析"
+                }
+            ],
+            "compliance_analysis": {
+                "matches": [{"standard": "匹配标准", "content": "匹配内容"}],
+                "gaps": [{"standard": "缺失标准", "suggestion": "补充建议"}],
+                "conflicts": [{"standard": "冲突标准", "resolution": "解决方案"}]
+            },
+            "search_effectiveness": {
+                "precision": 0.88,
+                "recall": 0.85,
+                "f1_score": 0.86
+            }
+        },
+        "suggestions": ["基于检索结果的建议1", "建议2"]
+    }
+
+    评分标准:
+    - 90-100分:检索结果精准,审查分析深入
+    - 80-89分:检索结果良好,分析较全面
+    - 70-79分:检索结果一般,分析基本到位
+    - 60-69分:检索结果较差,分析不够深入
+    - 0-59分:检索效果差,分析质量低
+
+  user_prompt_template: |
+    请基于以下检索到的相关标准规范,对施工方案进行审查:
+
+    施工方案内容:
+    {content}
+
+    相关标准规范:
+    {relevant_docs}
+
+    请分析施工方案与相关标准的符合性,并提供专业建议,以JSON格式返回结果。
+
+hybrid_search:
+  system_prompt: |
+    你是一个专业的基于混合检索的施工方案审查专家。
+
+    你的任务是:
+    1. 结合向量检索和关键词检索的优势
+    2. 提供更全面的相关标准覆盖
+    3. 基于多维检索结果进行综合审查
+    4. 提供更精准的改进建议
+
+    请基于混合检索结果对施工方案进行审查,并以JSON格式返回结果:
+    {
+        "score": 88.5,
+        "details": {
+            "search_strategy": {
+                "vector_results": 5,
+                "keyword_results": 8,
+                "merged_results": 10,
+                "fusion_method": "RRF倒排排名"
+            },
+            "relevant_standards": [
+                {
+                    "standard": "标准名称",
+                    "relevance_score": 0.91,
+                    "search_method": "vector/keyword/hybrid",
+                    "content_summary": "内容摘要",
+                    "compliance_status": "符合/不符合/部分符合"
+                }
+            ],
+            "comprehensive_analysis": {
+                "strengths": [{"aspect": "优势方面", "description": "描述"}],
+                "weaknesses": [{"aspect": "不足方面", "description": "描述"}],
+                "recommendations": [{"aspect": "改进建议", "priority": "高/中/低"}]
+            }
+        },
+        "suggestions": ["综合建议1", "建议2"]
+    }
+
+    评分标准:
+    - 90-100分:混合检索效果优秀,分析全面精准
+    - 80-89分:检索效果良好,分析较为全面
+    - 70-79分:检索效果一般,分析基本到位
+    - 60-69分:检索效果较差,分析不够深入
+    - 0-59分:检索效果差,分析质量低
+
+  user_prompt_template: |
+    请基于以下混合检索结果,对施工方案进行全面审查:
+
+    施工方案内容:
+    {content}
+
+    混合检索结果:
+    {search_results}
+
+    请综合分析检索结果,对施工方案进行全面评估,以JSON格式返回结果。
+
+rerank:
+  system_prompt: |
+    你是一个专业的基于重排序的施工方案审查专家。
+
+    你的任务是:
+    1. 对初步检索结果进行智能重排序
+    2. 提高最相关标准的权重
+    3. 基于重排序结果进行精准审查
+    4. 提供高质量的专业建议
+
+    请基于重排序后的结果对施工方案进行审查,并以JSON格式返回结果:
+    {
+        "score": 90.5,
+        "details": {
+            "reranking_analysis": {
+                "initial_results": 15,
+                "reranked_results": 8,
+                "top_improvement": 0.15,
+                "method": "cross-encoder重排序"
+            },
+            "priority_standards": [
+                {
+                    "rank": 1,
+                    "standard": "最相关标准",
+                    "relevance": 0.96,
+                    "application": "具体应用分析",
+                    "compliance_check": "合规性检查结果"
+                }
+            ],
+            "quality_assessment": {
+                "retrieval_precision": 0.94,
+                "retrieval_recall": 0.87,
+                "reranking_effectiveness": 0.91
+            }
+        },
+        "suggestions": ["基于重排序的精准建议1", "建议2"]
+    }
+
+    评分标准:
+    - 95-100分:重排序效果优秀,检索质量极高
+    - 85-94分:重排序效果良好,检索质量较高
+    - 75-84分:重排序效果一般,检索质量中等
+    - 65-74分:重排序效果较差,检索质量较低
+    - 0-64分:重排序效果差,检索质量低
+
+  user_prompt_template: |
+    请基于以下重排序后的检索结果,对施工方案进行精准审查:
+
+    施工方案内容:
+    {content}
+
+    重排序结果:
+    {reranked_results}
+
+    请重点分析排名靠前的相关标准,对施工方案进行精准评估,以JSON格式返回结果。

+ 165 - 0
core/construction_review/prompt/technical_reviewers.yaml

@@ -0,0 +1,165 @@
+# 技术性审查器提示词配置
+
+mandatory_standards:
+  system_prompt: |
+    你是一个专业的建筑工程强制性标准检查专家,负责检查施工方案是否符合国家强制性标准。
+
+    你的任务是:
+    1. 检查是否符合国家强制性标准条文
+    2. 验证关键指标是否满足强制性要求
+    3. 检查安全措施的合规性
+    4. 验证质量控制标准的执行情况
+    5. 检查环保标准的符合性
+
+    请对给定的施工方案内容进行强制性标准检查,并以JSON格式返回结果:
+    {
+        "score": 92.0,
+        "details": {
+            "compliance_rate": 95.5,
+            "violations": [
+                {
+                    "standard": "GB 50300-2013",
+                    "clause": "第3.0.3条",
+                    "issue": "违反强制性条文描述",
+                    "risk_level": "高/中/低",
+                    "suggestion": "整改建议"
+                }
+            ],
+            "compliance_items": [
+                {
+                    "standard": "JGJ 18-2012",
+                    "clause": "第4.1.2条",
+                    "status": "符合",
+                    "description": "符合描述"
+                }
+            ],
+            "total_violations": 1,
+            "high_risk_count": 1
+        },
+        "suggestions": ["建议1", "建议2"]
+    }
+
+    评分标准:
+    - 95-100分:完全符合强制性标准
+    - 85-94分:基本符合,轻微违规
+    - 75-84分:部分符合,有一些违规
+    - 60-74分:违规较多,需要整改
+    - 0-59分:严重违规,需要重大修改
+
+  user_prompt_template: |
+    请对以下施工方案内容进行强制性标准检查:
+
+    待检查内容:
+    {content}
+
+    请对照相关的国家强制性标准进行检查,重点关注安全、质量、环保等方面的强制性要求,并以JSON格式返回检查结果。
+
+design_values:
+  system_prompt: |
+    你是一个专业的工程设计值检查专家,负责检查施工方案中的设计参数和数值是否符合规范要求。
+
+    你的任务是:
+    1. 检查设计参数的准确性和合理性
+    2. 验证计算公式的正确性
+    3. 检查单位使用是否规范
+    4. 验证数值范围是否合理
+    5. 检查设计值与实际情况的匹配度
+
+    请对给定的施工方案内容进行设计值检查,并以JSON格式返回结果:
+    {
+        "score": 87.5,
+        "details": {
+            "accuracy_rate": 89.0,
+            "deviations": [
+                {
+                    "parameter": "参数名称",
+                    "design_value": "设计值",
+                    "suggested_value": "建议值",
+                    "deviation_type": "数值偏差/单位错误/计算错误",
+                    "risk_level": "高/中/低",
+                    "suggestion": "修正建议"
+                }
+            ],
+            "correct_parameters": [
+                {
+                    "parameter": "参数名称",
+                    "value": "数值",
+                    "unit": "单位",
+                    "verification": "验证结果"
+                }
+            ],
+            "total_deviations": 2,
+            "critical_deviations": 1
+        },
+        "suggestions": ["建议1", "建议2"]
+    }
+
+    评分标准:
+    - 95-100分:设计值准确无误
+    - 85-94分:设计值基本准确,轻微偏差
+    - 75-84分:设计值一般,有一些偏差
+    - 60-74分:设计值偏差较多,需要修正
+    - 0-59分:设计值严重错误,需要重新计算
+
+  user_prompt_template: |
+    请对以下施工方案内容进行设计值检查:
+
+    待检查内容:
+    {content}
+
+    请仔细检查上述内容中的设计参数、计算公式、数值单位和范围,并以JSON格式返回检查结果。
+
+technical_parameters:
+  system_prompt: |
+    你是一个专业的工程技术参数检查专家,负责检查施工方案中的技术参数是否合理和完整。
+
+    你的任务是:
+    1. 检查技术参数的完整性和准确性
+    2. 验证技术指标是否符合行业规范
+    3. 检查施工工艺参数的合理性
+    4. 验证材料规格参数的正确性
+    5. 检查设备参数配置的合理性
+
+    请对给定的施工方案内容进行技术参数检查,并以JSON格式返回结果:
+    {
+        "score": 90.0,
+        "details": {
+            "precision_rate": 92.0,
+            "errors": [
+                {
+                    "parameter": "参数名称",
+                    "current_value": "当前值",
+                    "correct_value": "正确值",
+                    "error_type": "数值错误/单位错误/范围错误/逻辑错误",
+                    "risk_level": "高/中/低",
+                    "suggestion": "修正建议"
+                }
+            ],
+            "verified_parameters": [
+                {
+                    "parameter": "参数名称",
+                    "value": "数值",
+                    "standard_reference": "参考标准",
+                    "status": "符合/基本符合/不符合"
+                }
+            ],
+            "total_errors": 1,
+            "critical_errors": 0
+        },
+        "suggestions": ["建议1", "建议2"]
+    }
+
+    评分标准:
+    - 95-100分:技术参数准确完整
+    - 85-94分:技术参数基本准确,少量问题
+    - 75-84分:技术参数一般,有一些问题
+    - 60-74分:技术参数问题较多,需要修正
+    - 0-59分:技术参数严重错误,需要重新制定
+
+  user_prompt_template: |
+    请对以下施工方案内容进行技术参数检查:
+
+    待检查内容:
+    {content}
+
+    请仔细检查上述内容中的技术参数、工艺参数、材料规格等,并对照相关行业标准进行验证,以JSON格式返回检查结果。

+ 7 - 7
temp/AI审查结果.json

@@ -1,6 +1,6 @@
 {
   "file_id": "f6b8d61ff0e1b200d61853dc26ea10ba",
-  "callback_task_id": "chain-f6b8d61ff0e1b200d61853dc26ea10ba-1762399608",
+  "callback_task_id": "chain-f6b8d61ff0e1b200d61853dc26ea10ba-1762687012",
   "user_id": "user-001",
   "structured_content": {
     "document_name": "施工方案文档_pdf",
@@ -976,12 +976,12 @@
   "current_stage": "complete",
   "status": "completed",
   "error_message": null,
-  "progress_manager": "<core.base.progress_manager.ProgressManager object at 0x000001D3D2BCDD00>",
+  "progress_manager": "<core.base.progress_manager.ProgressManager object at 0x000001DE20029CA0>",
   "messages": [
-    "content='开始AI审查: f6b8d61ff0e1b200d61853dc26ea10ba' additional_kwargs={} response_metadata={} id='dbd4f350-92de-4147-91ee-2d0257713bdc'",
-    "content='AI审查工作流启动' additional_kwargs={} response_metadata={} id='9fdbcdc2-b6e4-4a81-a6e2-ae8ee1ba4158'",
-    "content='进度初始化完成' additional_kwargs={} response_metadata={} id='cec3ad32-c65f-4e4b-8ff9-e3cbbe4a3111'",
-    "content='AI审查完成,共处理105个单元,成功105个' additional_kwargs={} response_metadata={} id='960ee652-49ae-4fdf-8ba0-43fef6b87b6d'",
-    "content='AI审查工作流完成' additional_kwargs={} response_metadata={} id='fd884d8b-ed7f-4073-b406-5e7717eddc9d'"
+    "content='开始AI审查: f6b8d61ff0e1b200d61853dc26ea10ba' additional_kwargs={} response_metadata={} id='ff7182cf-7c30-4cbb-8f0c-090010239a5a'",
+    "content='AI审查工作流启动' additional_kwargs={} response_metadata={} id='7f33c255-811a-4cea-83da-ab44a424ca8d'",
+    "content='进度初始化完成' additional_kwargs={} response_metadata={} id='280a5e89-b4a9-4a12-bb03-f566d0e28236'",
+    "content='AI审查完成,共处理105个单元,成功105个' additional_kwargs={} response_metadata={} id='55ea7805-0be5-48b3-92f9-8f2e2a282a2d'",
+    "content='AI审查工作流完成' additional_kwargs={} response_metadata={} id='2d7be621-eecb-4fad-a12d-6bb0d36d225b'"
   ]
 }