o
    ̳i                     @   s0   d dl mZ d dlmZmZ G dd deZdS )    )List)MessagePromptTemplateInterfacec                   @   s8   e Zd ZdZdddddZdee dee fdd	Zd
S )Llama2ChatTemplatea
  
    Prompt template that formats chat data of human and system prompts with appropriate tags
    used in Llama2 pre-training. Taken from Meta's official `Llama inference
    repository <https://github.com/meta-llama/llama/blob/main/llama/generation.py>`_.

    .. code-block:: text

        "[INST] <<SYS>>
        You are a helpful, respectful and honest assistant.
        <</SYS>>"

        I am going to Paris, what should I see? [/INST] Paris, the capital of France, is known for its stunning architecture..."


    )z<<SYS>>
z
<</SYS>>

)z[INST] z	 [/INST] ) r   )systemuser	assistantipythonmessagesreturnc              
   C   s   g }g }|D ]Z}|j dkr'd| jd d dg|j d| jd d dg }q|j dkrHd| jd d dg| |j d| jd d dg }n|j dkrP|j}|t|j ||j|j|jd q|S )	a  
        Format user and system messages with appropriate tags.

        Args:
            messages (List[Message]): a single conversation, structured as a list
                of `Message` objects

        Returns:
            The formatted list of messages
        r   textr   )typecontent   r   r	   )roler   maskedr
   eot)r   templater   appendr   r   r
   r   )selfr   system_messageformatted_dialoguemessager    r   \/home/ubuntu/.local/lib/python3.10/site-packages/torchtune/models/llama2/_prompt_template.py__call__#   s@   
	

	zLlama2ChatTemplate.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s    r   N)typingr   torchtune.datar   r   r   r   r   r   r   <module>   s   