__init__.py — langchain Source File
Architecture documentation for __init__.py, a python file in the langchain codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 96ba21b7_1471_b17f_8407_f3fe3cd4752b["__init__.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 96ba21b7_1471_b17f_8407_f3fe3cd4752b --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 7e64d143_ea36_1c73_4897_1d0ae1757b5b["langchain_core.callbacks.base"] 96ba21b7_1471_b17f_8407_f3fe3cd4752b --> 7e64d143_ea36_1c73_4897_1d0ae1757b5b a5d3b8a8_801d_777f_b85d_70e1e80fd759["langchain_community.callbacks"] 96ba21b7_1471_b17f_8407_f3fe3cd4752b --> a5d3b8a8_801d_777f_b85d_70e1e80fd759 0e486ead_1fea_c512_c199_a6f0f07c8422["streamlit.delta_generator"] 96ba21b7_1471_b17f_8407_f3fe3cd4752b --> 0e486ead_1fea_c512_c199_a6f0f07c8422 b629afa7_5c59_5ca1_51a3_b88be5a8c0d4["streamlit.external.langchain"] 96ba21b7_1471_b17f_8407_f3fe3cd4752b --> b629afa7_5c59_5ca1_51a3_b88be5a8c0d4 a80d7117_dc2a_8af7_6a1c_2f9c5d7f2efa["langchain_community.callbacks.streamlit.streamlit_callback_handler"] 96ba21b7_1471_b17f_8407_f3fe3cd4752b --> a80d7117_dc2a_8af7_6a1c_2f9c5d7f2efa style 96ba21b7_1471_b17f_8407_f3fe3cd4752b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
from typing import TYPE_CHECKING
from langchain_core.callbacks.base import BaseCallbackHandler
if TYPE_CHECKING:
from langchain_community.callbacks import LLMThoughtLabeler
from streamlit.delta_generator import DeltaGenerator
def StreamlitCallbackHandler( # noqa: N802
parent_container: DeltaGenerator,
*,
max_thought_containers: int = 4,
expand_new_thoughts: bool = True,
collapse_completed_thoughts: bool = True,
thought_labeler: LLMThoughtLabeler | None = None,
) -> BaseCallbackHandler:
"""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.
expand_new_thoughts
Each LLM "thought" gets its own `st.expander`. This param controls whether that
expander is expanded by default.
collapse_completed_thoughts
If `True`, LLM thought expanders will be collapsed when completed.
thought_labeler
An optional custom LLMThoughtLabeler instance. If unspecified, the handler
will use the default thought labeling logic.
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.
"""
# If we're using a version of Streamlit that implements StreamlitCallbackHandler,
# delegate to it instead of using our built-in handler. The official handler is
# guaranteed to support the same set of kwargs.
try:
from streamlit.external.langchain import StreamlitCallbackHandler
# This is the official handler, so we can just return it.
return StreamlitCallbackHandler(
parent_container,
max_thought_containers=max_thought_containers,
expand_new_thoughts=expand_new_thoughts,
collapse_completed_thoughts=collapse_completed_thoughts,
thought_labeler=thought_labeler,
)
except ImportError:
try:
from langchain_community.callbacks.streamlit.streamlit_callback_handler import ( # noqa: E501
StreamlitCallbackHandler as _InternalStreamlitCallbackHandler,
)
except ImportError as e:
msg = (
"To use the StreamlitCallbackHandler, please install "
"langchain-community with `pip install langchain-community`."
)
raise ImportError(msg) from e
return _InternalStreamlitCallbackHandler(
parent_container,
max_thought_containers=max_thought_containers,
expand_new_thoughts=expand_new_thoughts,
collapse_completed_thoughts=collapse_completed_thoughts,
thought_labeler=thought_labeler,
)
Domain
Subdomains
Dependencies
- langchain_community.callbacks
- langchain_community.callbacks.streamlit.streamlit_callback_handler
- langchain_core.callbacks.base
- streamlit.delta_generator
- streamlit.external.langchain
- typing
Source
Frequently Asked Questions
What does __init__.py do?
__init__.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in __init__.py?
__init__.py defines 2 function(s): StreamlitCallbackHandler, langchain_community.
What does __init__.py depend on?
__init__.py imports 6 module(s): langchain_community.callbacks, langchain_community.callbacks.streamlit.streamlit_callback_handler, langchain_core.callbacks.base, streamlit.delta_generator, streamlit.external.langchain, typing.
Where is __init__.py in the architecture?
__init__.py is located at libs/langchain/langchain_classic/callbacks/streamlit/__init__.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/callbacks/streamlit).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free