o
    NK&h                     @   sT   d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
 G dd deZdS )	z"Copyright (C) 2020 Nidhal Baccouri    N)ListOptional)BaseTranslator)OPEN_AI_ENV_VAR)ApiKeyExceptionc                
       s   e Zd ZdZddeeddfdededee d	ee f fd
dZ	dedefddZ
dedefddZdee dee fddZ  ZS )ChatGptTranslatorzv
    class that wraps functions, which use the DeeplTranslator translator
    under the hood to translate word(s)
    autoenglishNzgpt-3.5-turbosourcetargetapi_keymodelc                    s6   |st td|| _|| _t jd||d| dS )z
        @param api_key: your openai api key.
        @param source: source language
        @param target: target language
        )env_var)r
   r   N )r   r   r   r   super__init__)selfr
   r   r   r   kwargs	__class__r   J/var/www/html/venv/lib/python3.10/site-packages/deep_translator/chatgpt.pyr      s
   
zChatGptTranslator.__init__textreturnc                 K   sV   ddl }| j|_d| j d}|d| d7 }|jj| jd|dgd	}|jd jjS )
zQ
        @param text: text to translate
        @return: translated text
        r   NzTranslate the text below into z.
zText: ""user)rolecontent)r   messages)	openair   r   ChatCompletioncreater   choicesmessager   )r   r   r   r   promptresponser   r   r   	translate&   s   
zChatGptTranslator.translatepathc                 K      | j |fi |S )N)_translate_file)r   r&   r   r   r   r   translate_file>   s   z ChatGptTranslator.translate_filebatchc                 K   r'   )z`
        @param batch: list of texts to translate
        @return: list of translations
        )_translate_batch)r   r*   r   r   r   r   translate_batchA   s   z!ChatGptTranslator.translate_batch)__name__
__module____qualname____doc__osgetenvr   strr   r   r%   r)   r   r,   __classcell__r   r   r   r   r      s$    
"r   )__copyright__r1   typingr   r   deep_translator.baser   deep_translator.constantsr   deep_translator.exceptionsr   r   r   r   r   r   <module>   s    