|
@@ -61,6 +61,10 @@ def chatbot(state: State):
|
|
return {"messages": [message]}
|
|
return {"messages": [message]}
|
|
|
|
|
|
def execute_agent_with_api(user_input: str):
|
|
def execute_agent_with_api(user_input: str):
|
|
|
|
+ # 生成唯一的线程ID
|
|
|
|
+ import uuid
|
|
|
|
+ thread_id = str(uuid.uuid4())
|
|
|
|
+ logger.info(f"开始执行提取,user_input={user_input}, thread_id={thread_id}")
|
|
global graph, llm_with_tools, prompt
|
|
global graph, llm_with_tools, prompt
|
|
|
|
|
|
# 替换prompt中的{input}占位符为用户输入
|
|
# 替换prompt中的{input}占位符为用户输入
|
|
@@ -96,10 +100,6 @@ def execute_agent_with_api(user_input: str):
|
|
logger.error(f"初始化Agent失败: {str(e)}")
|
|
logger.error(f"初始化Agent失败: {str(e)}")
|
|
return f"初始化Agent失败: {str(e)}"
|
|
return f"初始化Agent失败: {str(e)}"
|
|
|
|
|
|
- # 生成唯一的线程ID
|
|
|
|
- import uuid
|
|
|
|
- thread_id = str(uuid.uuid4())
|
|
|
|
-
|
|
|
|
# 执行Agent并收集结果
|
|
# 执行Agent并收集结果
|
|
results = []
|
|
results = []
|
|
config = {"configurable": {"thread_id": thread_id}}
|
|
config = {"configurable": {"thread_id": thread_id}}
|
|
@@ -113,7 +113,9 @@ def execute_agent_with_api(user_input: str):
|
|
results.append(message.content)
|
|
results.append(message.content)
|
|
|
|
|
|
# 返回结果
|
|
# 返回结果
|
|
- return "\n".join(results) if results else "Agent执行完成,但没有返回结果"
|
|
|
|
|
|
+ res="\n".join(results) if results else "Agent执行完成,但没有返回结果"
|
|
|
|
+ logger.info(f"Agent执行完成,返回结果: {res}, thread_id={thread_id}")
|
|
|
|
+ return res
|
|
except requests.exceptions.ConnectionError as e:
|
|
except requests.exceptions.ConnectionError as e:
|
|
return f"OpenAI API 连接错误: {str(e)}\n请检查网络连接或代理设置。"
|
|
return f"OpenAI API 连接错误: {str(e)}\n请检查网络连接或代理设置。"
|
|
except Exception as e:
|
|
except Exception as e:
|