o
    JjgO                     @  s^   d dl mZ d dlmZmZ d dlmZ er"d dlmZ d dl	m
Z
 ddddd	dddZdS )    )annotations)TYPE_CHECKINGOptional)BaseCallbackHandler)LLMThoughtLabeler)DeltaGenerator   TNmax_thought_containersexpand_new_thoughtscollapse_completed_thoughtsthought_labelerparent_containerr   r
   intr   boolr   r   Optional[LLMThoughtLabeler]returnr   c                C  sn   zddl m} || ||||dW S  ty6   zddlm} W n ty*   tdw || ||||d Y S w )ab  Callback Handler that writes to a Streamlit app.

    This CallbackHandler is geared towards
    use with a LangChain Agent; it displays the Agent's LLM and tool-usage "thoughts"
    inside a series of Streamlit expanders.

    Parameters
    ----------
    parent_container
        The `st.container` that will contain all the Streamlit elements that the
        Handler creates.
    max_thought_containers
        The max number of completed LLM thought containers to show at once. When this
        threshold is reached, a new thought will cause the oldest thoughts to be
        collapsed into a "History" expander. Defaults to 4.
    expand_new_thoughts
        Each LLM "thought" gets its own `st.expander`. This param controls whether that
        expander is expanded by default. Defaults to True.
    collapse_completed_thoughts
        If True, LLM thought expanders will be collapsed when completed.
        Defaults to True.
    thought_labeler
        An optional custom LLMThoughtLabeler instance. If unspecified, the handler
        will use the default thought labeling logic. Defaults to None.

    Returns
    -------
    A new StreamlitCallbackHandler instance.

    Note that this is an "auto-updating" API: if the installed version of Streamlit
    has a more recent StreamlitCallbackHandler implementation, an instance of that class
    will be used.

    r   )StreamlitCallbackHandlerr	   zoTo use the StreamlitCallbackHandler, please install langchain-community with `pip install langchain-community`.)streamlit.external.langchainr   ImportErrorBlangchain_community.callbacks.streamlit.streamlit_callback_handler)r   r
   r   r   r   r   !_InternalStreamlitCallbackHandler r   ^/var/www/html/zoom/venv/lib/python3.10/site-packages/langchain/callbacks/streamlit/__init__.pyr      s2   -
r   )r   r   r
   r   r   r   r   r   r   r   r   r   )
__future__r   typingr   r   langchain_core.callbacks.baser   langchain_community.callbacksr   streamlit.delta_generatorr   r   r   r   r   r   <module>   s    