
    3fi	                     v    d Z ddlmZ ddl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  G d	 d
e      Zy).Question-answering with sources over an index.    )Any)AsyncCallbackManagerForChainRunCallbackManagerForChainRun)Document)BaseRetriever)Field)StuffDocumentsChain)BaseQAWithSourcesChainc                       e Zd ZU dZ ed      Zeed<   	 dZe	ed<   	 dZ
eed<   	 d	ee   d
ee   fdZdeeef   ded
ee   fdZdeeef   ded
ee   fdZed
efd       Zy)RetrievalQAWithSourcesChainr   T)exclude	retrieverFreduce_k_below_max_tokensi/  max_tokens_limitdocsreturnc                 d   t        |      }| j                  rt        | j                  t              rv|D cg c]1  }| j                  j
                  j                  |j                        3 }}t        |d |       }|| j                  kD  r|dz  }|||   z  }|| j                  kD  r|d | S c c}w )N   )
lenr   
isinstancecombine_documents_chainr
   	llm_chain_get_num_tokenspage_contentsumr   )selfr   num_docsdoctokenstoken_counts         p/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/chains/qa_with_sources/retrieval.py_reduce_tokens_below_limitz6RetrievalQAWithSourcesChain._reduce_tokens_below_limit   s    t9))j((/
   ,,66FFsGWGWXF  fYh/0K 5 55Avh//  5 55 IXs   6B-inputsrun_managerc                    || j                      }| j                  j                  |d|j                         i      }| j	                  |      S N	callbacks)config)question_keyr   invoke	get_childr#   r   r$   r%   questionr   s        r"   	_get_docsz%RetrievalQAWithSourcesChain._get_docs.   sT     $++,~~$$!6!6!89 % 
 ..t44    c                   K   || j                      }| j                  j                  |d|j                         i       d {   }| j	                  |      S 7 wr'   )r*   r   ainvoker,   r#   r-   s        r"   
_aget_docsz&RetrievalQAWithSourcesChain._aget_docs;   sb      $++,^^++!6!6!89 , 
 
 ..t44	
s   A AAAc                      y)zReturn the chain type.retrieval_qa_with_sources_chain )r   s    r"   _chain_typez'RetrievalQAWithSourcesChain._chain_typeH   s     1r0   N)__name__
__module____qualname____doc__r	   r   r   __annotations__r   boolr   intlistr   r#   dictstrr   r   r/   r   r3   propertyr7   r6   r0   r"   r   r      s    8$T2I}2&+t+Q c XtH~ $x. $5S#X5 0	5
 
h55S#X5 5	5
 
h5 1S 1 1r0   r   N)r;   typingr   langchain_core.callbacksr   r   langchain_core.documentsr   langchain_core.retrieversr   pydanticr	   0langchain_classic.chains.combine_documents.stuffr
   -langchain_classic.chains.qa_with_sources.baser   r   r6   r0   r"   <module>rJ      s.    4  . 3  P P:1"8 :1r0   