from langchain_classic import hubfrom langchain.tools import toolprompt = hub.pull("hwchase17/openai-tools-agent")@tooldef multiply(first_int: int, second_int: int) -> int: """Multiply two integers together.""" return first_int * second_int@tooldef exponentiate(base: int, exponent: int) -> int: "Exponentiate the base to the exponent power." return base**exponenttools = [multiply, exponentiate]
常规运行您的智能体。唯一的修改是现在我们将包含上述请求头在请求中。
model = ChatOpenAI( base_url=PORTKEY_GATEWAY_URL, default_headers=portkey_headers, temperature=0)# Construct the OpenAI Tools agentagent = create_openai_tools_agent(model, tools, prompt)# Create an agent executor by passing in the agent and toolsagent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke( { "input": "Take 3 to the fifth power and multiply that by thirty six, then square the result" })
> Entering new AgentExecutor chain...Invoking: `exponentiate` with `{'base': 3, 'exponent': 5}`243Invoking: `multiply` with `{'first_int': 243, 'second_int': 36}`8748Invoking: `exponentiate` with `{'base': 8748, 'exponent': 2}`76527504The result of taking 3 to the fifth power, multiplying it by 36, and then squaring the result is 76,527,504.> Finished chain.
{'input': 'Take 3 to the fifth power and multiply that by thirty six, then square the result', 'output': 'The result of taking 3 to the fifth power, multiplying it by 36, and then squaring the result is 76,527,504.'}