
    *e                     ~    d dl mZ d dlZ ed      Zej	                  d      e_         G d d      Z G d de      Zy)	    )dotenv_valuesNz.envOPENAI_API_KEYc                       e Zd Zd Zd Zy)OpenAiChatCompletionClientc                     d | _         y N)response)selfs    C/home/dictionary/smart-dictionary-consec/app/gogyup/openai_tools.py__init__z#OpenAiChatCompletionClient.__init__	   s	        c                 d    d|dg}t         j                  j                  d|dddd      | _        y )Nuser)rolecontentzgpt-3.5-turboi      r   )modelmessages
max_tokenstop_pfrequency_penaltypresence_penalty)openaiChatCompletioncreater	   )r
   promptr   s      r   sendzOpenAiChatCompletionClient.send   s>    #78--44! 5 
r   N)__name__
__module____qualname__r   r    r   r   r   r      s    	
r   r   c                   &     e Zd Z fdZddZ xZS )OpenAiTranslatorc                 "    t         |           y r   )superr   )r
   	__class__s    r   r   zOpenAiTranslator.__init__   s    r   c                     |j                         }|j                  d      s|dz  }dj                  |||      }| j                  |       y )N).?!r(   a  You will be given an English sentence, and a selected word that appears in that sentence. Translate the sentence from English to {language}.If the selected word is part of an idiomatic expression, then mark the idiomatic expression instead. Write a definition in {language} of the selected word or words. Return a JSON object with the following keys: 'translation', 'definition'.

English sentence: "{context}"
selected word: "{word}")wordcontextlanguage)stripendswithformatr   )r
   r+   r,   r-   r   s        r   	translatezOpenAiTranslator.translate   sO    --/0sNG( )/D'T\(] 	 			&r   )Spanish)r   r   r    r   r1   __classcell__)r&   s   @r   r#   r#      s    r   r#   )dotenvr   r   configgetapi_keyr   r#   r!   r   r   <module>r8      s=      	v	,-
 
 1 r   