-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMyAmadeusFlightSearchTool.py
More file actions
45 lines (37 loc) · 1.82 KB
/
MyAmadeusFlightSearchTool.py
File metadata and controls
45 lines (37 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from langchain_community.tools.amadeus.base import AmadeusBaseTool
from pydantic import BaseModel, Field
from typing import Type
from amadeus import Client
class MyAmadeusFlightSearchTool(AmadeusBaseTool):
class FlightSearchSchema(BaseModel):
# explanation of the flight information
origin: str = Field(description="IATA code of the origin airport (e.g., CTA for Catania).")
destination: str = Field(description="IATA code of the destination airport (e.g., FCO for Rome).")
departure_date: str = Field(description="Date of departure in YYYY-MM-DD format.")
name: str = "flight_search"
description: str = "Search for flights between two airports."
args_schema: Type[BaseModel] = FlightSearchSchema
def _run(self, origin: str, destination: str, departure_date: str, max_flights: int = 2):
# Use the Amadeus client to search for flights
client = self.client # Automatically set up by AmadeusBaseTool
try:
# client.shopping.flight_dates.get() Ricerca chepest
response = client.shopping.flight_offers_search.get(
originLocationCode=origin,
destinationLocationCode=destination,
departureDate=departure_date,
adults=1
)
flights = response.data[:max_flights] # only 2 flights
return flights
except Exception as e:
return {"error": str(e)}
def _arun(self, *args, **kwargs):
raise NotImplementedError("Async not supported yet.")
def getClient():
# Create the Amadeus client with your credentials
amadeus_client = Client(
client_id="GPBeOGYq15rpYAKlJi8nG0e4DLUcvMrk",
client_secret="3ETaMtYhnfczzUcW"
)
return amadeus_client