
    @hz
                    j    S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	J
r
  S SKJr          S	S jrg)
    )annotations)LanguageModelLike)StrOutputParser)BasePromptTemplate)RetrieverLikeRetrieverOutputLike)RunnableBranchc                    SUR                   ;  a  SUR                    3n[        U5      e[        S S U-  4X -  [        5       -  U-  5      R	                  SS9nU$ )a6  Create a chain that takes conversation history and returns documents.

If there is no `chat_history`, then the `input` is just passed directly to the
retriever. If there is `chat_history`, then the prompt and LLM will be used
to generate a search query. That search query is then passed to the retriever.

Args:
    llm: Language model to use for generating a search term given chat history
    retriever: RetrieverLike object that takes a string as input and outputs
        a list of Documents.
    prompt: The prompt used to generate the search query for the retriever.

Returns:
    An LCEL Runnable. The runnable input must take in `input`, and if there
    is chat history should take it in the form of `chat_history`.
    The Runnable output is a list of Documents

Example:
    .. code-block:: python

        # pip install -U langchain langchain-community

        from langchain_community.chat_models import ChatOpenAI
        from langchain.chains import create_history_aware_retriever
        from langchain import hub

        rephrase_prompt = hub.pull("langchain-ai/chat-langchain-rephrase")
        llm = ChatOpenAI()
        retriever = ...
        chat_retriever_chain = create_history_aware_retriever(
            llm, retriever, rephrase_prompt
        )

        chain.invoke({"input": "...", "chat_history": })

inputz2Expected `input` to be a prompt variable, but got c                0    U R                  SS5      (       + $ )Nchat_historyF)getxs    `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/chains/history_aware_retriever.py<lambda>0create_history_aware_retriever.<locals>.<lambda>=   s    !%%66    c                    U S   $ )Nr    r   s    r   r   r   ?   s    qzr   chat_retriever_chain)run_name)input_variables
ValueErrorr	   r   with_config)llm	retrieverpromptmsgretrieve_documentss        r   create_history_aware_retrieverr!   
   s    R f,,,--.0 	 o.< 7!Y.		
 	((94	/ k1k2  r   N)r   r   r   r   r   r   returnr   )
__future__r   langchain_core.language_modelsr   langchain_core.output_parsersr   langchain_core.promptsr   langchain_core.retrieversr   r   langchain_core.runnablesr	   r!   r   r   r   <module>r)      s@    " < 9 5 H 3:	:: : 	:r   