o
    5ti                     @   s   U d dl Z d dlZd dlZd dlmZ d dlmZ eeZ	ddddiZ
eeeeef f ed< dd	ed
edefddZ	ddefddZG dd dZdS )    N)Dict)utilszqa-basiczQuestion: {{question}}
Answer:zQ: {{question}}
A:)zquestion-newline-answerzq-newline-aPROMPT_REGISTRY	prompt_iddataset_namesubset_namec              
   C   st  |  d\}}|d u r|}n| d| }td| d|  |dkrwzddlm} W n ty? } zt|dd	d }~ww z|d u rK||d
}n|||d}W n tyc   t| d| dw ||j	v rm|| S t| d|j	 d|v rdd l
}	t|d}
|	|
}W d    n1 sw   Y  |d | }t|S zt| | W S  ty   td|  dw )N:-zLoading prompt from z for promptsourcer   DatasetTemplateszITried to load a Promptsource template, but promptsource is not installed zcplease install promptsource via pip install lm-eval[promptsource] or pip install -e .[promptsource]r   r   r   z and z
 not foundz not in prompt list .yamlrbpromptszcexpected only a single `:` as separator between                 prompt category and name, but got `z	` instead)spliteval_loggerinfopromptsource.templatesr   ModuleNotFoundErrortype	Exception
ValueErrorall_template_namesyamlopen	full_loadPromptStringr   )r   r   r   category_nameprompt_namedataset_full_namer   	exceptionr   r   fileprompt_yaml_fileprompt_string r&   L/home/ubuntu/.local/lib/python3.10/site-packages/lm_eval/prompts/__init__.py
get_prompt   s\   
r(   
use_promptc                    s   |  d\ } dkr)ddlm} |d u r||d}n|||d}t||j}n;d v rddd l}	|d ur@tj	tj
|  t d}
|	|
}W d    n1 sUw   Y  t||d	  } fd
d|D S )Nr   r
   r   r   r   r   r   r   r   c                    s   g | ]	}d   |gqS )r   )join).0promptr   r&   r'   
<listcomp>n   s    z$load_prompt_list.<locals>.<listcomp>)r   r   r   r   pattern_matchr   r   ospathrealpathr*   r   r   keys)r)   r   r   	yaml_pathkwargsr    r   r   prompt_listr   r#   r$   r&   r-   r'   load_prompt_listH   s(   r7   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s
   || _ d S )N)r%   )selfr%   r&   r&   r'   __init__r   s   
zPromptString.__init__c                 C   sF   | j d }| j d }d| j v rtdt||}t||}||gS )Ndoc_to_textdoc_to_targetdoc_to_choicez+Not yet implemented to accept doc_to_choice)r%   NotImplementedErrorr   apply_template)r8   docr:   r;   text_stringtarget_stringr&   r&   r'   applyu   s   


zPromptString.applyN)__name__
__module____qualname__r9   rB   r&   r&   r&   r'   r   q   s    r   )NN)NNN)astloggingr0   typingr   lm_evalr   	getLoggerrC   r   r   str__annotations__r(   r7   r   r&   r&   r&   r'   <module>   s"   
 
2
)