o
    &i                     @   s&   d dl Z d dlmZ G dd dZdS )    N)OpenAIc                   @   sR   e Zd ZdedededefddZdd Zd	ed
efddZd	ed
efddZ	dS )
LLMServicebase_urlapi_keymodeltimeout_secondsc                 C   s"   || _ || _|| _d | _|| _d S )N)r   r   r   clientr   )selfr   r   r   r    r
   E/home/aiteam/pcaa-dev/ai-call-quality-rag/app/services/llm_service.py__init__   s
   
zLLMService.__init__c                 C   s&   | j d u rt| j| j| jd| _ | j S )N)r   r   timeout)r   r   r   r   r   )r	   r
   r
   r   _get_client   s   
zLLMService._get_clientpromptreturnc                 C   sL   |   jjj| jddidddd|dgdd}|jd	 jjp d
}t	|S )Ntypejson_objectsystemz"You output strict valid JSON only.rolecontentuserg?)r   response_formatmessagestemperaturer   z{})
r   chatcompletionscreater   choicesmessager   jsonloads)r	   r   respr   r
   r
   r   generate_json   s   	
zLLMService.generate_jsonc                 C   s<   |   jjj| jdddd|dgdd}|jd jjpdS )	Nr   z)You are a call quality advisor assistant.r   r   g?)r   r   r   r    )r   r   r   r   r   r   r   r   )r	   r   r"   r
   r
   r   answer#   s   zLLMService.answerN)
__name__
__module____qualname__strintr   r   dictr#   r%   r
   r
   r
   r   r      s
    	r   )r    openair   r   r
   r
   r
   r   <module>   s    