refactor(memory): consolidate memory config extraction and remove unused validator
- Add workspace default LLM fallback for emotion model in extraction orchestrator - Consolidate memory config ID extraction logic into MemoryConfigService - Remove duplicate extraction methods from AppService (_extract_memory_config_id_from_agent, _extract_memory_config_id_from_workflow) - Remove unused validate_embedding_model function from validators - Simplify AppService by delegating memory config extraction to MemoryConfigService - Update validator exports to remove validate_embedding_model - Improve code maintainability by centralizing memory configuration logic
This commit is contained in:
@@ -120,7 +120,14 @@ class WorkspaceAppService:
|
||||
return None
|
||||
|
||||
def _get_memory_config(self, memory_content: str) -> Dict[str, Any]:
|
||||
"""Retrieve memory_config information based on memory_content"""
|
||||
"""Retrieve memory_config information based on memory_content
|
||||
|
||||
Args:
|
||||
memory_content: Memory config ID string
|
||||
|
||||
Returns:
|
||||
Dict containing memory config info including workspace_id for model fallback
|
||||
"""
|
||||
try:
|
||||
memory_content = resolve_config_id(memory_content, self.db)
|
||||
memory_config_result = MemoryConfigRepository.query_reflection_config_by_id(self.db, (memory_content))
|
||||
@@ -128,6 +135,7 @@ class WorkspaceAppService:
|
||||
if memory_config_result:
|
||||
return {
|
||||
"config_id": memory_content,
|
||||
"workspace_id": memory_config_result.workspace_id,
|
||||
"enable_self_reflexion": memory_config_result.enable_self_reflexion,
|
||||
"iteration_period": memory_config_result.iteration_period,
|
||||
"reflexion_range": memory_config_result.reflexion_range,
|
||||
@@ -359,7 +367,17 @@ class MemoryReflectionService:
|
||||
}
|
||||
|
||||
def _create_reflection_config_from_data(self, config_data: Dict[str, Any]) -> ReflectionConfig:
|
||||
"""Create reflective configuration objects from configuration data"""
|
||||
"""Create reflective configuration objects from configuration data
|
||||
|
||||
If reflection_model_id is not set, falls back to workspace default LLM.
|
||||
|
||||
Args:
|
||||
config_data: Dict containing reflection config including workspace_id
|
||||
|
||||
Returns:
|
||||
ReflectionConfig object with model_id resolved
|
||||
"""
|
||||
from app.repositories.workspace_repository import get_workspace_models_configs
|
||||
|
||||
reflexion_range_value = config_data.get("reflexion_range")
|
||||
if reflexion_range_value is None or reflexion_range_value == "":
|
||||
@@ -392,6 +410,17 @@ class MemoryReflectionService:
|
||||
if reflection_model_id:
|
||||
reflection_model_id = str(reflection_model_id)
|
||||
|
||||
# 如果 reflection_model_id 为空,回退到工作空间默认 LLM
|
||||
if not reflection_model_id:
|
||||
workspace_id = config_data.get("workspace_id")
|
||||
if workspace_id:
|
||||
workspace_models = get_workspace_models_configs(self.db, workspace_id)
|
||||
if workspace_models and workspace_models.get("llm"):
|
||||
reflection_model_id = workspace_models["llm"]
|
||||
api_logger.info(
|
||||
f"reflection_model_id 为空,使用工作空间默认 LLM: {reflection_model_id}"
|
||||
)
|
||||
|
||||
return ReflectionConfig(
|
||||
enabled=config_data.get("enable_self_reflexion", False),
|
||||
iteration_period=str(iteration_period), # ReflectionConfig期望字符串
|
||||
|
||||
Reference in New Issue
Block a user