§
    è˜ºhu  ã                  ó®   — 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dS )z Question answering over a graph.é    )Úannotations)ÚAnyÚDictÚListÚOptional)Ú	KuzuGraph)ÚBaseLanguageModel)ÚBasePromptTemplate)ÚField)ÚCallbackManagerForChainRun)ÚChain)ÚCYPHER_QA_PROMPTÚKUZU_GENERATION_PROMPT©ÚLLMChainc                  óÂ   — 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<   e	d"d„¦   «         Z
e	d"d„¦   «         Zeeedœd#d„¦   «         Z	 d$d%d!„ZdS )&ÚKuzuQAChainué  Question-answering against a graph by generating Cypher statements for KÃ¹zu.

    *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   Úcypher_generation_chainÚqa_chainÚqueryÚstrÚ	input_keyÚresultÚ
output_keyÚreturnú	List[str]c                ó   — | j         gS )z7Return the input keys.

        :meta private:
        )r   )Úselfs    úf/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain/chains/graph_qa/kuzu.pyÚ
input_keyszKuzuQAChain.input_keys&   s   € ð ”ÐÐó    c                ó   — | j         g}|S )z8Return the output keys.

        :meta private:
        )r   )r    Ú_output_keyss     r!   Úoutput_keyszKuzuQAChain.output_keys.   s   € ð œÐ(ˆØÐr#   )Ú	qa_promptÚcypher_promptÚllmr	   r'   r
   r(   Úkwargsr   c               ó\   — t          ||¬¦  «        }t          ||¬¦  «        } | d||dœ|¤ŽS )zInitialize from LLM.)r)   Úprompt)r   r   © r   )Úclsr)   r'   r(   r*   r   r   s          r!   Úfrom_llmzKuzuQAChain.from_llm7   sW   € õ  ¨IÐ6Ñ6Ô6ˆÝ"*¨s¸=Ð"IÑ"IÔ"IÐàˆsð 
ØØ$;ð
ð 
ð ð
ð 
ð 	
r#   NÚinputsúDict[str, Any]Úrun_managerú$Optional[CallbackManagerForChainRun]úDict[str, str]c                ó`  — |pt          j        ¦   «         }|                     ¦   «         }|| j                 }| j                             || j        j        dœ|¬¦  «        }|                     dd| j	        ¬¦  «         |                     |dd| j	        ¬¦  «         | j         
                    |¦  «        }|                     dd| j	        ¬¦  «         |                     t          |¦  «        dd| j	        ¬¦  «         |                      ||d	œ|¬¦  «        }| j        || j        j                 iS )
zGGenerate Cypher statement, use it to look up in db and answer question.)ÚquestionÚschema)Ú	callbackszGenerated Cypher:ú
)Ú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    r0   r2   Ú_run_managerr8   r6   Úgenerated_cypherr>   r   s	            r!   Ú_callzKuzuQAChain._callJ   sQ  € ð #ÐSÕ&@Ô&QÑ&SÔ&SˆØ ×*Ò*Ñ,Ô,ˆ	Ø˜$œ.Ô)ˆàÔ7×;Ò;Ø!¨T¬ZÔ-BÐCÐCÈyð <ñ 
ô 
Ðð 	×ÒÐ0°dÀDÄLÐÑQÔQÐQØ×ÒØ G°¸t¼|ð 	ñ 	
ô 	
ð 	
ð ”*×"Ò"Ð#3Ñ4Ô4ˆà×Ò˜_°$ÀÄÐÑMÔMÐMØ×ÒÝ�‰LŒL ¨T¸4¼<ð 	ñ 	
ô 	
ð 	
ð —’Ø!¨gÐ6Ð6Øð ñ 
ô 
ˆð ” ¨¬Ô(@Ô!AÐBÐBr#   )r   r   )
r)   r	   r'   r
   r(   r
   r*   r   r   r   )N)r0   r1   r2   r3   r   r4   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r   r   Úpropertyr"   r&   Úclassmethodr   r   r/   rF   r-   r#   r!   r   r      s  € € € € € € ðð ð �u TÐ*Ñ*Ô*€EÐ*Ð*Ð*Ñ*Ø%Ð%Ð%Ñ%ØÐÐÑØ€IÐÐÐÑØ€JÐÐÐÑàð ð  ð  ñ „Xð ð ðð ð ñ „Xðð ð
 )9Ø,Bð
ð 
ð 
ð 
ð 
ñ „[ð
ð* =AðCð Cð Cð Cð Cð Cð Cr#   r   N)rJ   Ú
__future__r   Útypingr   r   r   r   Ú%langchain_community.graphs.kuzu_graphr   Úlangchain_core.language_modelsr	   Úlangchain_core.promptsr
   Úlangchain_core.pydantic_v1r   Úlangchain.callbacks.managerr   Úlangchain.chains.baser   Ú!langchain.chains.graph_qa.promptsr   r   Úlangchain.chains.llmr   r   r-   r#   r!   ú<module>rX      s  ðØ &Ð &Ø "Ð "Ð "Ð "Ð "Ð "à ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø <Ð <Ð <Ð <Ð <Ð <Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,à BÐ BÐ BÐ BÐ BÐ BØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø VÐ VÐ VÐ VÐ VÐ VÐ VÐ VØ )Ð )Ð )Ð )Ð )Ð )ðVCð VCð VCð VCð VC�%ñ VCô VCð VCð VCð VCr#   