a
    agf
                     @  sd   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 ddd	d
dddZdS )    )annotations)LanguageModelLike)StrOutputParser)BasePromptTemplate)RetrieverLikeRetrieverOutputLike)RunnableBranchr   r   r   r   )llm	retrieverpromptreturnc                 C  sN   d|j vrtd|j  tdd dd |B f|| B t B |B jdd}|S )a  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                 S  s   |  dd S )NZchat_historyF)getx r   v/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain/chains/history_aware_retriever.py<lambda><       z0create_history_aware_retriever.<locals>.<lambda>c                 S  s   | d S )Nr   r   r   r   r   r   r   >   r   Zchat_retriever_chain)Zrun_name)Zinput_variables
ValueErrorr   r   Zwith_config)r	   r
   r   Zretrieve_documentsr   r   r   create_history_aware_retriever
   s    )

	
r   N)
__future__r   Zlangchain_core.language_modelsr   Zlangchain_core.output_parsersr   Zlangchain_core.promptsr   Zlangchain_core.retrieversr   r   Zlangchain_core.runnablesr   r   r   r   r   r   <module>   s   