
    i                        d dl Z d dlZd dlmZmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ  e	            Z ej        e          Ze                    ddd          defd            ZdS )    N)date	timedelta)AnyAsyncIterable)	APIRouterHTTPException)EventSourceResponse)
HotelAgent)tool_map)ChatRequest)settings)create_conversationsave_conversation)get_available_datesz/streamzstream chat   )summarystatus_codeargsc                 f    K   dt           t                   f fd}t           |                      S )Nreturnc            	       K   	 j         st          j                   d {V _         t          j                                        d          } t          j                    t          d          z   }t                       d {V \  }}t          dt          j
        j                   }|                    j        | ||t          j        j                  |dj                  2 3 d {V }|dk    rd	}|W V  6 t!          |j        ||          2 3 d {V }|W V  6 j         r@d
j         z   W V  t%          j         j        |j        j        j                   d {V  d S d S # t*          $ rP}t,                              dt1          |                      t3          ddt1          |                     d }~ww xY w)Nz	%d %B, %Yim  )dayszgpt-5.1)modelapi_keyconversation_id)questionr   checkincheckoutcontextmax_future_booking_allowed)inputhistory
z<br>z	#conv_id:zError: i  )r   detail)r   r   r   r   todaystrftimer   r   r
   r   OPENAI_API_KEYstreamjsondumpsroomListr"   r   resultr   answercustomer_id	Exceptionloggererrorstrr   )r%   r    r   r   agenttokener   s          5/var/www/html/ls-ibe-bot-apis/app/controllers/chat.pysend_messagezchat.<locals>.send_message   s]     !	L' P-@-O-O'O'O'O'O'O'O$JLL))+66E)-	s8K8K8K)K&&9&;&; ; ; ; ; ; ;GXY8OaeauvvvE$|| M"$:dm44.H3 3 |  ,  %  % 
 
 
 
 
 
 
e D=="E %  (dGXNN       e  O # t!D$888888'(<dmU\M`bfbrssssssssssst t  	L 	L 	LLL+3q66++,,,C8J#a&&8J8JKKKK	Ls2   C'E0 ,D2'E0 D&AE0 0
G
:AGG
)r   r   r	   )r   r7   s   ` r6   chatr8      sO      "Lc 2 "L "L "L "L "L "LF ||~~...    ) r)   loggingdatetimer   r   typingr   r   fastapir   r   sse_starlette.sser	   
app.agentsr
   app.agents.tool_mapr   app.schemas.chatr   app.configs.settingsr   app.utils.store_conversationr   r   !app.agents.tools.search_room_toolr   router	getLogger__name__r0   postr8    r9   r6   <module>rJ      sP     $ $ $ $ $ $ $ $ % % % % % % % % , , , , , , , , 1 1 1 1 1 1 ! ! ! ! ! ! ( ( ( ( ( ( ( ( ( ( ( ( ) ) ) ) ) ) O O O O O O O O A A A A A A 
		8	$	$   
%/K %/ %/ %/ 
%/ %/ %/r9   