
    0gq               	          d dl Z d dl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 ddlmZ ddlmZmZmZmZmZmZmZmZ d	Zd
Z e j        ej                  Z e
g dg dg dg dg dg dd          ZeeeeeeedZ e e          5 Z! ej"        e!          Z#ddd           n# 1 swxY w Y    e e          5 Z! ej"        e!          Z$ddd           n# 1 swxY w Y   d dl%m&Z& d Z'd Z(d Z)d Z*ed             Z+dS )    N)settings)login_required)OrderedDict   )respostas_prontasresposta_treinamento_aplicativo)resposta_coeficiente_parede) system_educacional_carga_termicasystem_cadastro_projetosystem_cadastro_ambientesystem_lista_ambientesystem_bibliotecasystem_relatoriossystem_termo_referenciasystem_geralz</var/www/html/cagpublico/cag/projeto/fabiano_embeddings.jsonzF/var/www/html/cagpublico/cag/projeto/respostas_prontas_embeddings.json)api_key)
zcadastrar ambientezquero cadastrar um ambientezcomo cadastrar um ambienteznovo ambientezcriar ambienteu   formulário de ambientezadicionar ambientezinserir ambientezambiente novozpreencher ambiente)zcadastrar projetozquero cadastrar um projetozcomo cadastrar um projetoznovo projetozcriar projetozinserir projetoznome do projetozcidade do projetozcoordenadas do projetozabrir projetozadicionar projeto)	u   termo de referênciaztermo de referenciau   licitaçãoz	lei 8.666u   compras públicaszdocumento para comprazdocumento oficialu   justificativa técnicazprojeto para edital)u
   relatório
relatoriosu   gráficou	   gráficoszresultado finalzexportar docxu   documentaçãoztabela de dadosu   resultados do cálculou   relatório técnicozarquivo docx)zlista de ambienteszvisualizar ambienteszver ambienteszresultados do ambientezmostrar ambientesu   relatório do ambientezambientes cadastradoszdados do ambiente)coeficientecoeficientes
biblioteca   valores térmicos   resistência térmicau   material de construçãoztabela de valores
isolamento   potência térmica   dissipação de calorztabela coeficientezqual coeficientezcoeficiente uzu-valueu   valor térmicou   coeficiente térmicor   r   r   r   r   )r   r   r   r   r   r   )r
   r   r   r   r   r   r   )SequenceMatcherc                 $   |                                                                  }d|v rd|v rt          S d }d}t          j                    D ]/}t          d ||                                          }||k    r|}|}0|dk    rt          |         S d S )Ntreinamento
aplicativog        g      ?)lowerstripr   r   keysr   ratio)textotexto_normalizadomelhor_chavemaior_similaridadechavesims         "/var/www/html/cag/projeto/agent.pyresposta_fixa_se_houverr+   [   s    ++-- )))l>O.O.O.. L"')) % %d$5u==CCEE### L!$D   ..4    c                     t           j                            | d          }t          j        |j        d         j                  S )Nztext-embedding-ada-002)inputmodelr   )client
embeddingscreatenparraydata	embedding)r$   responses     r*   gerar_embeddingr8   t   sA     ''& (  H 8HM!$.///r,   c                    t          |           }i }t                                          D ]s\  }}t          j        |          }t          j        ||          t          j                            |          t          j                            |          z  z  }|||<   tt          ||j	                  }||         dk    rt          j	        |          S d S )Nkeyg333333?)r8   respostas_rapidas_embeddingsitemsr3   r4   dotlinalgnormmaxgetr   )r$   pergunta_vecsimilaridadesperguntaembemb_vecr)   melhors           r*   buscar_resposta_rapidarI   }   s    "5))LM5;;== & &#(3--f\7++ry~~l/K/Kbinn]dNeNe/ef"%hM$5666FVt## $V,,,4r,   c                 .   t          |           dk    r!| d         d         dz   | d         d         z   }n| d         d         }t          |          }i }t                                          D ]s\  }}t	          j        |          }t	          j        ||          t          j                            |          t          j                            |          z  z  }|||<   tt          ||j
                  }t          
                    |t                    S )N   content r:   )lenr8   system_embeddingsr=   r3   r4   r>   r?   r@   rA   rB   prompts_dictr   )	historico_mensagenspergunta_compostarC   rD   nomerF   rG   r)   rH   s	            r*   detectar_contextorV      s    
1$$/3I>DGZ[]G^_hGii/3I>"#455LM&,,.. " "	c(3--f\7++ry~~l/K/Kbinn]dNeNe/ef!dM$5666FFL111r,   c                     |d         d         }t          |          }|r|S t          |          }||d         g}t          j        j                            d|d          }|j        d         j        j        S )NrO   rM   zgpt-3.5-turbog333333?)r/   messagestemperaturer   )	rI   rV   r0   chatcompletionsr2   choicesmessagerM   )requestrS   user_mensagemresposta_prontasystem_prompt	mensagensr7   s          r*   responder_pergunta_termo_iarc      s    '+I6M,];;O %&9::M 3B 78I{&-- .  H A&..r,   ),openaijsonnumpyr3   osdjango.confr   django.contrib.auth.decoratorsr   collectionsr   respostas_rapidasr   r   resposta_coeficientesr	   fabiano_promptsr
   r   r   r   r   r   r   r   EMBEDDINGS_PATHEMBEDDINGS_RAPIDAS_PATHOpenAIOPENAI_API_KEYr0   keywords_maprR   openfloadrQ   r<   difflibr   r+   r8   rI   rV   rc    r,   r*   <module>rx      s         				             9 9 9 9 9 9 # # # # # # Q Q Q Q Q Q Q Q > > > > > >	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Qb  
x6	7	7	7 ! ! !
     
           /   B )I6 82**6  
T/ %a!	!% % % % % % % % % % % % % % % 
T
!"" 0a#,49Q<< 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $ # # # # #  20 0 0   2 2 2$ / / / / /s$   B//B36B3C""C&)C&