Ë
    µŒj(  ã                  ó¦   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlm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  G d„ de	«      Zy)z Question answering over a graph.é    )Úannotations)ÚAnyÚDictÚListÚOptional)ÚChain©ÚLLMChain)ÚCallbackManagerForChainRun)ÚBaseLanguageModel)ÚBasePromptTemplate)ÚField)ÚCYPHER_QA_PROMPTÚGREMLIN_GENERATION_PROMPT)Ú	HugeGraphc                  óè   ‡ — e Zd ZU dZ ed¬«      Zded<   ded<   ded<   d	Zd
ed<   dZd
ed<   dZ	ded<   	 dˆ fd„Z
edd„«       Zedd„«       Zeeedœ	 	 	 	 	 	 	 	 	 dd„«       Z	 d	 	 	 	 	 dd„Zˆ xZS )ÚHugeGraphQAChainaê  Chain for question-answering against a graph by generating gremlin statements.

    *Security note*: Make sure that the database connection uses credentials
        that are narrowly-scoped to only include necessary permissions.
        Failure to do so may result in data corruption or loss, since the calling
        code may attempt commands that would result in deletion, mutation
        of data if appropriately prompted or reading sensitive data if such
        data is present in the database.
        The best way to guard against such negative outcomes is to (as appropriate)
        limit the permissions granted to the credentials used with this tool.

        See https://python.langchain.com/docs/security for more information.
    T)Úexcluder   Úgraphr
   Úgremlin_generation_chainÚqa_chainÚqueryÚstrÚ	input_keyÚresultÚ
output_keyFÚboolÚallow_dangerous_requestsc                óV   •— t        ‰| �  di |¤Ž | j                  durt        d«      ‚y)zInitialize the chain.Ta  In order to use this chain, you must acknowledge that it can make dangerous requests by setting `allow_dangerous_requests` to `True`.You must narrowly scope the permissions of the database connection to only include necessary permissions. Failure to do so may result in data corruption or loss or reading sensitive data if such data is present in the database.Only use this chain if you understand the risks and have taken the necessary precautions. See https://python.langchain.com/docs/security for more information.N© )ÚsuperÚ__init__r   Ú
ValueError)ÚselfÚkwargsÚ	__class__s     €úw/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/chains/graph_qa/hugegraph.pyr"   zHugeGraphQAChain.__init__9   s9   ø€ ä‰ÑÑ"˜6Ò"Ø×(Ñ(°Ñ4ÜðWó
ð 
ð 5ó    c                ó   — | j                   gS )z,Input keys.

        :meta private:
        )r   )r$   s    r'   Ú
input_keyszHugeGraphQAChain.input_keysI   s   € ð —‘ÐÐr(   c                ó    — | j                   g}|S )z-Output keys.

        :meta private:
        )r   )r$   Ú_output_keyss     r'   Úoutput_keyszHugeGraphQAChain.output_keysQ   s   € ð Ÿ™Ð(ˆØÐr(   )Ú	qa_promptÚgremlin_promptc               óL   — t        ||¬«      }t        ||¬«      } | d||dœ|¤ŽS )zInitialize from LLM.)ÚllmÚprompt)r   r   r    r	   )Úclsr1   r.   r/   r%   r   r   s          r'   Úfrom_llmzHugeGraphQAChain.from_llmZ   s?   € ô  ¨IÔ6ˆÜ#+°¸NÔ#KÐ áð 
ØØ%=ñ
ð ñ
ð 	
r(   c                óŠ  — |xs t        j                  «       }|j                  «       }|| j                     }| j                  j                  || j                  j                  dœ|¬«      }|j                  dd| j                  ¬«       |j                  |dd| j                  ¬«       | j                  j                  |«      }|j                  dd| j                  ¬«       |j                  t        |«      dd| j                  ¬«       | j                  ||d	œ|¬«      }| j                  || j                  j                     iS )
zHGenerate gremlin statement, use it to look up in db and answer question.)ÚquestionÚschema)Ú	callbackszGenerated gremlin:Ú
)ÚendÚverboseÚgreen)Úcolorr:   r;   zFull Context:)r6   Úcontext)r   Úget_noop_managerÚ	get_childr   r   Úrunr   Ú
get_schemaÚon_textr;   r   r   r   r   )	r$   ÚinputsÚrun_managerÚ_run_managerr8   r6   Úgenerated_gremlinr>   r   s	            r'   Ú_callzHugeGraphQAChain._callm   s4  € ð #ÒSÔ&@×&QÑ&QÓ&SˆØ ×*Ñ*Ó,ˆ	Ø˜$Ÿ.™.Ñ)ˆà ×9Ñ9×=Ñ=Ø!¨T¯Z©Z×-BÑ-BÑCÈyð >ó 
Ðð 	×ÑÐ1°tÀTÇ\Á\ÐÔRØ×ÑØ W°$ÀÇÁð 	ô 	
ð —*‘*×"Ñ"Ð#4Ó5ˆà×Ñ˜_°$ÀÇÁÐÔMØ×ÑÜ�‹L ¨T¸4¿<¹<ð 	ô 	
ð —‘Ø!¨gÑ6Øð ó 
ˆð —‘ ¨¯©×(@Ñ(@Ñ!AÐBÐBr(   )r%   r   ÚreturnÚNone)rI   z	List[str])
r1   r   r.   r   r/   r   r%   r   rI   r   )N)rD   zDict[str, Any]rE   z$Optional[CallbackManagerForChainRun]rI   zDict[str, str])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r   r   r   r"   Úpropertyr*   r-   Úclassmethodr   r   r4   rH   Ú__classcell__)r&   s   @r'   r   r      sí   ø… ññ  TÔ*€Eˆ9Ó*Ø&Ó&ØÓØ€IˆsÓØ€J�Óà%*Ð˜dÓ*ðõð  ò ó ð ð òó ðð ð
 )9Ø-Fñ
àð
ð &ð	
ð
 +ð
ð ð
ð 
ò
ó ð
ð* =AðCàðCð :ðCð 
÷	Cr(   r   N)rN   Ú
__future__r   Útypingr   r   r   r   Úlangchain.chains.baser   Úlangchain.chains.llmr
   Úlangchain_core.callbacksr   Úlangchain_core.language_modelsr   Úlangchain_core.promptsr   Úpydanticr   Ú+langchain_community.chains.graph_qa.promptsr   r   Ú$langchain_community.graphs.hugegraphr   r   r    r(   r'   Ú<module>r]      s=   ðÙ &å "ç ,Ó ,å 'Ý )Ý ?Ý <Ý 5Ý ÷õ ;ôuC�uõ uCr(   