|
|
|
|
|
def agent_executor(): |
|
|
|
from dotenv import load_dotenv |
|
load_dotenv(); |
|
|
|
|
|
from agent.toolset import tools |
|
from agent.prompt import prompt |
|
|
|
|
|
from langchain_openai import ChatOpenAI |
|
llm = ChatOpenAI(model="gpt-4", temperature=0) |
|
|
|
from langchain_community.tools.convert_to_openai import format_tool_to_openai_function |
|
|
|
llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools]) |
|
|
|
from langchain.agents.format_scratchpad import format_to_openai_function_messages |
|
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser |
|
|
|
agent = ( |
|
{ |
|
"input": lambda x: x["input"], |
|
"agent_scratchpad": lambda x: format_to_openai_function_messages( |
|
x["intermediate_steps"] |
|
), |
|
} |
|
| prompt |
|
| llm_with_tools |
|
| OpenAIFunctionsAgentOutputParser() |
|
) |
|
|
|
|
|
|
|
from langchain.agents import AgentExecutor |
|
|
|
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) |
|
|
|
return agent_executor.invoke({"input": "What is Rise?"})['output'] |