feat: 优化LLM节点配置获取逻辑
- 更新工作流引擎以支持从节点定义和默认配置中获取模型ID - 增强错误提示信息,提供更详细的配置指导 - 改进对节点参数的处理,确保兼容性和稳定性
This commit is contained in:
parent
02ae5908b9
commit
77c5c57203
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue