o
    &ai	                     @   sJ   d dl mZ d dlmZ d dlZd dlmZ d dlZdZG dd dZ	dS )    )LLM)settingsN)Pathz(user_journey_service/config/prompts.yamlc                   @   s$   e Zd Zdd Zdd Zdd ZdS )MicrolearningDurationEstimatorc              	   C   s@   t tj dtj tjtjtjtjtjtj	d| _
|  | _d S )N/)modeltemperatureapi_keyapi_baseapi_versionseedtimeout)r   r   PROVIDERLLM1TEMPERATUREOPENAI_KEY1	ENDPOINT1API_VERSION1SEEDTIMEOUTllmload_promptsprompts)self r   q/home/azureuser/microlearn/backend/user_journey_with_openai/user_journey_service/processors/duration_estimator.py__init__
   s   	z'MicrolearningDurationEstimator.__init__c                 C   st   t ttd}| }W d   n1 sw   Y  z|d}W n ty2   |jddd}Y nw t|}|S )z9Load prompts from YAML file with explicit UTF-8 encoding.rbNzutf-8replace)errors)openr   prompts_pathreaddecodeUnicodeDecodeErroryaml	safe_load)r   fcontent_bytescontentr   r   r   r   r      s   

z+MicrolearningDurationEstimator.load_promptsc           
      C   s   | j d }|j|j|j|j|j|jd}d|dg}| j|}|	 }t
d|}|r3t|d }nd}d}	||	kr=|	}t|S )	Nduration_estimator)	Job_Title
ExperienceSkillstopicLeveluser)roler)   z\d+r      ih  )r   formatr+   r,   r-   r.   r/   r   callstriprefindallintstr)
r   
input_dataprompt_templatepromptmessagesresponseduration_textnumbersestimated_minutesMAX_MINUTESr   r   r   estimate_duration'   s,   

z0MicrolearningDurationEstimator.estimate_durationN)__name__
__module____qualname__r   r   rC   r   r   r   r   r   	   s    r   )
crewair    user_journey_service.core.configr   r%   pathlibr   r6   r!   r   r   r   r   r   <module>   s    