§
    è˜ºho  ã                  ó®   — 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)ÚNebulaGraph)ÚBaseLanguageModel)ÚBasePromptTemplate)ÚField)ÚCallbackManagerForChainRun)ÚChain)ÚCYPHER_QA_PROMPTÚNGQL_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 )&ÚNebulaGraphQAChainaç  Chain for question-answering against a graph by generating nGQL 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   Úngql_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    úm/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain/chains/graph_qa/nebulagraph.pyÚ
input_keyszNebulaGraphQAChain.input_keys&   s   € ð ”ÐÐó    c                ó   — | j         g}|S )z8Return the output keys.

        :meta private:
        )r   )r    Ú_output_keyss     r!   Úoutput_keyszNebulaGraphQAChain.output_keys.   s   € ð œÐ(ˆØÐr#   )Ú	qa_promptÚngql_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NebulaGraphQAChain.from_llm7   sW   € õ  ¨IÐ6Ñ6Ô6ˆÝ (¨S¸Ð EÑ EÔ EÐàˆsð 
ØØ"7ð
ð 
ð ð
ð 
ð 	
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 )
zEGenerate nGQL statement, use it to look up in db and answer question.)ÚquestionÚschema)Ú	callbackszGenerated nGQL:ú
)Ú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_ngqlr>   r   s	            r!   Ú_callzNebulaGraphQAChain._callJ   sO  € ð #ÐSÕ&@Ô&QÑ&SÔ&SˆØ ×*Ò*Ñ,Ô,ˆ	Ø˜$œ.Ô)ˆàÔ3×7Ò7Ø!¨T¬ZÔ-BÐCÐCÈyð 8ñ 
ô 
ˆð 	×ÒÐ.°DÀ$Ä,ÐÑOÔOÐOØ×ÒØ '¨t¸T¼\ð 	ñ 	
ô 	
ð 	
ð ”*×"Ò" >Ñ2Ô2ˆà×Ò˜_°$ÀÄÐÑ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  € € € € € € ðð ð ˜ tÐ,Ñ,Ô,€EÐ,Ð,Ð,Ñ,Ø#Ð#Ð#Ñ#ØÐÐÑØ€IÐÐÐÑØ€JÐÐÐÑàð ð  ð  ñ „Xð ð ðð ð ñ „Xðð ð
 )9Ø*@ð
ð 
ð 
ð 
ð 
ñ „[ð
ð* =AðCð Cð Cð Cð Cð Cð Cr#   r   N)rJ   Ú
__future__r   Útypingr   r   r   r   Ú'langchain_community.graphs.nebula_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#   