HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langchain/chains/__pycache__/loading.cpython-310.pyc
o

���g�p�@s�dZddlmZddlZddlmZddlmZmZm	Z	ddl
Z
ddlmZddl
mZmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.m/Z/er�ddl0m1Z1ddl2m3Z3z
ddl4m5Z5m6Z6Wne7y�ddd �Z5dd!d"�Z6Ynwd#Z8d�d'd(�Z9d�d*d+�Z:d�d-d.�Z;d�d0d1�Z<d�d3d4�Z=d�d5d6�Z>d�d8d9�Z?d�d;d<�Z@d�d>d?�ZAd�d@dA�ZBd�dCdD�ZCd�dFdG�ZDd�dHdI�ZEd�dKdL�ZFd�dNdO�ZGd�dQdR�ZHd�dTdU�ZId�dWdX�ZJd�dZd[�ZKd�d]d^�ZLid_eK�d`e:�dae9�dbe>�dce?�dde@�deeL�dfeB�dgeD�dhe;�die<�dje=�dkeA�dleC�dmeE�dneF�doeI�eGeHeJdp��ZMedqdrdsdt�d�dvdw��ZNedqdrdsdt�d�dzd{��ZOd�d}d~�ZPdS)�z!Functionality for loading chains.�)�annotationsN)�Path)�
TYPE_CHECKING�Any�Union)�
deprecated)�_load_output_parser�load_prompt�load_prompt_from_config)�ReduceDocumentsChain)�APIChain)�Chain)�MapReduceDocumentsChain)�MapRerankDocumentsChain)�RefineDocumentsChain)�StuffDocumentsChain)�HypotheticalDocumentEmbedder)�LLMChain)�LLMCheckerChain)�LLMMathChain)�QAWithSourcesChain)�RetrievalQAWithSourcesChain)�VectorDBQAWithSourcesChain)�RetrievalQA�
VectorDBQA��GraphCypherQAChain��LLMRequestsChain)�load_llm�load_llm_from_config�argsr�kwargs�return�NonecO�td��)Nz�To use this load_llm functionality you must install the langchain_community package. You can install it with `pip install langchain_community`��ImportError�r!r"�r)�C/usr/local/lib/python3.10/dist-packages/langchain/chains/loading.pyr*s�rcOr%)Nz�To use this load_llm_from_config functionality you must install the langchain_community package. You can install it with `pip install langchain_community`r&r(r)r)r*r 1s�r zHhttps://raw.githubusercontent.com/hwchase17/langchain-hub/master/chains/�config�dictrcKs�d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��d|vr4|�d�}t|�}nd|vr@t|�d��}ntd��t|�td	||d�|��S)
z Load LLM chain from config dict.�llm�llm_path�+One of `llm` or `llm_path` must be present.�prompt�prompt_pathz1One of `prompt` or `prompt_path` must be present.�r-r0Nr))�popr r�
ValueErrorr
r	rr)r+r"�
llm_configr-�
prompt_configr0r)r)r*�_load_llm_chain>s


r7rcKs|d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��d|vr0|�d�}ntd��td||d�|��S)	z;Load hypothetical document embedder chain from config dict.�	llm_chain�llm_chain_path�7One of `llm_chain` or `llm_chain_path` must be present.�
embeddingsz`embeddings` must be present.)r8�base_embeddingsNr))r3�load_chain_from_config�
load_chainr4r)r+r"�llm_chain_configr8r;r)r)r*�_load_hyde_chainTs
��r@rcKs�d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��t|t�s2td|����d|vr@|�d�}t|�}nd|vrLt|�d��}ntd��td	||d�|��S)
Nr8r9r:�Expected LLMChain, got �document_prompt�document_prompt_pathzCOne of `document_prompt` or `document_prompt_path` must be present.)r8rBr))	r3r=r>r4�
isinstancerr
r	r)r+r"r?r8r6rBr)r)r*�_load_stuff_documents_chainhs*



���rErcKs�d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��t|t�s2td|����d|vrBt|�d�fi|��}nd|vrRt|�d�fi|��}nt|fi|��}td||d�|��S)	Nr8r9r:rA�reduce_documents_chain�reduce_documents_chain_path)r8rFr))r3r=r>r4rDr�_load_reduce_documents_chainr)r+r"r?r8rFr)r)r*� _load_map_reduce_documents_chain�s6

������rIrcKsNd}d}d|vr|�d�}t|fi|��}n6d|vr(|�d�}t|fi|��}n$d|vr8t|�d�fi|��}nd|vrHt|�d�fi|��}ntd��d|vre|�d�}|dur\d}nAt|fi|��}n8d|vrut|�d�fi|��}n(d|vr�|�d�}|dur�d}nt|fi|��}nd	|vr�t|�d	�fi|��}td||d
�|��S)N�combine_documents_chain�combine_document_chain�combine_documents_chain_path�combine_document_chain_path�SOne of `combine_documents_chain` or `combine_documents_chain_path` must be present.�collapse_documents_chain�collapse_documents_chain_path�collapse_document_chain�collapse_document_chain_path)rJrOr))r3r=r>r4r)r+r"rJrO�combine_document_chain_config�collapse_document_chain_configr)r)r*rH�s�
��
�������
����
������rHc	Ks�ddlm}d}d|vr|�d�}t|fi|��}n6d|vr*t|�d�fi|��}n&d|vr<|�d�}t|fi|��}nd|vrLt|�d�fi|��}ntd��d|vr^|�d�}t|�}nd	|vrit	|�d	��}|ru|d||d
�|��S|d||d�|��S)
Nr)�LLMBashChainr8r9r-r.r:r0r1�r8r0r2r))
�$langchain_experimental.llm_bash.baserUr3r=r>r rr4r
r	)	r+r"rUr8r?r5r-r6r0r)r)r*�_load_llm_bash_chain�s*



rXrcKs.d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��d|vr4|�d�}t|�}nd|vr?t|�d��}d|vrM|�d�}t|�}nd|vrXt|�d��}d|vrf|�d�}t|�}	nd	|vrqt|�d	��}	d
|vr|�d
�}
t|
�}nd|vr�t|�d��}td
||||	|d�|��S)Nr-r.r/�create_draft_answer_prompt�create_draft_answer_prompt_path�list_assertions_prompt�list_assertions_prompt_path�check_assertions_prompt�check_assertions_prompt_path�revised_answer_prompt�revised_answer_prompt_path)r-rYr[r]r_r))r3r rr4r
r	r)r+r"r5r-�!create_draft_answer_prompt_configrY�list_assertions_prompt_configr[�check_assertions_prompt_configr]�revised_answer_prompt_configr_r)r)r*�_load_llm_checker_chain�sV

��


��

��rercKs�d}d|vr|�d�}t|fi|��}n6d|vr$t|�d�fi|��}n&d|vr6|�d�}t|fi|��}nd|vrFt|�d�fi|��}ntd��d|vrX|�d�}t|�}nd|vrct|�d��}|rotd
||d�|��Std
||d	�|��S)Nr8r9r-r.r:r0r1rVr2r))	r3r=r>r rr4r
r	r)r+r"r8r?r5r-r6r0r)r)r*�_load_llm_math_chain+s(



rfrcK�^d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��tdd|i|��S)Nr8r9r:r))r3r=r>r4r)r+r"r?r8r)r)r*� _load_map_rerank_documents_chainGs
rhcKsjddlm}d|vr|�d�}t|fi|��}nd|vr(t|�d�fi|��}ntd��|dd|i|��S)Nr)�PALChainr8r9r:r))� langchain_experimental.pal_chainrir3r=r>r4)r+r"rir?r8r)r)r*�_load_pal_chainTs
rkrcKs�d|vr|�d�}t|fi|��}nd|vr"t|�d�fi|��}ntd��d|vr8|�d�}t|fi|��}nd|vrHt|�d�fi|��}ntd��d|vrZ|�d�}t|�}nd|vret|�d��}td
|||d	�|��S)N�initial_llm_chain�initial_llm_chain_pathzGOne of `initial_llm_chain` or `initial_llm_chain_path` must be present.�refine_llm_chain�refine_llm_chain_pathzEOne of `refine_llm_chain` or `refine_llm_chain_path` must be present.rBrC)rlrnrBr))r3r=r>r4r
r	r)r+r"�initial_llm_chain_configrl�refine_llm_chain_configrnr6rBr)r)r*�_load_refine_documents_chainas8
�
�

��rrrcKrg)NrJrLrNr))r3r=r>r4r)r+r"�combine_documents_chain_configrJr)r)r*�_load_qa_with_sources_chain�s"
�����rtc
Ks�ddlm}d|vr|�d�}ntd��d|vr/|�d�}t|fi|��}|d||d�|��Sd|vrA|�d�}t|fi|��}nd|vrQt|�d�fi|��}ntd	��d
|vrc|�d
�}t|�}	nd}	|j||fd
|	i|��S)Nr)�SQLDatabaseChain�databasez`database` must be present.r8)r8rvr-r.r/r0r))	�langchain_experimental.sqlrur3r4r=r rr
�from_llm)
r+r"rurvr?�chainr5r-r6r0r)r)r*�_load_sql_database_chain�s&



rzrcK�|d|vr
|�d�}ntd��d|vr |�d�}t|fi|��}nd|vr0t|�d�fi|��}ntd��td||d�|��S�N�vectorstorez`vectorstore` must be present.rJrLrN)rJr}r))r3r4r=r>r�r+r"r}rsrJr)r)r*�%_load_vector_db_qa_with_sources_chain��2
�������rrcKr{�N�	retrieverz`retriever` must be present.rJrLrN)rJr�r))r3r4r=r>r�r+r"r�rsrJr)r)r*�_load_retrieval_qa��2
�������r�rcKr{r�)r3r4r=r>rr�r)r)r*�%_load_retrieval_qa_with_sources_chain�r�r�rcKr{r|)r3r4r=r>rr~r)r)r*�_load_vector_db_qar�r�rcKs�d|vr
|�d�}ntd��d|vr |�d�}t|fi|��}ntd��d|vr6|�d�}t|fi|��}ntd��zddlm}WntyMtd	��w|d|||d
�|��S)N�graphz`graph` must be present.�cypher_generation_chainz*`cypher_generation_chain` must be present.�qa_chainz`qa_chain` must be present.rrz�To use this GraphCypherQAChain functionality you must install the langchain_community package. You can install it with `pip install langchain_community`)r�r�r�r))r3r4r=�*langchain_community.chains.graph_qa.cypherrr')r+r"r��cypher_generation_chain_configr��qa_chain_configr�rr)r)r*�_load_graph_cypher_chains:
��
����r�rcKs�d|vr|�d�}t|fi|��}nd|vrt|�d��}ntd��d|vr4|�d�}t|fi|��}nd|vrDt|�d�fi|��}ntd��d|vrR|�d�}ntd��td
|||d	�|��S)N�api_request_chain�api_request_chain_pathzGOne of `api_request_chain` or `api_request_chain_path` must be present.�api_answer_chain�api_answer_chain_pathzEOne of `api_answer_chain` or `api_answer_chain_path` must be present.�requests_wrapperz#`requests_wrapper` must be present.)r�r�r�r))r3r=r>r4r)r+r"�api_request_chain_configr��api_answer_chain_configr�r�r)r)r*�_load_api_chain<s4
�
���r�rcKs�zddlm}Wntytd��wd|vr&|�d�}t|fi|��}nd|vr6t|�d�fi|��}ntd��d|vrM|�d�}|d	||d�|��S|d	d|i|��S)
Nrrz�To use this LLMRequestsChain functionality you must install the langchain package. You can install it with `pip install langchain`r8r9r:r�)r8r�r))�langchain.chains.llm_requestsrr'r3r=r>r4)r+r"rr?r8r�r)r)r*�_load_llm_requests_chain[s*��

��r��	api_chain�
hyde_chainr8�llm_bash_chain�llm_checker_chain�llm_math_chain�llm_requests_chain�	pal_chain�qa_with_sources_chain�stuff_documents_chain�map_reduce_documents_chainrF�map_rerank_documents_chain�refine_documents_chain�sql_database_chain�vector_db_qa_with_sources_chain�vector_db_qa)�retrieval_qa�retrieval_qa_with_sources_chain�graph_cypher_chainz0.2.13z�This function is deprecated and will be removed in langchain 1.0. At that point chains must be imported from their respective modules.z1.0)�since�message�removalr
cKsJd|vrtd��|�d�}|tvrtd|�d���t|}||fi|��S)zLoad chain from Config Dict.�_typez#Must specify a chain Type in configzLoading z chain not supported)r4r3�type_to_loader_dict)r+r"�config_type�chain_loaderr)r)r*r=�s

r=�path�Union[str, Path]cKs,t|t�r|�d�rtd��t|fi|��S)zAUnified method for loading a chain from LangChainHub or local fs.zlc://z�Loading from the deprecated github-based Hub is no longer supported. Please use the new LangChain Hub at https://smith.langchain.com/hub instead.)rD�str�
startswith�RuntimeError�_load_chain_from_file)r�r"r)r)r*r>�s

�r>�filecKs�t|t�r
t|�}n|}|jdkr+t|��
}t�|�}Wd�n1s%wYn%|j�d�rLt|d��
}t�	|�}Wd�n1sFwYnt
d��d|vr[|�d�|d<d|vrf|�d�|d<t|fi|��S)zLoad chain from file.z.jsonN)z.yamlz.yml�rzFile type must be json or yaml�verbose�memory)
rDr�r�suffix�open�json�load�endswith�yaml�	safe_loadr4r3r=)r�r"�	file_path�fr+r)r)r*r��s&



����r�)r!rr"rr#r$)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r)r+r,r"rr#r
)r�r�r"rr#r
)r�r�r"rr#r
)Q�__doc__�
__future__rr��pathlibr�typingrrrr��langchain_core._apir�langchain_core.prompts.loadingrr	r
�langchain.chainsr�langchain.chains.api.baser�langchain.chains.baser
�-langchain.chains.combine_documents.map_reducer�-langchain.chains.combine_documents.map_rerankr�)langchain.chains.combine_documents.refiner�(langchain.chains.combine_documents.stuffr�langchain.chains.hyde.baser�langchain.chains.llmr�!langchain.chains.llm_checker.baser�langchain.chains.llm_math.baser�%langchain.chains.qa_with_sources.baser�*langchain.chains.qa_with_sources.retrievalr�*langchain.chains.qa_with_sources.vector_dbr�"langchain.chains.retrieval_qa.baserrr�rr�r� langchain_community.llms.loadingrr r'�URL_BASEr7r@rErIrHrXrerfrhrkrrrtrzrr�r�r�r�r�r�r�r=r>r�r)r)r)r*�<module>s�
�




 
<

.



 






"
��������	�
���
�������
�