From 77c5c57203f4e1b5936fbbd687ce2f597412e773 Mon Sep 17 00:00:00 2001 From: eason Date: Fri, 23 Jan 2026 14:02:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96LLM=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新工作流引擎以支持从节点定义和默认配置中获取模型ID - 增强错误提示信息,提供更详细的配置指导 - 改进对节点参数的处理,确保兼容性和稳定性 --- th_agenter/services/workflow_engine.py | 41 +++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/th_agenter/services/workflow_engine.py b/th_agenter/services/workflow_engine.py index ee12812..5ad3b66 100644 --- a/th_agenter/services/workflow_engine.py +++ b/th_agenter/services/workflow_engine.py @@ -582,8 +582,8 @@ class WorkflowEngine: previous_outputs = input_data.get('previous_outputs', {}) # 处理结束节点的输出参数配置 - node_parameters = node.get('parameters', {}) - output_params = node_parameters.get('outputs', []) + node_parameters = node.get('parameters') or {} + output_params = node_parameters.get('outputs', []) if isinstance(node_parameters, dict) else [] result_data = {} @@ -652,7 +652,7 @@ class WorkflowEngine: async def _execute_llm_node(self, node: Dict[str, Any], input_data: Dict[str, Any]) -> Dict[str, Any]: """执行LLM节点""" - config = input_data['node_config'] + config = input_data.get('node_config', {}) # 获取LLM配置 model_id = config.get('model_id') @@ -673,8 +673,41 @@ class WorkflowEngine: if llm_config: model_id = llm_config.id + # 如果还是没有,尝试从节点定义本身获取 if not model_id: - raise ValueError("未指定有效的大模型配置") + node_config = node.get('config', {}) + model_id = node_config.get('model_id') + if not model_id: + model_value = node_config.get('model_name', node_config.get('model')) + if model_value: + if isinstance(model_value, int): + model_id = model_value + else: + from sqlalchemy import select + result = await self.session.execute( + select(LLMConfig).where(LLMConfig.model_name == model_value) + ) + llm_config = result.scalar_one_or_none() + if llm_config: + model_id = llm_config.id + + # 如果还是没有,尝试使用默认的LLM配置 + if not model_id: + from ..services.llm_config_service import LLMConfigService + llm_config_service = LLMConfigService() + default_config = await llm_config_service.get_default_chat_config(self.session) + if default_config: + model_id = default_config.id + logger.info(f"LLM节点未指定模型配置,使用默认模型: {default_config.model_name} (ID: {model_id})") + else: + raise ValueError( + "未指定有效的大模型配置,且未找到默认配置。\n" + "请在节点配置中添加模型ID或模型名称,例如:\n" + " - config.model_id: 1\n" + " - config.model_name: 'gpt-4'\n" + " - config.model: 'gpt-4'\n" + "或者设置一个默认的LLM配置。" + ) from sqlalchemy import select result = await self.session.execute(