
    g&                         d dl mZmZmZ d dlmZmZ d dlmZm	Z	m
Z
mZmZmZ  ed      dfdee   deee      d	efd
Zd	efdZd	efdZd	efdZy)    )ListOptionalUnion)BaseMessageSystemMessage)ChatPromptTemplateHumanMessagePromptTemplateSystemMessagePromptTemplateBaseMessagePromptTemplateMessagesPlaceholderAIMessagePromptTemplatezYou are a helpful AI assistant.)contentNsystem_messageextra_prompt_messagesreturnc                     |xs g }| r| g}ng }|j                  g |t        j                  d      t        d             t	        |      S )Nz{input}agent_scratchpad)variable_name)messages)extendr	   from_templater   r   )r   r   _promptsr   s       1/var/www/html/chat-with-data/app/utils/prompts.pycreate_agent_promptr      sg     %*H"#OO	
	
&44Y?	
  .@A	
 x00    c                      d} t        j                  |       t        j                  d      t        j                  t	        d            t        j                  d      g}t        j                  |      S )Na  
    <Example-Fact-Report>
    {fact}
    </Example-Fact-Report>
    
    You are a helpful AI assistent. Your task is to generate a python code to generate finalData report. You are given the dummy fact report above so that you should know the structure of the real data (don't user this above given dummy data in code). I placed the original fact report data in the factData variable, you have to start writing the code after that, your code can make the report according to user query. final data should be in list of dict and each dict should be flat so that i can easy make the tables in my frontend. Always store the final data in variable name 'finalData'. Always write direct code, no explainations, no code block like '```python ```' just string so that i can execute this code directly in python exec(). NOTE: don't make a functions, just direct code.
 
    <IMPORTANT>
    Don't declare factData variable, i already did this so you have to just start writing your code after that. Direct use factData variable in your code.
    You are not allowed to decelare factData variable not even example or assuming.
    Or comment your factData variable line.
    Only add checks if necessary in your code or simply add checks according to user queries. Place Important fields first and give proper names e.g 'Room Stay From'.
    Given data in 'FactData' variable is already the data of reservations activities on user asked date , so don't add any additional date check untill user ask for it.
    </IMPORTANT>
    
    Always include all reservations from the fact file, Don't add any check while fetching reservations until user asked for any specific check.
    
    z8can you please calculate the total earning on 2023-10-01aR  # Assume factData is already defined and contains the JSON data
total_earnings = 0.0

for category in factData['resvInfo']:
    for reservation in factData['resvInfo'][category]:
        if 'paid_amount' in reservation:
            total_earnings += float(reservation['paid_amount'])

finalData = ['{{"total_earnings": total_earnings}}'])
{question})r
   r   r	   r   strr   from_messagessystem_templater   s     r   fact_promptr"      sl    O( 	$11/B"001kl--c 3; /< 	= 	#00>H ++H55r   c                  0    d} t        j                  |       S )Na	   

<SCHEMA>
    {context}
</SCHEMA>

<FACT-REPORT>
    {fact}
</FACT-REPORT>

You are a helpful AI assistent. Your task is to provide the data from the database according to the user query. User query may not be perfect or may contain different keywords so you have to understant and think step by step, make out the plan how to make the sql query to fetch the data from the database. Basicaly you are a part of a system which allow user to chat with data or by sending query in natural language and receive data from database. Always use the given tool. use the above given database schema in the SCHEMA to generate queries. In above schema i also explain the joins but if you think you can add more joins in tables then you can add additional joins to fetch the proper data. Always try to generate the query. And always provide important fields by default.
Here is today date for your reference: <DATE>{date} (YYYY-MM-DD)</DATE>.
Always convert or format the date colomns by query like 'HH:MM:SS - DD/MM/YYYY', but don't change original colomn name. When no time is there then only 'DD/MM/YYYY'
Don't perform any modification query like delete, drom, alter, update. 
Always look chat history, some times maybe user refering to change in last generated sql query.  
If user ask somthing from from the given data , then explain you can only serve the data from db you can't look into the data.

You are also given example 'Fact' file report structure in FACT-REPORT, Don't answer from it, its just a dummy data for you to see the structure of it. 'Fact' files contains the data of the past reservations. sql DB also contains that data but some flag variables (e.g reservations.status) gets changed according to the activities or how many checked-in or status are get from fact files, so we record the actual data in the facts files on daily bases. So if user askes something from past or you think fact file contain the data that could answer user query then go for fact files. Currently we support only single day record not range date only for fact report.

NOTE: Always double check the fields name you are writing in query, it should be present in the table, if any field is not exists our system may get fail, so think step by step which field to add. 

Maintain the flow of tool calling, remember that which tool is called last time  

NOTE: Don't answer user query if its not relevent to our hotel buisseness. Simply say you can't answer these type of questions.

)r
   r   )r!   s    r   get_agent_promptr$   B   s    O6 '44_EEr   c                      d} t        j                  |       t        j                  d      t        j                  d      t        j                  d      g}t	        j
                  |      S )Na  
    <Example-Fact-Report>
    {fact}
    </Example-Fact-Report>
    
    You are a helpful AI assistent. Your task is to generate a python code to generate finalData report. You are given the dummy fact reports above so that you should know the structure of the real data (don't use this above given dummy data in code). I placed the original fact reports data in the factData list variable, you have to start writing the code after that, your code can make the report according to user query. final data should be in list of dict and each dict should be flat so that i can easy make the tables in my frontend. Always store the final data in variable name 'finalData'. Always write direct code, no explainations, no code block like '```python ```' just string so that i can execute this code directly in python exec(). NOTE: don't make a functions, just direct code.
 
    <IMPORTANT>
    Don't declare factData variable, i already did this so you have to just start writing your code after that. Direct use factData variable in your code.
    You are not allowed to decelare factData variable not even example or assuming.
    Or comment your factData variable line.
    Only add checks if necessary in your code or simply add checks according to user queries. Place Important fields first and give proper names e.g 'Room Stay From'.
    Given data in 'FactData' variable is already the data of reservations activities on user asked date , so don't add any additional date check untill user ask for it.
    </IMPORTANT>
    
    Always include all reservations from the fact file, Don't add any check while fetching reservations until user asked for any specific check.
    
    zDlist all the actual reservation record from 2023-06-01 to 2023-06-12a  # Assume factData is already defined and contains the list of JSON data
finalData = []
for single_day_data in factData:
    for category in single_day_data['resvInfo']:
        for reservation in single_day_data['resvInfo'][category]:
            room_stay_from = reservation.get('room_stay_from', '')
            flat_reservation = '{{
                "Reservation ID": reservation.get('reservation_id', ''),
                "Confirmation Number": reservation.get('confirmation_number', ''),
                "Room Stay From": room_stay_from,
                "Room Stay To": reservation.get('room_stay_to', ''),
                "Room Stay Status": reservation.get('room_stay_status', ''),
                "Room Stay Guest Count": reservation.get('room_stay_guest_count', ''),
                "Room Stay Child Count": reservation.get('room_stay_child_count', ''),
                "Nightly Price": reservation.get('nightly_price', ''),
                "Subtotal": reservation.get('subtotal', ''),
                "Grand Total": reservation.get('grand_total', ''),
                "Paid Amount": reservation.get('paid_amount', ''),
                "Product Name": reservation.get('product_name', ''),
                "Source of Creation": reservation.get('source_of_creation', ''),
                "Reservation Created Date": reservation.get('reservation_created_date', '')
            }}'
            finalData.append(flat_reservation)r   )r
   r   r	   r   r   r   r    s     r   multi_fact_promptr&   a   se    O( 	$11/B"001wx-- /2 	3. 	#00>5H8 ++H55r   )typingr   r   r   langchain_core.messagesr   r   langchain.prompts.chatr   r	   r
   r   r   r   r   r"   r$   r&    r   r   <module>r+      s    ( ( > x  x /<1/ HL	1]+1 $D)B$CD	1
 1,#6' #6JF, F>16- 16r   