工具
This commit is contained in:
@@ -725,19 +725,44 @@ class WorkflowEngine:
|
||||
# 记录实际发送给LLM的prompt
|
||||
logger.info(f"[rjb] 准备调用LLM: node_id={node_id}, provider={provider}, model={model}, prompt前200字符='{prompt[:200] if len(prompt) > 200 else prompt}'")
|
||||
|
||||
# 检查是否启用工具调用
|
||||
enable_tools = node_data.get('enable_tools', False)
|
||||
tools_config = node_data.get('tools', []) # 工具名称列表
|
||||
|
||||
# 如果启用了工具,加载工具定义
|
||||
tools = []
|
||||
if enable_tools and tools_config:
|
||||
from app.services.tool_registry import tool_registry
|
||||
# 从注册表加载工具定义
|
||||
tools = tool_registry.get_tools_by_names(tools_config)
|
||||
logger.info(f"[rjb] LLM节点启用工具调用: {len(tools)} 个工具, 工具列表: {tools_config}")
|
||||
|
||||
# 调用LLM服务
|
||||
try:
|
||||
if self.logger:
|
||||
logger.debug(f"[rjb] LLM节点配置: provider={provider}, model={model}, 使用系统默认API Key配置")
|
||||
logger.debug(f"[rjb] LLM节点配置: provider={provider}, model={model}, 使用系统默认API Key配置, 工具调用: {'启用' if tools else '禁用'}")
|
||||
self.logger.info(f"调用LLM服务: {provider}/{model}", node_id=node_id, node_type=node_type)
|
||||
result = await llm_service.call_llm(
|
||||
prompt=prompt,
|
||||
provider=provider,
|
||||
model=model,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens
|
||||
# 不传递 api_key 和 base_url,使用系统默认配置
|
||||
)
|
||||
|
||||
# 根据是否启用工具选择不同的调用方式
|
||||
if tools:
|
||||
result = await llm_service.call_llm_with_tools(
|
||||
prompt=prompt,
|
||||
tools=tools,
|
||||
provider=provider,
|
||||
model=model,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens
|
||||
)
|
||||
else:
|
||||
result = await llm_service.call_llm(
|
||||
prompt=prompt,
|
||||
provider=provider,
|
||||
model=model,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens
|
||||
# 不传递 api_key 和 base_url,使用系统默认配置
|
||||
)
|
||||
|
||||
exec_result = {'output': result, 'status': 'success'}
|
||||
if self.logger:
|
||||
duration = int((time.time() - start_time) * 1000)
|
||||
@@ -748,6 +773,7 @@ class WorkflowEngine:
|
||||
if self.logger:
|
||||
duration = int((time.time() - start_time) * 1000)
|
||||
self.logger.log_node_error(node_id, node_type, e, duration)
|
||||
logger.error(f"[rjb] LLM节点执行失败: {str(e)}", exc_info=True)
|
||||
return {
|
||||
'output': None,
|
||||
'status': 'failed',
|
||||
@@ -2438,6 +2464,15 @@ class WorkflowEngine:
|
||||
logger.info(f"[rjb] user_input: {user_input[:50]}, output: {str(output)[:50]}, timestamp: {timestamp}")
|
||||
value = eval(value_str, {"__builtins__": {}}, safe_dict)
|
||||
logger.info(f"[rjb] Cache节点 {node_id} value模板执行成功,类型: {type(value)}")
|
||||
|
||||
# 确保conversation_history只保留最近的20条(性能优化)
|
||||
if isinstance(value, dict) and 'conversation_history' in value:
|
||||
if isinstance(value['conversation_history'], list):
|
||||
max_history_length = 20
|
||||
if len(value['conversation_history']) > max_history_length:
|
||||
value['conversation_history'] = value['conversation_history'][-max_history_length:]
|
||||
logger.info(f"[rjb] 对话历史已截断,保留最近 {max_history_length} 条")
|
||||
|
||||
if isinstance(value, dict):
|
||||
logger.info(f"[rjb] keys: {list(value.keys())}")
|
||||
if 'conversation_history' in value:
|
||||
|
||||
Reference in New Issue
Block a user