Преглед изворни кода

chore: 更新配置文件、文档与 .gitignore

同步 config.ini.template 模板、model_setting.yaml 模型路由、README 架构说明,
排除 .sync-conflict 文件,更新入库脚本。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
WangXuMing пре 1 недеља
родитељ
комит
632e360e12

+ 1 - 1
.gitignore

@@ -62,7 +62,7 @@ docs/_build/
 
 # PyBuilder
 target/
-
+life_cycle_process/
 todo.md
 .design/
 .claude/

+ 7 - 0
.vscode/settings.json

@@ -4,5 +4,12 @@
     "python-envs.defaultPackageManager": "ms-python.python:conda",
     "python.analysis.extraPaths": [
         "../your_env_name/Lib/site-packages"
+    ],
+    "python-envs.pythonProjects": [
+        {
+            "path": "utils_test",
+            "envManager": "ms-python.python:conda",
+            "packageManager": "ms-python.python:conda"
+        }
     ]
 }

+ 74 - 153
README.md

@@ -1,156 +1,77 @@
-### LQAgentPlatform
+# LQAgentPlatform
 
- 
-
- ### LQAgentPlatform 智能体应用服务
- - 环境安装
-   - pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
- - 后端启动服务
-    - cd LQAgentPlatform
-    - uvicorn server.app:app --port=8001 --host=0.0.0.0
-    - gunicorn -c gunicorn_config.py server.app:app       多进程启动
-
-    - python .\views\construction_review\app.py
-
-
-  
-
-
-
-  
-    pip install aioredis -i https://mirrors.aliyun.com/pypi/simple/
-    pip install langgraph-checkpoint-postgres -i https://mirrors.aliyun.com/pypi/simple/
-    pip install langchain-redis -i https://mirrors.aliyun.com/pypi/simple/
-
-
-### 增加组件依赖
-  pip install aiomysql -i https://mirrors.aliyun.com/pypi/simple/
-
-
-
-### 向量模型和重排序模型测试
-  cd LQAgentPlatform
-  python foundation/models/silicon_flow.py
-
-
-
-### 测试接口
-
-  #### 生成模型接口 
-    - chat
-        http://localhost:8001/test/generate/chat
-        {
-          "config": {
-              "session_id":"111"
-          },
-          "input": "你好"
-        }
-    - stream
-      http://localhost:8001/test/generate/stream
-        {
-          "config": {
-              "session_id":"111"
-          },
-          "input": "你好,我叫小红,你叫什么?"
-        }
-
-
-
-  #### agent 智能体
-    - chat
-      http://localhost:8001/test/agent/stream
-        {
-          "config": {
-              "session_id":"111"
-          },
-          "input": "你好"
-        }
-
-    - stream
-curl -X POST "http://localhost:8001/test/agent/stream" \
--H "Content-Type: application/json" \
--d '{
-    "config": {
-        "session_id": "111"
-    },
-    "input": "你好"
-}'
-
-  #### Workflow-Graph stream
-    - chat
-      http://localhost:8001/test/graph/stream
-        {
-          "config": {
-              "session_id":"111"
-          },
-          "input": "你好"
-        }
-
-    - agent
-      http://localhost:8001/test/graph/stream
-        {
-          "config": {
-              "session_id":"111"
-          },
-          "input": "查询信息"
-        }
-
-
-### MySQL 数据库操作测试
-  - 新增
-        http://localhost:8001/test/mysql/add
-        {
-          "config": {
-              "session_id":"10002"
-          },
-          "input": "张三"
-        }
-    - 查询列表
-      http://localhost:8001/test/mysql/list
-       {
-        "config": {
-            "session_id":"10002"
-        },
-        "input": "张三"
-      }
-
-     - 查询单个
-      http://localhost:8001/test/mysql/get
-       {
-        "config": {
-            "session_id":"10002"
-        },
-        "input": "4"
-      }
-
-      - 修改
-        http://localhost:8001/test/mysql/update
-        {
-          "config": {
-              "session_id":"1"
-          },
-          "input": "李四"
-        }
-      
-
-
-#### 向量检索测试
-  - 向量检索测试
-   http://localhost:8001/test/bfp/search
-   {
-      "config": {
-          "session_id":"20"
-      },
-      "input": "安全生产条件"
-    }
-
-  - 向量检索和重排序测试
-    - http://localhost:8001/test/bfp/search/rerank
-    {
-      "config": {
-          "session_id":"20"
-      },
-      "input": "安全生产条件"
-    }
+施工方案智能审查与编写系统(FastAPI + LangGraph + Celery)
 
+## 环境安装
 
+```bash
+# 1. 安装生产依赖
+pip install -r requirements/base.txt -i https://mirrors.aliyun.com/pypi/simple/
+
+# 2. 安装开发依赖(可选,含 pytest/ruff/mypy)
+pip install -r requirements/dev.txt -i https://mirrors.aliyun.com/pypi/simple/
+
+# 3. 注册项目路径(替代 sys.path.insert,秒级完成)
+pip install -e .
+```
+
+## 启动服务
+
+```bash
+# 开发模式(单进程)
+uvicorn server.app:app --port=8001 --host=0.0.0.0
+
+# 开发模式(含 Celery Worker)
+python server/app.py --host 0.0.0.0 --port 8001
+
+# 生产模式(多进程)
+gunicorn -c gunicorn_config.py server.app:app
+```
+
+## Docker 部署
+
+```bash
+# 首次或依赖变更时:构建 base 镜像(耗时较长)
+docker build -f Dockerfile.base -t lq-agent-base:latest .
+
+# 日常构建:秒级(仅复制源码)
+docker build -t lq_agent_platform_server_dev:v1.0 .
+
+# 启动
+docker-compose -f docker/docker-compose.yml up -d
+```
+
+## 运行测试
+
+```bash
+pytest utils_test/<TestDir>/
+```
+
+## 项目结构
+
+```
+server/          — 应用入口(app/factory/routes/celery_manager/runner)
+views/           — API 路由层
+core/            — 业务逻辑(审查引擎、编写引擎、工作流编排)
+foundation/      — 基础设施(AI 模型、数据库、Redis、Celery、链路追踪)
+config/          — 配置文件 & Prompt 模板
+requirements/    — 依赖清单(base.txt 生产 / dev.txt 开发)
+data_pipeline/   — Milvus 向量库灌入工具
+utils_test/      — 按模块组织的测试套件
+```
+
+## API 路由前缀
+
+| 前缀 | 功能 |
+|------|------|
+| `/sgsc` | 施工方案审查 |
+| `/sgbx` | 施工方案编写 |
+| `/health` | 健康检查 |
+| `/celery/status` | Celery 状态 |
+
+## 架构约束
+
+- `views/` 禁止直接导入 `foundation/database/`
+- `core/component/` 禁止直接导入 `foundation/database/`
+- 配置读取通过 `config_handler.get(section, key)`
+- 提交前运行 `python scripts/check_imports.py`

+ 11 - 1
config/config.ini

@@ -174,6 +174,11 @@ SHUTIAN_8B_SERVER_URL=http://183.220.37.46:25424/v1
 SHUTIAN_8B_MODEL_ID=/model/Qwen3-8B
 SHUTIAN_8B_API_KEY=sk_prod_SELVoIV1d3gku28koH_ONg8L_B2cQis__71f55615
 
+# Qwen3.6-27B 模型(端口25424)
+SHUTIAN_27B_SERVER_URL=http://183.220.37.46:25424/v1
+SHUTIAN_27B_MODEL_ID=/model/Qwen3.6-27B
+SHUTIAN_27B_API_KEY=sk_prod_SELVoIV1d3gku28koH_ONg8L_B2cQis__71f55615
+
 # Qwen3.5-35B 模型(端口25427)
 SHUTIAN_35B_SERVER_URL=http://183.220.37.46:25427/v1
 SHUTIAN_35B_MODEL_ID=/model/Qwen3.5-35B
@@ -194,7 +199,6 @@ SHUTIAN_RERANK_API_KEY=sk_prod_SELVoIV1d3gku28koH_ONg8L_B2cQis__71f55615
 MILVUS_HOST=192.168.92.96
 MILVUS_PORT=30129
 MILVUS_DB=lq_db
-MILVUS_COLLECTION=first_bfp_collection_test
 MILVUS_USER=
 MILVUS_PASSWORD=
 
@@ -204,6 +208,12 @@ MILVUS_PASSWORD=
 DENSE_WEIGHT=0.3
 SPARSE_WEIGHT=0.7
 
+[rag_collections]
+# RAG 检索链路使用的 Milvus 集合名
+ENTITY_COLLECTION=first_bfp_collection_entity
+CHILDREN_COLLECTION=t_rag_kng_standard # 子分段集合
+PARENT_COLLECTION=t_rag_kng_standard_parent # 父分段集合
+
 
 # ============================================================
 # DashScope Qwen3.5 系列模型配置

+ 12 - 14
config/config.ini.template

@@ -3,7 +3,7 @@
 [model]
 # 注意:模型配置已迁移到 model_setting.yaml
 # 请通过 config/model_config_loader.py 获取模型配置
-# Embedding模型类型选择: lq_qwen3_8b_emd, siliconflow_embed, shutian_qwen3_embed
+# Embedding模型类型选择: shutian_qwen3_embed, siliconflow_embed
 EMBEDDING_MODEL_TYPE=shutian_qwen3_embed
 
 # Rerank模型类型选择: bge_rerank_model, lq_rerank_model, silicoflow_rerank_model
@@ -26,12 +26,6 @@ QWEN_SERVER_URL=http://192.168.91.253:8003/v1/
 QWEN_MODEL_ID=qwen3-30b
 QWEN_API_KEY=sk-123456
 
-# Qwen3-30B 独立配置(与qwen配置相同,方便后续独立管理)
-[qwen3_30b]
-QWEN3_30B_SERVER_URL=http://192.168.91.253:8003/v1/
-QWEN3_30B_MODEL_ID=qwen3-30b
-QWEN3_30B_API_KEY=sk-123456
-
 
 [ai_review]
 # 调试模式配置
@@ -106,12 +100,6 @@ QWEN_LOCAL_1_5B_SERVER_URL=http://192.168.91.253:9002/v1
 QWEN_LOCAL_1_5B_MODEL_ID=Qwen3-8B
 QWEN_LOCAL_1_5B_API_KEY=dummy
 
-# 本地部署的Qwen3-Embedding-8B配置
-[lq_qwen3_8b_emd]
-LQ_EMBEDDING_SERVER_URL=http://192.168.91.253:9003/v1
-LQ_EMBEDDING_MODEL_ID=Qwen3-Embedding-8B
-LQ_EMBEDDING_API_KEY=dummy
-
 [lq_qwen3_4b]
 QWEN_LOCAL_1_5B_SERVER_URL=http://192.168.91.253:9001/v1
 QWEN_LOCAL_1_5B_MODEL_ID=Qwen3-4B
@@ -174,6 +162,11 @@ SHUTIAN_8B_SERVER_URL=http://183.220.37.46:25424/v1
 SHUTIAN_8B_MODEL_ID=/model/Qwen3-8B
 SHUTIAN_8B_API_KEY=sk_prod_SELVoIV1d3gku28koH_ONg8L_B2cQis__71f55615
 
+# Qwen3.6-27B 模型(端口25424)
+SHUTIAN_27B_SERVER_URL=http://183.220.37.46:25424/v1
+SHUTIAN_27B_MODEL_ID=/model/Qwen3.6-27B
+SHUTIAN_27B_API_KEY=sk_prod_SELVoIV1d3gku28koH_ONg8L_B2cQis__71f55615
+
 # Qwen3.5-35B 模型(端口25427)
 SHUTIAN_35B_SERVER_URL=http://183.220.37.46:25427/v1
 SHUTIAN_35B_MODEL_ID=/model/Qwen3.5-35B
@@ -194,7 +187,6 @@ SHUTIAN_RERANK_API_KEY=sk_prod_SELVoIV1d3gku28koH_ONg8L_B2cQis__71f55615
 MILVUS_HOST=192.168.92.96
 MILVUS_PORT=30129
 MILVUS_DB=lq_db
-MILVUS_COLLECTION=first_bfp_collection_test
 MILVUS_USER=
 MILVUS_PASSWORD=
 
@@ -204,6 +196,12 @@ MILVUS_PASSWORD=
 DENSE_WEIGHT=0.3
 SPARSE_WEIGHT=0.7
 
+[rag_collections]
+# RAG 检索链路使用的 Milvus 集合名
+ENTITY_COLLECTION=first_bfp_collection_entity
+BFP_COLLECTION=rag_children_hybrid
+CHILDREN_COLLECTIONION=rag_parent_hybrid
+
 
 # ============================================================
 # DashScope Qwen3.5 系列模型配置

+ 38 - 2
config/model_setting.yaml

@@ -28,9 +28,9 @@ available_models:
   - shutian_qwen3_5_122b   # 蜀天Qwen3.5-122B
   - shutian_qwen3_8b       # 蜀天Qwen3-8B
   - shutian_qwen3_5_35b    # 蜀天Qwen3.5-35B
+  - shutian_qwen3_6_27b    # 蜀天Qwen3.6-27B
 
   # Embedding 模型
-  - lq_qwen3_8b_emd        # 本地Qwen3-Embedding-8B
   - siliconflow_embed      # 硅基流动Embedding
   - shutian_qwen3_embed    # 蜀天Embedding
 
@@ -88,6 +88,18 @@ model_settings:
     enable_thinking: false
     description: "RAG答案生成,蜀天122B"
 
+  # 查询提取(从审查条文中提取查询关键词)
+  query_extract:
+    model: shutian_qwen3_5_35b
+    enable_thinking: false
+    description: "查询提取,从审查条文中提取实体和关键词,蜀天35B"
+
+  # 相关性判断(判断两个文本是否相关)
+  relevance_judge:
+    model: shutian_qwen3_5_122b
+    enable_thinking: false
+    description: "相关性判断,判断文本是否可作为审查引用依据,蜀天122B"
+
   # 敏感信息检查
   sensitive_check:
     model: shutian_qwen3_5_122b
@@ -118,6 +130,18 @@ model_settings:
     enable_thinking: false
     description: "规范性审查(引用匹配),蜀天122B"
 
+  # 非参数合规性检查(安全相关/强制性条文)
+  non_parameter_compliance_check:
+    model: shutian_qwen3_5_122b
+    enable_thinking: false
+    description: "非参数合规性检查,安全相关/强制性条文知识库,蜀天122B"
+
+  # 参数合规性检查(实体概念/工程术语)
+  parameter_compliance_check:
+    model: shutian_qwen3_5_122b
+    enable_thinking: false
+    description: "参数合规性检查,实体概念/工程术语知识库,蜀天122B"
+
   # 时效规范审查抽取(目录提取)
   directory_extraction:
     model: shutian_qwen3_5_35b
@@ -142,9 +166,21 @@ model_settings:
     enable_thinking: false
     description: "施工方案章节模板受限校订,蜀天122B"
 
+  # 施工方案大纲生成(SSE流式)
+  write_outline_generate:
+    model: shutian_qwen3_5_122b
+    enable_thinking: false
+    description: "施工方案大纲流式生成,蜀天122B"
+
+  # 施工方案内容补全生成(SSE流式)
+  write_content_generate:
+    model: shutian_qwen3_5_122b
+    enable_thinking: false
+    description: "施工方案内容补全流式生成,蜀天122B"
+
   # Embedding 模型(用于相似度计算)
   embedding:
-    model: lq_qwen3_8b_emd # 或 lq_qwen3_8b_emd 
+    model: shutian_qwen3_embed
     description: "文本Embedding向量生成(蜀天)"
 
 # 默认配置(当功能未指定时使用)

+ 2 - 1
config/模型调用指南.md

@@ -14,7 +14,8 @@ available_models:
   - qwen3_5_35b_a3b        # DashScope Qwen3.5-35B-A3B
   - shutian_qwen3_5_35b    # 蜀天Qwen3.5-35B
   - shutian_qwen3_5_122b   # 蜀天Qwen3.5-122B
-  - lq_qwen3_8b_emd        # 本地Embedding模型
+  - shutian_qwen3_6_27b    # 蜀天Qwen3.6-27B
+  - shutian_qwen3_embed    # 蜀天Embedding模型
 
 # 功能模块模型配置
 model_settings:

+ 2 - 1
data_pipeline/milvus_inbound_script/milvus入库脚本.py

@@ -110,7 +110,8 @@ def test_basic_functionality():
         print(f"\n测试 create_hybrid_collection 方法...")
         vectorstore = manager.create_hybrid_collection(
             collection_name=collection_name,
-            documents=all_documents  # ← 用目录里解析出的所有 documents
+            documents=all_documents,  # ← 用目录里解析出的所有 documents
+            drop_old=True
         )
         print("create_hybrid_collection 执行成功!")
         print(f"返回的 vectorstore 类型: {type(vectorstore)}")

+ 2 - 1
utils_test/Milvus_Test/milvus入库脚本.py

@@ -43,7 +43,8 @@ def test_basic_functionality():
         print(f"\n测试 create_hybrid_collection 方法...")
         vectorstore = manager.create_hybrid_collection(
             collection_name=collection_name,
-            documents=test_documents
+            documents=test_documents,
+            drop_old=True
         )
         print("create_hybrid_collection 执行成功!")
         print(f"返回的 vectorstore 类型: {type(vectorstore)}")

+ 105 - 0
utils_test/Milvus_Test/连通性测试.py

@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+"""
+简化调试 - 检查集合字段结构
+"""
+
+import sys
+import os
+
+
+print("调试 LangChain Milvus 集合字段结构")
+print("=" * 50)
+
+def debug_collection():
+    """调试集合结构"""
+    try:
+        from langchain_milvus import Milvus, BM25BuiltInFunction
+        from langchain_core.documents import Document
+        from pymilvus import Collection, utility
+        from foundation.ai.models.model_handler import model_handler
+
+        # 连接参数
+        connection_args = {
+            "uri": "http://192.168.92.61:19530",
+            "user": None,
+            "db_name": "lq_db"
+        }
+
+        collection_name = "debug_simple_fields"
+
+        # 获取嵌入模型
+        emdmodel = model_handler.get_embedding_model()
+
+        # 创建测试文档
+        test_docs = [
+            Document(page_content="测试文档内容", metadata={"category": "test"})
+        ]
+
+        print("1. 创建 LangChain Milvus 混合搜索集合...")
+        vectorstore = Milvus.from_documents(
+            documents=test_docs,
+            embedding=emdmodel,
+            builtin_function=BM25BuiltInFunction(),
+            vector_field=["dense", "sparse"],
+            connection_args=connection_args,
+            collection_name=collection_name,
+            consistency_level="Strong",
+            drop_old=True,
+        )
+
+        print("集合创建成功")
+
+        # 等待索引创建
+        import time
+        time.sleep(3)
+
+        print("\n2. 检查集合结构...")
+        from pymilvus import connections
+        connections.connect(uri="http://192.168.92.61:19530", db_name="lq_db")
+        if utility.has_collection(collection_name):
+            collection = Collection(collection_name)
+
+            # 获取集合信息
+            print(f"集合名称: {collection.name}")
+            print(f"集合数量: {collection.num_entities}")
+
+            # 获取字段信息
+            schema = collection.schema
+            print(f"\n字段结构:")
+            for field in schema.fields:
+                print(f"  - 字段名: {field.name}")
+                print(f"    类型: {field.dtype}")
+                print(f"    是否主键: {field.is_primary}")
+                if hasattr(field, 'dim'):
+                    print(f"    维度: {field.dim}")
+                if hasattr(field, 'max_length'):
+                    print(f"    最大长度: {field.max_length}")
+                print()
+
+            # 获取索引信息
+            print("索引信息:")
+            try:
+                indexes = collection.indexes
+                for index in indexes:
+                    print(f"  - 索引字段: {index.field_name}")
+                    print(f"    索引类型: {index.params.get('index_type', 'N/A')}")
+                    print(f"    索引参数: {index.params}")
+                    print()
+            except Exception as e:
+                print(f"获取索引失败: {e}")
+
+        # 清理
+        if utility.has_collection(collection_name):
+            utility.drop_collection(collection_name)
+            print(f"清理测试集合: {collection_name}")
+
+        return True
+
+    except Exception as e:
+        print(f"调试失败: {e}")
+        import traceback
+        traceback.print_exc()
+        return False
+
+if __name__ == "__main__":
+    debug_collection()