B
    *e                 @   sJ   d dl mZ d dlZedZede_G dd dZG dd deZdS )	    )dotenv_valuesNz.envZOPENAI_API_KEYc               @   s   e Zd Zdd Zdd ZdS )OpenAiChatCompletionClientc             C   s
   d | _ d S )N)response)self r   C/home/dictionary/smart-dictionary-consec/app/gogyup/openai_tools.py__init__	   s    z#OpenAiChatCompletionClient.__init__c             C   s*   d|dg}t jjd|ddddd| _d S )Nuser)Zrolecontentzgpt-3.5-turboi      r   )modelmessagesZ
max_tokensZtop_pZfrequency_penaltyZpresence_penalty)openaiZChatCompletioncreater   )r   promptr   r   r   r   send   s    zOpenAiChatCompletionClient.sendN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                   s&   e Zd Z fddZdddZ  ZS )OpenAiTranslatorc                s   t    d S )N)superr   )r   )	__class__r   r   r      s    zOpenAiTranslator.__init__Spanishc             C   s8   |  }|ds|d7 }dj|||d}| | d S )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   r   r   r   	translate   s    
zOpenAiTranslator.translate)r   )r   r   r   r   r"   __classcell__r   r   )r   r   r      s   r   )dotenvr   r   configgetZapi_keyr   r   r   r   r   r   <module>   s
   