mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 22:29:51 +00:00
community[patch]: Improve amadeus tool and doc (#18509)
Description: This pull request addresses two key improvements to the langchain repository: **Fix for Crash in Flight Search Interface**: Previously, the code would crash when encountering a failure scenario in the flight ticket search interface. This PR resolves this issue by implementing a fix to handle such scenarios gracefully. Now, the code handles failures in the flight search interface without crashing, ensuring smoother operation. **Documentation Update for Amadeus Toolkit**: Prior to this update, examples provided in the documentation for the Amadeus Toolkit were unable to run correctly due to outdated information. This PR includes an update to the documentation, ensuring that all examples can now be executed successfully. With this update, users can effectively utilize the Amadeus Toolkit with accurate and functioning examples. These changes aim to enhance the reliability and usability of the langchain repository by addressing issues related to error handling and ensuring that documentation remains up-to-date and actionable. Issue: https://github.com/langchain-ai/langchain/issues/17375 Twitter Handle: SingletonYxx
This commit is contained in:
parent
f77f7dc3ec
commit
dc81dba6cf
File diff suppressed because one or more lines are too long
@ -31,7 +31,7 @@ class FlightSearchSchema(BaseModel):
|
||||
description=(
|
||||
" The earliest departure datetime from the origin airport "
|
||||
" for the flight search in the following format: "
|
||||
' "YYYY-MM-DDTHH:MM", where "T" separates the date and time '
|
||||
' "YYYY-MM-DDTHH:MM:SS", where "T" separates the date and time '
|
||||
' components. For example: "2023-06-09T10:30:00" represents '
|
||||
" June 9th, 2023, at 10:30 AM. "
|
||||
)
|
||||
@ -40,7 +40,7 @@ class FlightSearchSchema(BaseModel):
|
||||
description=(
|
||||
" The latest departure datetime from the origin airport "
|
||||
" for the flight search in the following format: "
|
||||
' "YYYY-MM-DDTHH:MM", where "T" separates the date and time '
|
||||
' "YYYY-MM-DDTHH:MM:SS", where "T" separates the date and time '
|
||||
' components. For example: "2023-06-09T10:30:00" represents '
|
||||
" June 9th, 2023, at 10:30 AM. "
|
||||
)
|
||||
@ -97,6 +97,7 @@ class AmadeusFlightSearch(AmadeusBaseTool):
|
||||
return [None]
|
||||
|
||||
# Collect all results from the Amadeus Flight Offers Search API
|
||||
response = None
|
||||
try:
|
||||
response = client.shopping.flight_offers_search.get(
|
||||
originLocationCode=originLocationCode,
|
||||
@ -109,32 +110,32 @@ class AmadeusFlightSearch(AmadeusBaseTool):
|
||||
|
||||
# Generate output dictionary
|
||||
output = []
|
||||
if response is not None:
|
||||
for offer in response.data:
|
||||
itinerary: Dict = {}
|
||||
itinerary["price"] = {}
|
||||
itinerary["price"]["total"] = offer["price"]["total"]
|
||||
currency = offer["price"]["currency"]
|
||||
currency = response.result["dictionaries"]["currencies"][currency]
|
||||
itinerary["price"]["currency"] = {}
|
||||
itinerary["price"]["currency"] = currency
|
||||
|
||||
for offer in response.data:
|
||||
itinerary: Dict = {}
|
||||
itinerary["price"] = {}
|
||||
itinerary["price"]["total"] = offer["price"]["total"]
|
||||
currency = offer["price"]["currency"]
|
||||
currency = response.result["dictionaries"]["currencies"][currency]
|
||||
itinerary["price"]["currency"] = {}
|
||||
itinerary["price"]["currency"] = currency
|
||||
segments = []
|
||||
for segment in offer["itineraries"][0]["segments"]:
|
||||
flight = {}
|
||||
flight["departure"] = segment["departure"]
|
||||
flight["arrival"] = segment["arrival"]
|
||||
flight["flightNumber"] = segment["number"]
|
||||
carrier = segment["carrierCode"]
|
||||
carrier = response.result["dictionaries"]["carriers"][carrier]
|
||||
flight["carrier"] = carrier
|
||||
|
||||
segments = []
|
||||
for segment in offer["itineraries"][0]["segments"]:
|
||||
flight = {}
|
||||
flight["departure"] = segment["departure"]
|
||||
flight["arrival"] = segment["arrival"]
|
||||
flight["flightNumber"] = segment["number"]
|
||||
carrier = segment["carrierCode"]
|
||||
carrier = response.result["dictionaries"]["carriers"][carrier]
|
||||
flight["carrier"] = carrier
|
||||
segments.append(flight)
|
||||
|
||||
segments.append(flight)
|
||||
itinerary["segments"] = []
|
||||
itinerary["segments"] = segments
|
||||
|
||||
itinerary["segments"] = []
|
||||
itinerary["segments"] = segments
|
||||
|
||||
output.append(itinerary)
|
||||
output.append(itinerary)
|
||||
|
||||
# Filter out flights after latest departure time
|
||||
for index, offer in enumerate(output):
|
||||
|
Loading…
Reference in New Issue
Block a user