Team Ai
Apppublic

afulara/PythonicRAG-FastAPI-React

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
prompts.cpython-312.pyc51 linesDownload Raw Back to __pycache__
1�

2ʱ�g�	��4�ddlZGd�d�ZGd�de�ZGd�de�ZGd�d	e�ZGd3�de�Zedk(rYed
�Zeejdd���ed
�Zeejdd���eej��yy)�Nc��eZdZd�Zd�Zd�Zy)�4BasePromptc�F�||_tjd�|_y)z�5        Initializes the BasePrompt object with a prompt template.6 7        :param prompt: A string that can contain placeholders within curly braces8        z\{([^}]+)\}N)�prompt�re�compile�_pattern)�selfrs  ��/Users/aqsa/AI Projects/AIE6 Class Projects/AIE6-DeployPythonicRAG-Fastapi-react-app/backend/aimakerspace/openai_utils/prompts.py�__init__zBasePrompt.__init__s������9�10�>�2��
�c���|jj|j�}|jjdi|D�cic]}||j	|d���c}��Scc}w)z�11        Formats the prompt string using the keyword arguments provided.12 13        :param kwargs: The values to substitute into the prompt string14        :return: The formatted prompt string15        ��)r	�findallr�format�get)r16�kwargs�matches�matchs    r�
format_promptzBasePrompt.format_promptsT���-�-�'�'����4��!�t�{�{�!�!�X�w�$W�e�U�F�J�J�u�b�,A�%A�$W�X�X��$Ws�A!c�L�|jj|j�S)z~17        Gets the list of input variable names from the prompt string.18 19        :return: List of input variable names20        )r	rr)r21s r�get_input_variableszBasePrompt.get_input_variabless���}�}�$�$�T�[�[�1�1r
N)�__name__�22__module__�__qualname__rrrrr
rrrs��3�Y�2r
rc�,��eZdZdef�fd�Zdd�Z�xZS)�23RolePrompt�rolec�2��t�|�|�||_y)z�24        Initializes the RolePrompt object with a prompt template and a role.25 26        :param prompt: A string that can contain placeholders within curly braces27        :param role: The role for the message ('system', 'user', or 'assistant')28        N)�superrr)r29rr�	__class__s   �rrzRolePrompt.__init__"s���	���� ���	r
c�v�|r|j|jdi|��d�S|j|jd�S)z�30        Creates a message dictionary with a role and a formatted message.31 32        :param kwargs: The values to substitute into the prompt string33        :return: Dictionary containing the role and the formatted message34        )r�contentr)rrr)r35rrs   r�create_messagezRolePrompt.create_message,s:��� �I�I�2D�$�2D�2D�2N�v�2N�O�O��	�	�d�k�k�:�:r
)T)rrr�strrr%�
__classcell__�r"s@rrr!s����S��36;r
rc�$��eZdZdef�fd�Z�xZS)�SystemRolePromptrc�&��t�|�|d�y)N�system�r!r�r37rr"s  �rrzSystemRolePrompt.__init__:s���
�����*r
�rrrr&rr'r(s@rr*r*9s���+�s�+�+r
r*c�$��eZdZdef�fd�Z�xZS)�UserRolePromptrc�&��t�|�|d�y)N�userr-r.s  �rrzUserRolePrompt.__init__?s���
�����(r
r/r(s@rr1r1>s���)�s�)�)r
r1c�$��eZdZdef�fd�Z�xZS)�AssistantRolePromptrc�&��t�|�|d�y)N�	assistantr-r.s  �rrzAssistantRolePrompt.__init__Ds���
�����-r
r/r(s@rr5r5Cs���.�s�.�.r
r5�__main__z%Hello {name}, you are {age} years old�John�)�name�age)rrrr*r1r5rr�printrr%rrr
r�<module>r>s���	�2�2�:;��;�0+�z�+�38)�Z�)�39.�*�.�40�z��
�?�
@�F�	�&�41�42�F��43�443�4�
�E�
F�F�	�&�45�46�V��47�484�5�	�&�49$�50$�51&�'�
r