
    Ng                         d dl Z d dlmZ d dlmZmZmZ d dlmZ d dl	m
Z
mZ d dlmZ  e j        e          Z G d de
          Z G d	 d
e          ZdS )    N)datetime)DictOptionalType)CallbackManagerForToolRun)	BaseModelField)AmadeusBaseToolc                       e Zd ZU dZ ed          Zeed<    ed          Zeed<    ed          Z	eed<    ed	          Z
eed
<    edd          Zeed<   dS )FlightSearchSchemaz(Schema for the AmadeusFlightSearch tool.zx The three letter International Air Transport  Association (IATA) Location Identifier for the  search's origin airport. )descriptionoriginLocationCodez} The three letter International Air Transport  Association (IATA) Location Identifier for the  search's destination airport. destinationLocationCodea    The earliest departure datetime from the origin airport  for the flight search in the following format:  "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. departureDateTimeEarliestz The latest departure datetime from the origin airport  for the flight search in the following format:  "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. departureDateTimeLatest   z6The specific page number of flight results to retrieve)defaultr   page_numberN)__name__
__module____qualname____doc__r	   r   str__annotations__r   r   r   r   int     k/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/amadeus/flight_search.pyr   r      s        22#e)      $)5.$ $ $S    &+U-& & &s    $)5-$ $ $S    uL  K     r   r   c                       e Zd ZU dZdZeed<   dZeed<   eZ	e
e         ed<   	 	 dd	ed
ededededee         defdZdS )AmadeusFlightSearchz<Tool for searching for a single flight between two airports.single_flight_searchnamez Use this tool to search for a single flight between the origin and  destination airports at a departure between an earliest and  latest datetime. r   args_schemar   Nr   r   r   r   r   run_managerreturnc                    	 ddl m} n"# t          $ r}t          d          |d }~ww xY wd}	| j        }
t	          j        |d          }t	          j        |d          }|                                |                                k    rt                              d           d gS d }	 |
j	        j
                            |||                    d          d	          }n!# |$ r}t          |           Y d }~nd }~ww xY wg }||j        D ]}i }i |d
<   |d
         d         |d
         d<   |d
         d         }|j        d         d         |         }i |d
         d<   ||d
         d<   g }|d         d         d         D ]`}i }|d         |d<   |d         |d<   |d         |d<   |d         }|j        d         d         |         }||d<   |                    |           ag |d<   ||d<   |                    |           t#          |          D ]M\  }}t	          j        |d         d         d         d         d          }||k    r|                    |           N|dz
  |	z  }||	z   }|||         S )Nr   )ResponseErrorzDUnable to import amadeus, please install with `pip install amadeus`.
   z%Y-%m-%dT%H:%M:%Sz Error: Earliest and latest departure dates need to be the  same date. If you're trying to search for round-trip  flights, call this function for the outbound flight first,  and then call again for the return flight. z%Y-%m-%dr   )r   r   departureDateadultspricetotalcurrencydictionaries
currenciesitinerariessegments	departurearrivalnumberflightNumbercarrierCodecarrierscarrierat)amadeusr'   ImportErrorclientdtstrptimedateloggererrorshoppingflight_offers_searchgetstrftimeprintdataresultappend	enumeratepop)selfr   r   r   r   r   r$   r'   eRESULTS_PER_PAGEr<   earliestDeparturelatestDepartureresponserA   outputoffer	itineraryr-   r1   segmentflightr8   indexofferDeparture
startIndexendIndexs                              r   _runzAmadeusFlightSearch._runA   s*   	------- 	 	 	V 	
   K(ACVWW+&=?RSS!!##';';'='===LL?   6M 	;??#5(?-66zBB	 @  HH  	 	 	%LLLLLLLL	 ! ) )"$	%'	'".3GnW.E	'"7+ >*5#?>:<HR13	'":.19	'":.$]3A6zB 	, 	,GF*1+*>F;'(/	(:F9%-4X->F>*%m4G&on=jI'RG(/F9%OOF++++(*	*%(0	*%i(((( &f-- 	" 	"LE5[j!!$[1$79L N //

5!!! "Ao)99
 00j)**s(   	 
(#((6C C=$C88C=)r   N)r   r   r   r   r"   r   r   r   r   r#   r   r   r   r   listr[   r   r   r   r    r    6   s         FF&D#&&&	    
 -?K()>>> ;?X+ X+X+ "%X+ $'	X+
 "%X+ X+ 78X+ 
X+ X+ X+ X+ X+ X+r   r    )loggingr   r=   typingr   r   r   langchain_core.callbacksr   pydanticr   r	   &langchain_community.tools.amadeus.baser
   	getLoggerr   r@   r   r    r   r   r   <module>rc      s     # # # # # # ' ' ' ' ' ' ' ' ' ' > > > > > > % % % % % % % % B B B B B B		8	$	$& & & & & & & &Rc+ c+ c+ c+ c+/ c+ c+ c+ c+ c+r   