o
    sg                     @   sb   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZ e ZG dd dZdS )	zSlide researcher    N)ChatPromptTemplate)JsonOutputParser)
ChatOpenAI)OPENAI_API_KEYOPENAI_MODEL_MINIc                   @   sF   e Zd ZdZeededZeddedZdZ	dZ
ddd	Zd
d ZdS )SlideResearchz%Conduct research on the slide content   )modeltemperatureapi_keyzgpt-4o10z20-40Nc                 C   s   || _ || _|| _|| _dS )z#Initialize the slide research classN)slideprimary_dataparsing_classprompt_addition)selfr   r   r   r    r   A/var/www/html/XCapMarket/services/ppt_generator/slide_research.py__init__   s   
zSlideResearch.__init__c                 C   sv  d}|rz`ddd| j  dfdd| j dfddd	d
dg}d| jjv r(|d | jr3|d| jf t|}t| jd}|| j	B |B }|
| jj| jj| jd| d}| jdi | }d}W nR ty   tjddd td || jB |B }|
| jj| jj| jd| d}z| jdi | }d}W n ty   tjddd td Y nw Y nw |s|S )zFormat the slide contentT)systemz[You are an expert in converting the context provided and fit it within the format asked forr   zAll titles should be z tokens or shorterzAll helper text should be )humanzSlide title: {title})r   z&Slide highlevel takeaway is: {content})r   zSlide research data to be used:
                    Rely on primary data here first: {primary_data} 


                    Rely on secondary data here second if needed: {secondary_data})r   z%convert to json format: {json_format})r   zMake the slide content specific to the company. If you don't have specific data points or information, you can use [XXX] as a placeholder Examples: 
                     graph)r   zOIf you don't have actual numbers, use 0 as the placeholder for the data points.r   )pydantic_object )titlecontentr   secondary_datajson_formatFz&Error in formatting the slide content.)exc_info   z%Error in formatting the slide content
   Nr   )title_tokenstext_tokensr   __name__appendr   r   from_messagesr   
llm_model3invoker   r   r   r   get_format_instructionsdict	Exceptionloggingerrortimesleep
llm_model4)r   error_outputprompt_tempchat_promptparserchainchain_outputr   r   r   _format#   sx   


	TzSlideResearch._format)N)r#   
__module____qualname____doc__r   r   r   r&   r/   r!   r"   r   r6   r   r   r   r   r      s    
r   )r9   r+   r-   langchain.promptsr   langchain_core.output_parsersr   langchain_openair   configs.configr   r   	getLogger
XCM_loggerr   r   r   r   r   <module>   s    