Skip to main content

Amadeus工具包 (Amadeus Toolkit)

本笔记本将指导您如何将LangChain连接到Amadeus旅行信息API (This notebook walks you through connecting LangChain to the Amadeus travel information API)

要使用此工具包,您需要设置您在Amadeus for developers getting started overview中解释的凭据。一旦您收到了AMADEUS_CLIENT_ID和AMADEUS_CLIENT_SECRET,您可以在下面的环境变量中输入它们。

pip install --upgrade amadeus > /dev/null

分配环境变量 (Assign Environmental Variables)

工具包将读取AMADEUS_CLIENT_ID和AMADEUS_CLIENT_SECRET环境变量以对用户进行身份验证,因此您需要在此处设置它们。您还需要设置您的OPENAI_API_KEY以便稍后使用代理。

# 在这里设置环境变量
import os

os.environ["AMADEUS_CLIENT_ID"] = "CLIENT_ID"
os.environ["AMADEUS_CLIENT_SECRET"] = "CLIENT_SECRET"
os.environ["OPENAI_API_KEY"] = "API_KEY"

创建Amadeus工具包并获取工具 (Create the Amadeus Toolkit and Get Tools)

首先,您需要创建工具包,以便稍后可以访问其工具。

from langchain.agents.agent_toolkits.amadeus.toolkit import AmadeusToolkit

toolkit = AmadeusToolkit()
tools = toolkit.get_tools()

在代理中使用Amadeus工具包 (Use Amadeus Toolkit within an Agent)

from langchain import OpenAI
from langchain.agents import initialize_agent, AgentType
llm = OpenAI(temperature=0)
agent = initialize_agent(
tools=tools,
llm=llm,
verbose=False,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
)
agent.run("What is the name of the airport in Cali, Colombia?")
    'The closest airport to Cali, Colombia is Alfonso Bonilla Aragón International Airport (CLO).'
agent.run(
"What is the departure time of the cheapest flight on August 23, 2023 leaving Dallas, Texas before noon to Lincoln, Nebraska?"
)
    'The cheapest flight on August 23, 2023 leaving Dallas, Texas before noon to Lincoln, Nebraska has a departure time of 16:42 and a total price of 276.08 EURO.'
agent.run(
"At what time does earliest flight on August 23, 2023 leaving Dallas, Texas to Lincoln, Nebraska land in Nebraska?"
)
    'The earliest flight on August 23, 2023 leaving Dallas, Texas to Lincoln, Nebraska lands in Lincoln, Nebraska at 16:07.'
agent.run(
"What is the full travel time for the cheapest flight between Portland, Oregon to Dallas, TX on October 3, 2023?"
)
    'The cheapest flight between Portland, Oregon to Dallas, TX on October 3, 2023 is a Spirit Airlines flight with a total price of 84.02 EURO and a total travel time of 8 hours and 43 minutes.'
agent.run(
"Please draft a concise email from Santiago to Paul, Santiago's travel agent, asking him to book the earliest flight from DFW to DCA on Aug 28, 2023. Include all flight details in the email."
)
    'Dear Paul,\n\nI am writing to request that you book the earliest flight from DFW to DCA on Aug 28, 2023. The flight details are as follows:\n\nFlight 1: DFW to ATL, departing at 7:15 AM, arriving at 10:25 AM, flight number 983, carrier Delta Air Lines\nFlight 2: ATL to DCA, departing at 12:15 PM, arriving at 2:02 PM, flight number 759, carrier Delta Air Lines\n\nThank you for your help.\n\nSincerely,\nSantiago'