Переглянути джерело

refactor(model): 重构模型配置管理,统一移动到 foundation.ai.models

- 将 model_config_loader.py 从 config/ 移动到 foundation/ai/models/
- 更新所有相关导入路径:
  - model_handler.py
  - model_generate.py
  - bootstrap.py
  - llm_client.py
  - chunk_classifier.py
  - 模型调用指南.md
- 优化配置文件路径计算逻辑(支持新位置)

BREAKING CHANGE: 导入路径变更
  旧: from config.model_config_loader import ...
  新: from foundation.ai.models.model_config_loader import ...
WangXuMing 1 тиждень тому
батько
коміт
4a85c403c5

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

@@ -130,7 +130,7 @@ for chunk in generate_model_client.get_model_generate_stream(
 ### 获取模型配置
 
 ```python
-from config.model_config_loader import (
+from foundation.ai.models.model_config_loader import (
     get_model_for_function,
     get_thinking_mode_for_function,
     get_full_config_for_function
@@ -152,7 +152,7 @@ config = get_full_config_for_function("doc_classification_tertiary")
 ### 获取默认配置
 
 ```python
-from config.model_config_loader import get_model_for_function
+from foundation.ai.models.model_config_loader import get_model_for_function
 
 # 获取默认模型(当功能未指定时使用)
 default_model = get_model_for_function("default")

+ 2 - 2
core/construction_review/component/doc_worker/classification/chunk_classifier.py

@@ -283,7 +283,7 @@ class ChunkClassifier:
     def SECONDARY_MODEL(self) -> str:
         """二级分类模型,从 model_setting.yaml 读取配置"""
         try:
-            from config.model_config_loader import get_model_for_function
+            from foundation.ai.models.model_config_loader import get_model_for_function
             model = get_model_for_function("doc_classification_secondary")
             if model:
                 return model
@@ -522,7 +522,7 @@ class ChunkClassifier:
 
             # 从全局配置加载模型和thinking模式
             try:
-                from config.model_config_loader import get_model_for_function, get_thinking_mode_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function, get_thinking_mode_for_function
                 config.model = get_model_for_function("doc_classification_tertiary")
                 config.enable_thinking = get_thinking_mode_for_function("doc_classification_tertiary") or False
                 logger.info(f"三级分类配置 - 并发度: {config.max_concurrent_requests}, 模型: {config.model}, thinking: {config.enable_thinking}")

+ 1 - 1
core/construction_review/component/doc_worker/utils/llm_client.py

@@ -43,7 +43,7 @@ class LLMClient:
         """加载LLM API配置(优先从 model_setting.yaml,回退到 config.ini)"""
         # 获取模型类型(优先从 model_setting.yaml 读取默认配置)
         try:
-            from config.model_config_loader import get_model_for_function
+            from foundation.ai.models.model_config_loader import get_model_for_function
             model_type = get_model_for_function("default")
             if model_type:
                 self.model_type = model_type.lower()

+ 2 - 2
core/construction_review/component/reviewers/utils/llm_chain_client/bootstrap.py

@@ -42,7 +42,7 @@ class Bootstrap:
         # 获取模型类型(优先从 model_setting.yaml 读取默认配置)
         if model_type is None:
             try:
-                from config.model_config_loader import get_model_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function
                 model_type = get_model_for_function("default")
                 if model_type:
                     logger.debug(f"LLMChainClient 从 model_setting.yaml 读取默认模型: {model_type}")
@@ -218,7 +218,7 @@ class Bootstrap:
         # 确定模型类型(优先从 model_setting.yaml 读取默认配置)
         if model_type is None:
             try:
-                from config.model_config_loader import get_model_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function
                 model_type = get_model_for_function("default")
                 if model_type:
                     logger.debug(f"PromptChainProcessor 从 model_setting.yaml 读取默认模型: {model_type}")

+ 4 - 4
foundation/ai/agent/generate/model_generate.py

@@ -151,7 +151,7 @@ class GenerateModelClient:
         # 如果提供了功能名称,从配置加载模型和 thinking 模式
         if function_name:
             try:
-                from config.model_config_loader import get_model_for_function, get_thinking_mode_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function, get_thinking_mode_for_function
                 config_model = get_model_for_function(function_name)
                 config_thinking = get_thinking_mode_for_function(function_name)
                 if config_model:
@@ -167,7 +167,7 @@ class GenerateModelClient:
         # 如果没有指定模型名称,从 model_setting.yaml 读取默认配置
         if not model_name:
             try:
-                from config.model_config_loader import get_model_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function
                 model_name = get_model_for_function("default")
                 logger.info(f"[模型调用] 从 model_setting.yaml 读取默认模型: {model_name}, trace_id: {trace_id}")
             except Exception as e:
@@ -328,7 +328,7 @@ class GenerateModelClient:
         # 如果提供了功能名称,从配置加载模型
         if function_name:
             try:
-                from config.model_config_loader import get_model_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function
                 config_model = get_model_for_function(function_name)
                 if config_model:
                     model_name = config_model
@@ -339,7 +339,7 @@ class GenerateModelClient:
         # 如果没有指定模型名称,从 model_setting.yaml 读取默认配置
         if not model_name:
             try:
-                from config.model_config_loader import get_model_for_function
+                from foundation.ai.models.model_config_loader import get_model_for_function
                 model_name = get_model_for_function("default")
                 logger.info(f"[模型流式调用] 从 model_setting.yaml 读取默认模型: {model_name}, trace_id: {trace_id}")
             except Exception as e:

+ 3 - 2
config/model_config_loader.py → foundation/ai/models/model_config_loader.py

@@ -7,7 +7,7 @@
 提供按功能获取模型配置的接口
 
 使用方式:
-    from config.model_config_loader import get_model_for_function, get_thinking_mode_for_function
+    from foundation.ai.models.model_config_loader import get_model_for_function, get_thinking_mode_for_function
 
     model = get_model_for_function("doc_classification_secondary")
     thinking = get_thinking_mode_for_function("doc_classification_secondary")
@@ -62,7 +62,8 @@ class ModelConfigLoader:
     def _get_config_path(self) -> Path:
         """获取配置文件路径"""
         # 配置文件位于项目根目录 config/ 下
-        return Path(__file__).parent / "model_setting.yaml"
+        # 本文件位于 foundation/ai/models/,需要向上3层到项目根目录
+        return Path(__file__).parent.parent.parent.parent / "config" / "model_setting.yaml"
 
     def _load_config(self):
         """加载 YAML 配置文件"""

+ 2 - 2
foundation/ai/models/model_handler.py

@@ -174,7 +174,7 @@ class ModelHandler:
         """
         # 优先从 model_setting.yaml 读取默认模型配置
         try:
-            from config.model_config_loader import get_model_for_function
+            from foundation.ai.models.model_config_loader import get_model_for_function
             model_type = get_model_for_function("default")
             if model_type:
                 logger.debug(f"从 model_setting.yaml 读取默认模型: {model_type}")
@@ -367,7 +367,7 @@ class ModelHandler:
             model = model_handler.get_model_by_function("doc_classification_tertiary")
         """
         try:
-            from config.model_config_loader import get_model_for_function
+            from foundation.ai.models.model_config_loader import get_model_for_function
             model_type = get_model_for_function(function_name)
             logger.info(f"根据功能 '{function_name}' 获取模型: {model_type}")
             return self.get_model_by_name(model_type)