
    |hQ                     &   d dl mZ d dlmZmZ d dlmZ d dlZd dlZ	d dlm
Z
 d dl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mZ d dlmZ  e e             Z e       Z G d de      Zd Z edededeeef   defd       Z!edededeeef   deeeef      fd       Z"edededeeef   deeeef      fd       Z#edededeeef   deeeef      fd       Z$edededeeef   deeeef      fd       Z%edededeeef   deeeef      fd       Z&edededeeef   deeeef      fd       Z'edededeeef   deeeef      fd       Z(edededeeef   deeeef      fd        Z)d!e*defd"Z+d# Z,y)$    )tool)ListDict)VectorStoreN)Error)	Annotated)ToolMessage	AIMessage)MessagesState)InjectedToolCallId)add_messages)	TypedDict)Command)datetime	timedeltatimezone)uuid4c                   6    e Zd ZU eeef   ed<   eed<   eed<   y)StatemessagesnameroomnoN)__name__
__module____qualname__r   listr   __annotations__str     ,/home/kushmeetdev/Regenta/Chatbot/mytools.pyr   r      s    l*++
ILr    r   c                  H    t        j                         j                  d      S )z5Return the current time in UTC as a formatted string.z%Y-%m-%d %H:%M:%S)r   utcnowstrftimer   r    r!   get_current_timer%      s    ??%%&9::r    	guestnameroom_notool_call_idreturnc                     t        d       t        d|  d|        | |t        d|      gd}t        d|d    d|d	           t        |
      S )z 
    Captures guests name and Room number

    Args:
        name (str): Guest Name
        roomno (str): Guest Room Number 
    z**Invoking TOOL GetGuestDetailsguestname:  ,room no: u0   Thank you for providing Your name and Room Nor(   )r   r   r   zGUESTNAME: r   r   update)printr	   r   )r&   r'   r(   state_updates       r!   get_GuestDetailsr2      so     
+-	K	{+gY
78  !SbnopsL 
KV,-[h9O8P
QR,''r    querystatec                 0   t        d       |j                  d      }|j                  d      }t        d| d|        |dk(  s(|dk(  s#|dk(  s|d	k(  s|d
k(  s|dk(  s|dk(  s
|dk(  s|dk(  rt        dt        d|      gi      S |dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt        dt        d|      gi      S t	        t                     }d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )a  
        Looks up information in a knowledge base to help with answering customer questions regarding ordering food and beverages. For example
        Can I order food to my room?
        Is the restaurant open now?

        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL FnBr   r   zGUESTNAMEFNB: r,    Guest Room NumberrequiredNone
guest_nameGuest	Your nameguest
Guest Namer       May I have your name please?🤗r-   r.   room_numberunknownnullRoom Number(   May I have your room number, please?🤗   3answer to queryNew1BUID	RequestIDToDept
FromRoomNoRequestDescpBotResponseStatusRequestCreatedAtLastUpdatedAt
AttendedBy	GuestNamer3   )
r0   getr   r	   r   r   r%   add_requestvector_store	query_fnbr3   r4   r(   r   r'   
request_idsample_dataresults           r!   tool_fnbr_   1   s    
!99VDii!G	N4&G9
56rzW 33tj7H4RX=\`dp\ptx  }D  uD  HL  P[  H[  _c  gn  _n  rv  zF  rF%GVbcd
  	 "}=0Gy4HGW]L]ahkxax%O^jkl
  	 UWJ (,.)+K %F	6N"""/ELr    c                 0   t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )al  
        Looks up information in a knowledge base to help with answering customer questions regarding the hotel and its Amenities Inquiries. For example: 
        where is the swimming pool located.
        What are the gym timings. Is there any train station nearby etcetera. 
        check out timings
        parking facilities. Can you arrange a taxi for me?
        Are there any good restaurants serving Arabian cuisine?
        Can you recommend restaurants near the hotel?
        Payment & Billing issue and other info enquires
        Can I split the bill between multiple payment methods
        I noticed a charge on my bill that I don't recognize. Can you help?

        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL Receptionr   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r7   r@   rA   rB   rC   rD   rE   2rG   rH   rI   rJ   rV   )
r0   rW   r   r   r   r	   r%   rX   rY   query_receptionr[   s           r!   tool_receptionrc   a   s   ( 
%'99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}$77']:RV]ajVjnuyn  DK  N[  D[%O^jkl
  	 (,.)+K %F	6N((u(5ELr    c                    t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       y)a^  
    Captures queries that the bot cannot confidently answer and logs them for reception follow-up.
    
    Args:
        query (str): The unresolved user query
        state (Dict): Current conversation state
        tool_call_id (str): Unique tool call identifier

    Returns:
        Command to update the state and log the unresolved query
    z-**Invoking TOOL Catchall for unresolved queryr   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r7   r@   rA   rB   rC   rD   rE   ra   z5Unable to resolve query - Requires human intervention
Unresolved0rJ   N)r0   rW   r   r   r   r	   r%   rX   r[   s           r!   tool_catchallrg      sh    
9;99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}$77']:RV]ajVjnuyn  DK  N[  D[%O^jkl
  	
 N,.)+K %F	&Mr    c                 0   t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )a.  
        Looks up information in a knowledge base to help with answering customer regarding hotel's room service. For example
        Can I have a towel please
        Can I have a toothbrush please
        Can I get my room cleaned. Please help to clean my room
        I need a baby crib or cot
        Can I switch to a room with a better view . Room Preferences
        What are the pool hours?.
        What are the fitness center hours?
        Do you have vegetarian or special dietary options?
        what are breakfast hour or timings
        Can I get a couple of water bottles sent to my room
        
        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL Room Servicer   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r7   r@   rA   rB   rC   rD   rE   rI   rG   rH   rJ   rV   )
r0   rW   r   r   r   r	   r%   rX   rY   query_roomservicer[   s           r!   tool_roomservicerj      s   * 
(*99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}#66']:RV]ajVjnuyn  DK  N[  D[%O^jkl
  	 (,.)+K %F	6N***7ELr    c                 0   t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )a  
        Looks up information in a knowledge base to help with answering customer questions AND helping them if they face any technical difficulty. for example
        My Wifi is not working
        My TV is now working. OR I am unable to get the TV channels
        Is there a business center where I can print documents?

        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL Tech Helpr   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r7   r@   rA   rB   rC   rD   rE   4rG   rH   rI   rJ   rV   )
r0   rW   r   r   r   r	   r%   rX   rY   query_techhelpr[   s           r!   tool_techhelprn      s    
%'99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}#66']:RV]ajVjnuyn  DK  N[  D[%O^jkl
  	 (,.)+K %F	6N''e'4ELr    c                 0   t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )ag  
        Looks up information in a knowledge base to help with answering customer questions AND helping them if they face any Concierge related difficulty. for example
        Does the hotel offer shuttle service to the airport?
        How do I get to the nearest subway/metro station. or Is there a good jogging path nearby?
        Can you recommend a good spa nearby?
        Do you offer babysitting services?
        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL Concierger   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r7   r@   rA   rB   rC   rD   rE   5rG   rH   rI   rJ   rV   )
r0   rW   r   r   r   r	   r%   rX   rY   query_concierger[   s           r!   tool_conciergerr   /  s    
%'99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}#66']:RV]ajVjnuyn  DK  N[  D[%O^jkl
  	 (,.)+K %F	6N((u(5ELr    c                 0   t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )a  
        Looks up information in a knowledge base to help with answering customer questions AND helping them if they face any maintenance difficulty. for example
        The air conditioning in my room isn't working properly
        There's a light bulb out in my bathroom
        The shower drain is clogged.

        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL Maintenancer   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r7   r@   rA   rB   rC   rD   rE   7rG   rH   rI   rJ   rV   )
r0   rW   r   r   r   r	   r%   rX   rY   query_maintenancer[   s           r!   tool_maintenancerv   `  s    
')99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}$777m;SW^bkWkov  {A  pA  EL  O\  E\%O^jkl
  	 (,.)+K %F	6N***7ELr    c                 0   t        d       |j                  d      }|j                  d      }t        d| d|        t        t                     }|dk(  s#|dk(  s|dk(  s|d	k(  s|d
k(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S |dk(  s|dk(  s|dk(  s|dk(  s
|dk(  s|dk(  rt	        dt        d|      gi      S d|d|| ddt               t               d|d}t        |      }t        |       t        j                  |       } | S )a  
        Looks up information in a knowledge base to help with answering customer questions AND helping them if they face any safety and security related difficulty. for example
        I lost my room key. What should I do?
        What should I do in case of an emergency?
        Does the hotel have a safe in the room?

        Args:
            query (str): Question to ask the knowledge base

        Return:
            List[Dict[str, str]]: Potentially relevant question and answer pairs from the knowledge base
    z**Invoking TOOL Security r   r   r+   r,   r6   r8   r9   r:   r;   r<   r=   r>   r   r?   r-   r.   r@   rA   rB   rC   r7   rD   rE   8rG   rH   rI   rJ   rV   )
r0   rW   r   r   r   r	   r%   rX   rY   query_securityr[   s           r!   tool_securityrz     s~    
%'99VDii!G	Kv[	
23UWJrzTJ&$-4<;OSW[bSbfjnyfy  ~B  FM  ~M  PT  Xd  Pd%GVbcd
  	 "}=0Gy4HGW]L]ahkxax  }D  H[  }[%O^jkl
  	 (,.)+K %F	6N''e'4ELr    datac                    	 t               }|r|j                         }d}|j                  || d   | d   | d   | d   | d   | d   | d   | d	   | d
   | d   | d   f       |j                          	 |r2|j	                         r!|j                          |j                          yyy	 |r2|j	                         r!j                          |j                          yyy# t        $ rL}dt        |       cY d}~r2|j	                         r!j                          |j                          S S S d}~ww xY w# r2|j	                         r!j                          |j                          w w w xY w)z4Add a request to the t_requestmaster table in MySQL.z
                INSERT INTO t_Requests(BUID,RequestID, ToDept, FromRoomNo, RequestDescp,BotResponse, Status, RequestCreatedAt,LastUpdatedAt,AttendedBy, GuestName)
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
            rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   zRequest added successfully.Error: N)get_mysql_connectioncursorexecutecommitis_connectedcloser   r   )r{   
connectionr   	sql_queryes        r!   rX   rX     sz   )+
&&(FI NN9V[!X\"^$]#X'(_%\"[!'  0 *113LLN 4:1 0 *113LLN 4:  "Q!!*113LLN 4:" *113LLN 4:s0   A,C 	D/#D*0D/1D2 *D//D2 26E(c                      	 t         j                  j                  dddd      } | j                         rt	        d       | S t	        d       y # t
        $ r}t	        d|        Y d }~y d }~ww xY w)Nz157.173.210.15
testagent1RoyalOrchid)hostuserpassworddatabasezConnected to MySQL databasez"ERROR Connecting to MySQL databaser}   )mysql	connectorconnectr   r0   r   )r   r   s     r!   r~   r~     sv    __,,!!"	 - 

 ""$/067 sms   ?A A 	A/A**A/)-langchain_core.toolsr   typingr   r   rY   r   
sqlalchemymysql.connectorr   r   r   langchain_core.messagesr	   r
   langgraph.graphr   r   langgraph.graph.messager   typing_extensionsr   langgraph.typesr   r   r   r   uuidr   r   r\   r   r%   r2   r_   rc   rg   rj   rn   rr   rv   rz   dictrX   r~   r   r    r!   <module>r      s%   %  $   !  ; ) 3 0 ' # 2 2 \
}I 
; ( (c (3PbKbAc (il ( (& -C - -YsDV?V5W -\`aefiknfnao\p - -^ 3# 3e 39SJ\E\;] 3bfgkloqtltgubv 3 3j , ,T ,3HZCZ9[ ,`deijmorjres`t , ,^ 4C 4 4YsL^G^=_ 4dhimnqsvnviwdx 4 4l - -U -)CI[D[:\ -aefjknpsksftau - -` -# -e -9SJ\E\;] -bfgkloqtltgubv - -` -C - -YsL^G^=_ -dhimnqsvnviwdx - -` - -U -)CI[D[:\ -aefjknpsksftau - -`d s Br    