|
@@ -4,7 +4,8 @@ from langgraph.graph import StateGraph, START, END
|
|
from langgraph.graph.message import add_messages
|
|
from langgraph.graph.message import add_messages
|
|
import os
|
|
import os
|
|
from langchain_openai import ChatOpenAI
|
|
from langchain_openai import ChatOpenAI
|
|
-from .tools import evaluation_extraction_tool
|
|
|
|
|
|
+from .tools import evaluation_extraction_tool, evaluation_extraction
|
|
|
|
+import uuid
|
|
|
|
|
|
from langgraph.prebuilt import ToolNode, tools_condition
|
|
from langgraph.prebuilt import ToolNode, tools_condition
|
|
from langgraph.checkpoint.memory import InMemorySaver
|
|
from langgraph.checkpoint.memory import InMemorySaver
|
|
@@ -61,6 +62,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 +101,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,12 +114,19 @@ 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:
|
|
return f"执行Agent时出错: {str(e)}"
|
|
return f"执行Agent时出错: {str(e)}"
|
|
|
|
|
|
|
|
+def execute(query_word: str, request_id: str):
|
|
|
|
+ logger.info(f"开始处理,request_id: {request_id}, query_word: {query_word}")
|
|
|
|
+ result = evaluation_extraction(request_id, query_word)
|
|
|
|
+ return result
|
|
|
|
+
|
|
def main():
|
|
def main():
|
|
print(f"开始执行Agent")
|
|
print(f"开始执行Agent")
|
|
# 设置代理
|
|
# 设置代理
|
|
@@ -128,7 +136,8 @@ def main():
|
|
os.environ["HTTPS_PROXY"] = proxy_url
|
|
os.environ["HTTPS_PROXY"] = proxy_url
|
|
os.environ["HTTP_PROXY"] = proxy_url
|
|
os.environ["HTTP_PROXY"] = proxy_url
|
|
# 执行Agent
|
|
# 执行Agent
|
|
- result = execute_agent_with_api('{"query_word":"图文策划方法","request_id":"REQUEST_001"}')
|
|
|
|
|
|
+ # result = execute_agent_with_api('{"query_word":"图文策划方法","request_id":"REQUEST_001"}')
|
|
|
|
+ result = execute("图文策划方法", "REQUEST_001")
|
|
print(result)
|
|
print(result)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|