HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/calendar/calendar-planning/app/utils/__pycache__/openai_utils.cpython-312.pyc
�

�hDg
����ddlmZddlmZddlmZmZddlZddlm	Z	e	�eejd��ZGd�d	e�ZGd
�de�Z
dded
edefd�Zddddddd�ddd�d�dgd�d�d�gZdd�Zy) �)�OpenAI)�settings)�	BaseModel�FieldN)�load_dotenv�OPENAI_API_KEY)�api_keyc�h�eZdZUedd��Zeed<edd��Zeed<edd��Zeed<y	)
�EventDetail.zName of the event��description�namezEStarting date of the event in DD-MM-YYY format if present else use NA�datez<Location of the event city or country if present else use NA�locationN)	�__name__�
__module__�__qualname__rr�str�__annotations__rr���I/home/arjun/projects/calendar/calendar-planning/app/utils/openai_utils.pyrrs8���s�(;�<�D�3�<��s�(o�p�D�3�p��3�,j�k�H�s�krrc�<�eZdZUedd��Zeed<eeed<y)�Event.z Event category given by the userr�category�event_detailN)	rrrrrrr�listrrrrrrs���3�,N�O�H�s�O��{�#�#rr�user_prompt�model�returnc��d}tjjjj	|d|d�d|d�gt
d��}|jdj}|jr|jStd�iS)	Na.You will be provided with a Category, Year, Location, and text scraped from a website. Your task is to extract and generate unique event details that are relevant to the given Category, Year, and Location. Ensure that all event details are distinct, with no duplicate event names or repetitive entries. Each event should be explicitly tied to the inputs provided, and any event lacking sufficient information in the text should be excluded. Focus on accuracy and avoid assumptions, ensuring the generated content is clear, complete, and free from redundancy.�system)�role�content�useri@)r�messages�response_format�
max_tokensrz	No result)
�client�beta�chat�completions�parser�choices�message�parsed�print)rr�
system_prompt�
completion�results     r�generate_eventsr5s���H	�M����!�!�-�-�3�3���-�8���4�
�
��4�	�J��
�
��
"�
*�
*�F�
�}�}��}�}��
�k���	r�function�
search_webz"Search the web using google search�object�stringzThe query to be searched.)�typer
zThe result of web search.)�search_query�formatr;)r:�
properties�required)rr
�
parameters)r:r6c���	tjjj||||��}|S#t$r%}td�td|���|cYd}~Sd}~wwxYw)N)rr&�tools�tool_choicez*Unable to generate ChatCompletion responsezException: )r)r+r,�create�	Exceptionr1)r&rArBr�response�es      r�chat_completion_requestrGKsf����;�;�*�*�1�1����#�	2�
�������
�:�;�
��A�3�� �����s�.1�	A�A�A�A)�gpt-4o-mini)NNrH)�openair�django.confr�pydanticrr�os�dotenvr�environr)rrr�dictr5rArGrrr�<module>rPs���� �%�	���
�
��
�
�#3�4�	5��l�)�l�$�I�$�
���3��4��<� �?� �!)�'B�%�
!)�'B��	�,�,�
�
��	��0r