o
    7ti)                     @   s   d dl Z d dlZzd dlZW n ey   edw dgddgdZi eddgiZd	d
 Zdede	ddfddZ
dddZedkrHe  dS dS )    Nz`pycountry` is required for generating translation task prompt templates. please install pycountry via pip install lm-eval[multilingual] or pip install -e .[multilingual]zfr-enzro-enzde-en)wmt14wmt16	iwslt2017zen-arc                 C   s&   t jjdi dt|  | i}|jS )Nalpha_ )	pycountry	languagesgetlenname)codelanguage_tupler   r   S/home/ubuntu/.local/lib/python3.10/site-packages/lm_eval/tasks/translation/utils.pycode_to_language#   s    r   
output_dir	overwritereturnc                 C   s  g }t  D ]}t | D ]}|d\}}}||g||gfD ]\}}	|d |	 }
| d|
 d}zut|t|	}}dd|g}|t v rJ|dg7 }t|  d| |rUdnd	d
dB}|d td|||dksk|nd| | d|
 | dd d| d d | d dd|	 d d d| W d   n1 sw   Y  W q t	y   |
| Y qw qqt|dkrt	dd| dS )z
    Generate a yaml file for each language.

    :param output_dir: The directory to output the files to.
    :param overwrite: Whether to overwrite files if they already exist.
    -_z.yamlgenerate_untiltranslationgpt3_translation_benchmarks/wxutf8)encodingz# Generated by utils.py
wmt_common_yamlr   z
iwslt2017-z	 phrase: z{{translation["z]}}
z phrase:z {{translation[z"]z}})includegroupdataset_pathdataset_nametaskdoc_to_textdoc_to_targetNr   zJFiles were not created because they already exist (use --overwrite flag): z, )	LANGUAGESkeys	partitionr   r   openwriteyamldumpFileExistsErrorappendr
   join)r   r   errlangr"   src_langr   tgt_langsrctgt	lang_pair	file_namesourcetargetgroupsfr   r   r   gen_lang_yamls)   st   





+r<   c                  C   sF   t  } | jddddd | jdddd	 |  }t|j|jd
 dS )z9Parse CLI args and generate language-specific yaml files.z--overwriteF
store_truez%Overwrite files if they already exist)defaultactionhelpz--output-dir.z Directory to write yaml files to)r>   r@   )r   r   N)argparseArgumentParseradd_argument
parse_argsr<   r   r   )parserargsr   r   r   maind   s   rH   __main__)r   N)rB   r+   r   ModuleNotFoundError	Exceptionr   r&   r   strboolr<   rH   __name__r   r   r   r   <module>   s2    	
;
