o
    }oi                     @   s   U d dl mZmZ d dlZeeeej f Zee	e	gef Z
i aeeeef eB e
f ed< ddedefddZddee	B d	ee	B d
e
fddZde	eB d	e	eB d
efddZdS )    )CallableTypeNPROMPT_FORMAT_FNSexample_typeformatter_typec                    s2   dt ttgttttj f f f fdd}|S )aE  
    Decorator for registering text prompt functions.
    It allows to select the right prompt formatting function based on the types of the
    example and the prompt formatter, allowing different strategies for formatting different
    types of data with different prompt formats.

    When formatter_type is set None, registers a default prompt format function for a given data type.

    Example::

        >>> @registered_prompt_format_fn(SourceTargetTextExample, Llama2PromptFormatter)
        ... def my_src_tgt_text_prompt(example, formatter):
        ...     pass
        ...
        ... @registered_prompt_format_fn(Cut, Llama2PromptFormatter)
        ... def my_audio_prompt(example, formatter):
        ...     pass
        ...
        ... prompt_fn = get_prompt_format_fn(SourceTargetTextExample, Llama2PromptFormatter)
    	prompt_fnc                    s$   d u r
| t  < | S | t  f< | S N)r   )r   r   r    Z/home/ubuntu/.local/lib/python3.10/site-packages/nemo/collections/common/data/prompt_fn.py
_decorator.   s
   z/registered_prompt_format_fn.<locals>._decorator)r   objectdictstrlisttorchTensor)r   r   r   r
   r	   r   registered_prompt_format_fn   s   .r   examplepromptreturnc              	   C   s   t | ts	t| } t |tst|}|  D ]#}| D ]}||ftv r.t||f     S q|tv r9t|   S qtd|  d| dtt  )z9See the documentation of ``text_prompt_formatter`` above.z$Unknown prompt format function for (z, z). Available choices are: )
isinstancetypemror   
ValueErrorr   keys)r   r   example_subtypeprompt_subtyper
   r
   r   get_prompt_format_fn9   s"   


r   c                 C   s   t | |}|| |S )z
    Utility for resolving the prompt format function and applying it to an example in one go.
    See the documentation of ``text_prompt_formatter`` above.
    )r   )r   r   fnr
   r
   r   apply_prompt_format_fnU   s   

r    r   )typingr   r   r   r   r   r   r   PromptFormatFnReturnTyper   PromptFormatSignaturer   tuple__annotations__r   r   r    r
   r
   r
   r   <module>   s     !"