o
    sg
                     @   s   d Z ddlZejd ddlZddlZddlmZ e  ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ dd	lmZ G d
d deZdedeeeeB eB   fddZedkroddlmZ eg dZeeej dS dS )z(Format Public Comps as a table using LLM    N.)load_dotenv)JsonOutputParser)ChatPromptTemplate)
ChatOpenAI)	BaseModelField)OPENAI_MODEL_35c                   @   s2   e Zd ZU edddZeeeeB eB   e	d< dS )TableOutput.z!List of list for the table's data)titledataN)
__name__
__module____qualname__r   r   liststrfloatint__annotations__ r   r   N/var/www/html/XCapMarket/services/stock_info/public_comparable_format_table.pyr
      s   
 "r
   r   returnc                 C   s  t tdtdd}i }| D ]T}| | d }|D ]E}t|| tr2|| dkr1t|| d ||< qt|| tr]|| D ]}t|| | tr\|| | dkr\|| | d || |< q=q|||< qt	g d}t
td}||B |B }	|	t|| d	}
|
S )
Ng?OPENAI_API_KEY)modeltemperatureapi_key
comp_tablei i ʚ;))systemz.You are an expert with the Python PPTX library)r   zXYou are going to create a table for the data provided. Return the data as a list of list)r   zQDon't provide the ticker column and add an empty column between Name and the data)r   zIf there are units such as Billions or Millions consistent across the column, add it to the header. Don't add it to the Multiples like EV / Revenue)humanz)The data you have to work with is: {data})r   z!Return the in JSON: {json_format})placeholderz{agent_scratchpad})pydantic_model)r   json_format)r   r	   osgetenv
isinstancer   r   dictr   from_messagesr   r
   invokejsondumpsget_format_instructions)r   llm	llm_inputtickerr   keysub_keypromptparserchainoutputr   r   r   format_for_table   s6   

r4   __main__)PublicComparables)AAPLTSLAMETAMSFT) __doc__syspathappendr(   r"   dotenvr   langchain_core.output_parsersr   langchain_core.promptsr   langchain_openair   pydanticr   r   configs.configr	   r
   r%   r   r   r   r   r4   r   %services.stock_info.public_comparabler6   pcprintr   r   r   r   r   <module>   s&    "4