id
stringlengths
14
15
text
stringlengths
44
2.47k
source
stringlengths
61
181
6dbd5bb10488-1
Run on retriever error. on_retriever_start(serialized, query, *, run_id) Run on retriever start. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id, tags]) Run on arbitrary text. on_tool_end(output, *, run_id[, ...]) Run when tool ends running. on_tool_error(error, *, run_id[, ...]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__() → None[source]¶ async aiter() → AsyncIterator[str][source]¶ async on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run on agent action. async on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run on agent end. async on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run when chain ends running. async on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run when chain errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_aiter.AsyncIteratorCallbackHandler.html
6dbd5bb10488-2
Run when chain errors. async on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None¶ Run when chain starts running. async on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. async on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends running. async on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. async on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run on new LLM token. Only available when streaming is enabled. async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts running. async on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run on retriever end. async on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run on retriever error.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_aiter.AsyncIteratorCallbackHandler.html
6dbd5bb10488-3
Run on retriever error. async on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None¶ Run on retriever start. async on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. async on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run on arbitrary text. async on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run when tool ends running. async on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶ Run when tool errors. async on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None¶ Run when tool starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_aiter.AsyncIteratorCallbackHandler.html
7328c4053cbb-0
langchain.callbacks.utils.import_spacy¶ langchain.callbacks.utils.import_spacy() → Any[source]¶ Import the spacy python package and raise an error if it is not installed.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.utils.import_spacy.html
66058a758b4f-0
langchain.callbacks.manager.CallbackManagerForChainRun¶ class langchain.callbacks.manager.CallbackManagerForChainRun(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Callback manager for chain run. Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Methods __init__(*, run_id, handlers, ...[, ...]) Initialize the run manager. get_child([tag]) Get a child callback manager. get_noop_manager() Return a manager that doesn't perform any operations. on_agent_action(action, **kwargs) Run when agent action is received. on_agent_finish(finish, **kwargs) Run when agent finish is received. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_retry(retry_state, **kwargs) Run on a retry event.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainRun.html
66058a758b4f-1
on_retry(retry_state, **kwargs) Run on a retry event. on_text(text, **kwargs) Run when text is received. __init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. get_child(tag: Optional[str] = None) → CallbackManager¶ Get a child callback manager. Parameters tag (str, optional) – The tag for the child callback manager. Defaults to None. Returns The child callback manager. Return type CallbackManager classmethod get_noop_manager() → BRM¶ Return a manager that doesn’t perform any operations. Returns The noop manager. Return type BaseRunManager on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Run when agent action is received. Parameters action (AgentAction) – The agent action. Returns
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainRun.html
66058a758b4f-2
Parameters action (AgentAction) – The agent action. Returns The result of the callback. Return type Any on_agent_finish(finish: AgentFinish, **kwargs: Any) → Any[source]¶ Run when agent finish is received. Parameters finish (AgentFinish) – The agent finish. Returns The result of the callback. Return type Any on_chain_end(outputs: Union[Dict[str, Any], Any], **kwargs: Any) → None[source]¶ Run when chain ends running. Parameters outputs (Union[Dict[str, Any], Any]) – The outputs of the chain. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. Parameters error (Exception or KeyboardInterrupt) – The error. on_retry(retry_state: RetryCallState, **kwargs: Any) → None¶ Run on a retry event. on_text(text: str, **kwargs: Any) → Any¶ Run when text is received. Parameters text (str) – The received text. Returns The result of the callback. Return type Any Examples using CallbackManagerForChainRun¶ Custom chain
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainRun.html
0ad720816253-0
langchain.callbacks.manager.env_var_is_set¶ langchain.callbacks.manager.env_var_is_set(env_var: str) → bool[source]¶ Check if an environment variable is set. Parameters env_var (str) – The name of the environment variable. Returns True if the environment variable is set, False otherwise. Return type bool
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.env_var_is_set.html
7d0cdd3ee543-0
langchain.callbacks.manager.CallbackManagerForRetrieverRun¶ class langchain.callbacks.manager.CallbackManagerForRetrieverRun(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Callback manager for retriever run. Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Methods __init__(*, run_id, handlers, ...[, ...]) Initialize the run manager. get_child([tag]) Get a child callback manager. get_noop_manager() Return a manager that doesn't perform any operations. on_retriever_end(documents, **kwargs) Run when retriever ends running. on_retriever_error(error, **kwargs) Run when retriever errors. on_retry(retry_state, **kwargs) Run on a retry event. on_text(text, **kwargs) Run when text is received.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForRetrieverRun.html
7d0cdd3ee543-1
on_text(text, **kwargs) Run when text is received. __init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. get_child(tag: Optional[str] = None) → CallbackManager¶ Get a child callback manager. Parameters tag (str, optional) – The tag for the child callback manager. Defaults to None. Returns The child callback manager. Return type CallbackManager classmethod get_noop_manager() → BRM¶ Return a manager that doesn’t perform any operations. Returns The noop manager. Return type BaseRunManager on_retriever_end(documents: Sequence[Document], **kwargs: Any) → None[source]¶ Run when retriever ends running. on_retriever_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when retriever errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForRetrieverRun.html
7d0cdd3ee543-2
Run when retriever errors. on_retry(retry_state: RetryCallState, **kwargs: Any) → None¶ Run on a retry event. on_text(text: str, **kwargs: Any) → Any¶ Run when text is received. Parameters text (str) – The received text. Returns The result of the callback. Return type Any Examples using CallbackManagerForRetrieverRun¶ Retrieve as you generate with FLARE
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForRetrieverRun.html
d33a8932b903-0
langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler¶ class langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler(evaluators: Sequence[RunEvaluator], client: Optional[Client] = None, example_id: Optional[Union[str, UUID]] = None, skip_unfinished: bool = True, project_name: Optional[str] = 'evaluators', **kwargs: Any)[source]¶ A tracer that runs a run evaluator whenever a run is persisted. Parameters evaluators (Sequence[RunEvaluator]) – The run evaluators to apply to all top level runs. client (LangSmith Client, optional) – The LangSmith client instance to use for evaluating the runs. If not specified, a new instance will be created. example_id (Union[UUID, str], optional) – The example ID to be associated with the runs. project_name (str, optional) – The LangSmith project name to be organize eval chain runs under. example_id¶ The example ID associated with the runs. Type Union[UUID, None] client¶ The LangSmith client instance used for evaluating the runs. Type Client evaluators¶ The sequence of run evaluators to be executed. Type Sequence[RunEvaluator] executor¶ The thread pool executor used for running the evaluators. Type ThreadPoolExecutor futures¶ The set of futures representing the running evaluators. Type Set[Future] skip_unfinished¶ Whether to skip runs that are not finished or raised an error. Type bool project_name¶ The LangSmith project name to be organize eval chain runs under. Type Optional[str] Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler.html
d33a8932b903-1
ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. name raise_error run_inline Methods __init__(evaluators[, client, example_id, ...]) on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, *, run_id[, inputs]) End a trace for a chain run. on_chain_error(error, *[, inputs]) Handle an error for a chain run. on_chain_start(serialized, inputs, *, run_id) Start a trace for a chain run. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id, **kwargs) End a trace for an LLM run. on_llm_error(error, *, run_id, **kwargs) Handle an error for an LLM run. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Start a trace for an LLM run. on_retriever_end(documents, *, run_id, **kwargs) Run when Retriever ends running. on_retriever_error(error, *, run_id, **kwargs) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler.html
d33a8932b903-2
Run when Retriever starts running. on_retry(retry_state, *, run_id, **kwargs) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id, **kwargs) End a trace for a tool run. on_tool_error(error, *, run_id, **kwargs) Handle an error for a tool run. on_tool_start(serialized, input_str, *, run_id) Start a trace for a tool run. wait_for_futures() Wait for all futures to complete. __init__(evaluators: Sequence[RunEvaluator], client: Optional[Client] = None, example_id: Optional[Union[str, UUID]] = None, skip_unfinished: bool = True, project_name: Optional[str] = 'evaluators', **kwargs: Any) → None[source]¶ on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → Run¶ End a trace for a chain run. on_chain_error(error: BaseException, *, inputs: Optional[Dict[str, Any]] = None, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for a chain run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler.html
d33a8932b903-3
Handle an error for a chain run. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, run_type: Optional[str] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for a chain run. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, *, run_id: UUID, **kwargs: Any) → Run¶ End a trace for an LLM run. on_llm_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for an LLM run. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Run¶ Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for an LLM run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler.html
d33a8932b903-4
Start a trace for an LLM run. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, **kwargs: Any) → Run¶ Run on a retry event. on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, **kwargs: Any) → Run¶ End a trace for a tool run. on_tool_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for a tool run. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for a tool run. wait_for_futures() → None[source]¶ Wait for all futures to complete.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.evaluation.EvaluatorCallbackHandler.html
8e8ef8143b68-0
langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler¶ class langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler(logger: Logger, handler: Any)[source]¶ Callback Handler for logging to WhyLabs. This callback handler utilizes langkit to extract features from the prompts & responses when interacting with an LLM. These features can be used to guardrail, evaluate, and observe interactions over time to detect issues relating to hallucinations, prompt engineering, or output validation. LangKit is an LLM monitoring toolkit developed by WhyLabs. Here are some examples of what can be monitored with LangKit: * Text Quality readability score complexity and grade scores Text Relevance - Similarity scores between prompt/responses - Similarity scores against user-defined themes - Topic classification Security and Privacy - patterns - count of strings matching a user-defined regex pattern group - jailbreaks - similarity scores with respect to known jailbreak attempts - prompt injection - similarity scores with respect to known prompt attacks - refusals - similarity scores with respect to known LLM refusal responses Sentiment and Toxicity - sentiment analysis - toxicity analysis For more information, see https://docs.whylabs.ai/docs/language-model-monitoring or check out the LangKit repo here: https://github.com/whylabs/langkit — :param api_key: WhyLabs API key. Optional because the preferred way to specify the API key is with environment variable WHYLABS_API_KEY. Parameters org_id (Optional[str]) – WhyLabs organization id to write profiles to. Optional because the preferred way to specify the organization id is with environment variable WHYLABS_DEFAULT_ORG_ID. dataset_id (Optional[str]) – WhyLabs dataset id to write profiles to. Optional because the preferred way to specify the dataset id is
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
8e8ef8143b68-1
Optional because the preferred way to specify the dataset id is with environment variable WHYLABS_DEFAULT_DATASET_ID. sentiment (bool) – Whether to enable sentiment analysis. Defaults to False. toxicity (bool) – Whether to enable toxicity analysis. Defaults to False. themes (bool) – Whether to enable theme analysis. Defaults to False. Initiate the rolling logger. Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__(logger, handler) Initiate the rolling logger. close() Close any loggers to allow writing out of any profiles before exiting. flush() Explicitly write current profile if using a rolling logger. from_params(*[, api_key, org_id, ...]) Instantiate whylogs Logger from params. on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, *, run_id[, parent_run_id]) Run when chain ends running. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. on_chain_start(serialized, inputs, *, run_id) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id[, parent_run_id]) Run when LLM ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
8e8ef8143b68-2
Run when LLM ends running. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__(logger: Logger, handler: Any)[source]¶ Initiate the rolling logger. close() → None[source]¶ Close any loggers to allow writing out of any profiles before exiting. flush() → None[source]¶ Explicitly write current profile if using a rolling logger.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
8e8ef8143b68-3
flush() → None[source]¶ Explicitly write current profile if using a rolling logger. classmethod from_params(*, api_key: Optional[str] = None, org_id: Optional[str] = None, dataset_id: Optional[str] = None, sentiment: bool = False, toxicity: bool = False, themes: bool = False, logger: Optional[Logger] = None) → WhyLabsCallbackHandler[source]¶ Instantiate whylogs Logger from params. Parameters api_key (Optional[str]) – WhyLabs API key. Optional because the preferred way to specify the API key is with environment variable WHYLABS_API_KEY. org_id (Optional[str]) – WhyLabs organization id to write profiles to. If not set must be specified in environment variable WHYLABS_DEFAULT_ORG_ID. dataset_id (Optional[str]) – The model or dataset this callback is gathering telemetry for. If not set must be specified in environment variable WHYLABS_DEFAULT_DATASET_ID. sentiment (bool) – If True will initialize a model to perform sentiment analysis compound score. Defaults to False and will not gather this metric. toxicity (bool) – If True will initialize a model to score toxicity. Defaults to False and will not gather this metric. themes (bool) – If True will initialize a model to calculate distance to configured themes. Defaults to None and will not gather this metric. logger (Optional[Logger]) – If specified will bind the configured logger as the telemetry gathering agent. Defaults to LangKit schema with periodic WhyLabs writer. on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
8e8ef8143b68-4
Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain ends running. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM ends running. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
8e8ef8143b68-5
Run when LLM errors. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) – on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
8e8ef8143b68-6
Run on a retry event. on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when tool starts running. Examples using WhyLabsCallbackHandler¶ WhyLabs
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.whylabs_callback.WhyLabsCallbackHandler.html
cb6f76aa1113-0
langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler¶ class langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler(parent_container: DeltaGenerator, *, max_thought_containers: int = 4, expand_new_thoughts: bool = True, collapse_completed_thoughts: bool = True, thought_labeler: Optional[LLMThoughtLabeler] = None)[source]¶ A callback handler that writes to a Streamlit app. Create a StreamlitCallbackHandler instance. 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. Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__(parent_container, *[, ...]) Create a StreamlitCallbackHandler instance. on_agent_action(action[, color]) Run on agent action.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler.html
cb6f76aa1113-1
on_agent_action(action[, color]) Run on agent action. on_agent_finish(finish[, color]) Run on agent end. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run on new LLM token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text[, color, end]) Run on arbitrary text. on_tool_end(output[, color, ...]) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler.html
cb6f76aa1113-2
Run when tool starts running. __init__(parent_container: DeltaGenerator, *, max_thought_containers: int = 4, expand_new_thoughts: bool = True, collapse_completed_thoughts: bool = True, thought_labeler: Optional[LLMThoughtLabeler] = None)[source]¶ Create a StreamlitCallbackHandler instance. 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. on_agent_action(action: AgentAction, color: Optional[str] = None, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, color: Optional[str] = None, **kwargs: Any) → None[source]¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler.html
cb6f76aa1113-3
Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) – on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler.html
cb6f76aa1113-4
Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, color: Optional[str] = None, end: str = '', **kwargs: Any) → None[source]¶ Run on arbitrary text. on_tool_end(output: str, color: Optional[str] = None, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) → None[source]¶ Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Run when tool starts running. Examples using StreamlitCallbackHandler¶ Streamlit GPT4All
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler.html
f8cac7746be5-0
langchain.callbacks.manager.AsyncCallbackManagerForChainGroup¶ class langchain.callbacks.manager.AsyncCallbackManagerForChainGroup(handlers: List[BaseCallbackHandler], inheritable_handlers: Optional[List[BaseCallbackHandler]] = None, parent_run_id: uuid.UUID | None = None, *, parent_run_manager: AsyncCallbackManagerForChainRun, **kwargs: Any)[source]¶ Initialize callback manager. Attributes is_async Return whether the handler is async. Methods __init__(handlers[, inheritable_handlers, ...]) Initialize callback manager. add_handler(handler[, inherit]) Add a handler to the callback manager. add_metadata(metadata[, inherit]) add_tags(tags[, inherit]) configure([inheritable_callbacks, ...]) Configure the async callback manager. copy() Copy the callback manager. on_chain_end(outputs, **kwargs) Run when traced chain group ends. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs[, run_id]) Run when chain starts running. on_chat_model_start(serialized, messages, ...) Run when LLM starts running. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts running. on_retriever_start(serialized, query[, ...]) Run when retriever starts running. on_tool_start(serialized, input_str[, ...]) Run when tool starts running. remove_handler(handler) Remove a handler from the callback manager. remove_metadata(keys) remove_tags(tags) set_handler(handler[, inherit]) Set handler as the only handler on the callback manager. set_handlers(handlers[, inherit]) Set handlers as the only handlers on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForChainGroup.html
f8cac7746be5-1
Set handlers as the only handlers on the callback manager. __init__(handlers: List[BaseCallbackHandler], inheritable_handlers: Optional[List[BaseCallbackHandler]] = None, parent_run_id: uuid.UUID | None = None, *, parent_run_manager: AsyncCallbackManagerForChainRun, **kwargs: Any) → None[source]¶ Initialize callback manager. add_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶ Add a handler to the callback manager. add_metadata(metadata: Dict[str, Any], inherit: bool = True) → None¶ add_tags(tags: List[str], inherit: bool = True) → None¶ classmethod configure(inheritable_callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, local_callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, verbose: bool = False, inheritable_tags: Optional[List[str]] = None, local_tags: Optional[List[str]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None, local_metadata: Optional[Dict[str, Any]] = None) → AsyncCallbackManager¶ Configure the async callback manager. Parameters inheritable_callbacks (Optional[Callbacks], optional) – The inheritable callbacks. Defaults to None. local_callbacks (Optional[Callbacks], optional) – The local callbacks. Defaults to None. verbose (bool, optional) – Whether to enable verbose mode. Defaults to False. inheritable_tags (Optional[List[str]], optional) – The inheritable tags. Defaults to None. local_tags (Optional[List[str]], optional) – The local tags. Defaults to None. inheritable_metadata (Optional[Dict[str, Any]], optional) – The inheritable metadata. Defaults to None. local_metadata (Optional[Dict[str, Any]], optional) – The local metadata. Defaults to None. Returns
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForChainGroup.html
f8cac7746be5-2
Defaults to None. Returns The configured async callback manager. Return type AsyncCallbackManager copy() → T¶ Copy the callback manager. async on_chain_end(outputs: Union[Dict[str, Any], Any], **kwargs: Any) → None[source]¶ Run when traced chain group ends. Parameters outputs (Union[Dict[str, Any], Any]) – The outputs of the chain. async on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. Parameters error (Exception or KeyboardInterrupt) – The error. async on_chain_start(serialized: Dict[str, Any], inputs: Union[Dict[str, Any], Any], run_id: Optional[UUID] = None, **kwargs: Any) → AsyncCallbackManagerForChainRun¶ Run when chain starts running. Parameters serialized (Dict[str, Any]) – The serialized chain. inputs (Union[Dict[str, Any], Any]) – The inputs to the chain. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The async callback managerfor the chain run. Return type AsyncCallbackManagerForChainRun async on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs: Any) → List[AsyncCallbackManagerForLLMRun]¶ Run when LLM starts running. Parameters serialized (Dict[str, Any]) – The serialized LLM. messages (List[List[BaseMessage]]) – The list of messages. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The list ofasync callback managers, one for each LLM Run corresponding to each inner message list. Return type List[AsyncCallbackManagerForLLMRun]
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForChainGroup.html
f8cac7746be5-3
Return type List[AsyncCallbackManagerForLLMRun] async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → List[AsyncCallbackManagerForLLMRun]¶ Run when LLM starts running. Parameters serialized (Dict[str, Any]) – The serialized LLM. prompts (List[str]) – The list of prompts. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The list of asynccallback managers, one for each LLM Run corresponding to each prompt. Return type List[AsyncCallbackManagerForLLMRun] async on_retriever_start(serialized: Dict[str, Any], query: str, run_id: Optional[UUID] = None, parent_run_id: Optional[UUID] = None, **kwargs: Any) → AsyncCallbackManagerForRetrieverRun¶ Run when retriever starts running. async on_tool_start(serialized: Dict[str, Any], input_str: str, run_id: Optional[UUID] = None, parent_run_id: Optional[UUID] = None, **kwargs: Any) → AsyncCallbackManagerForToolRun¶ Run when tool starts running. Parameters serialized (Dict[str, Any]) – The serialized tool. input_str (str) – The input to the tool. run_id (UUID, optional) – The ID of the run. Defaults to None. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. Returns The async callback managerfor the tool run. Return type AsyncCallbackManagerForToolRun remove_handler(handler: BaseCallbackHandler) → None¶ Remove a handler from the callback manager. remove_metadata(keys: List[str]) → None¶ remove_tags(tags: List[str]) → None¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForChainGroup.html
f8cac7746be5-4
remove_tags(tags: List[str]) → None¶ set_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶ Set handler as the only handler on the callback manager. set_handlers(handlers: List[BaseCallbackHandler], inherit: bool = True) → None¶ Set handlers as the only handlers on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForChainGroup.html
7d8c58a50b01-0
langchain.callbacks.tracers.stdout.elapsed¶ langchain.callbacks.tracers.stdout.elapsed(run: Any) → str[source]¶ Get the elapsed time of a run. Parameters run – any object with a start_time and end_time attribute. Returns A string with the elapsed time in seconds ormilliseconds if time is less than a second.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.stdout.elapsed.html
1877565e8f0c-0
langchain.callbacks.tracers.langchain_v1.get_headers¶ langchain.callbacks.tracers.langchain_v1.get_headers() → Dict[str, Any][source]¶ Get the headers for the LangChain API.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain_v1.get_headers.html
47145536a72e-0
langchain.callbacks.infino_callback.InfinoCallbackHandler¶ class langchain.callbacks.infino_callback.InfinoCallbackHandler(model_id: Optional[str] = None, model_version: Optional[str] = None, verbose: bool = False)[source]¶ Callback Handler that logs to Infino. Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__([model_id, model_version, verbose]) on_agent_action(action, **kwargs) Do nothing when agent takes a specific action. on_agent_finish(finish, **kwargs) Do nothing. on_chain_end(outputs, **kwargs) Do nothing when LLM chain ends. on_chain_error(error, **kwargs) Need to log the error. on_chain_start(serialized, inputs, **kwargs) Do nothing when LLM chain starts. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Log the latency, error, token usage, and response to Infino. on_llm_error(error, **kwargs) Set the error flag. on_llm_new_token(token, **kwargs) Do nothing when a new token is generated. on_llm_start(serialized, prompts, **kwargs) Log the prompts to Infino, and set start time and error flag. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.infino_callback.InfinoCallbackHandler.html
47145536a72e-1
Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Do nothing. on_tool_end(output[, observation_prefix, ...]) Do nothing when tool ends. on_tool_error(error, **kwargs) Do nothing when tool outputs an error. on_tool_start(serialized, input_str, **kwargs) Do nothing when tool starts. __init__(model_id: Optional[str] = None, model_version: Optional[str] = None, verbose: bool = False) → None[source]¶ on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Do nothing when agent takes a specific action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Do nothing. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Do nothing when LLM chain ends. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Need to log the error. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Do nothing when LLM chain starts.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.infino_callback.InfinoCallbackHandler.html
47145536a72e-2
Do nothing when LLM chain starts. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Log the latency, error, token usage, and response to Infino. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Set the error flag. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Do nothing when a new token is generated. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Log the prompts to Infino, and set start time and error flag. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.infino_callback.InfinoCallbackHandler.html
47145536a72e-3
Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Do nothing. on_tool_end(output: str, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) → None[source]¶ Do nothing when tool ends. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when tool outputs an error. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Do nothing when tool starts. Examples using InfinoCallbackHandler¶ Infino
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.infino_callback.InfinoCallbackHandler.html
125e6232c6ab-0
langchain.callbacks.utils.hash_string¶ langchain.callbacks.utils.hash_string(s: str) → str[source]¶ Hash a string using sha1. Parameters s (str) – The string to hash. Returns The hashed string. Return type (str)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.utils.hash_string.html
707d6c705b48-0
langchain.callbacks.argilla_callback.ArgillaCallbackHandler¶ class langchain.callbacks.argilla_callback.ArgillaCallbackHandler(dataset_name: str, workspace_name: Optional[str] = None, api_url: Optional[str] = None, api_key: Optional[str] = None)[source]¶ Callback Handler that logs into Argilla. Parameters dataset_name – name of the FeedbackDataset in Argilla. Note that it must exist in advance. If you need help on how to create a FeedbackDataset in Argilla, please visit https://docs.argilla.io/en/latest/guides/llms/practical_guides/use_argilla_callback_in_langchain.html. workspace_name – name of the workspace in Argilla where the specified FeedbackDataset lives in. Defaults to None, which means that the default workspace will be used. api_url – URL of the Argilla Server that we want to use, and where the FeedbackDataset lives in. Defaults to None, which means that either ARGILLA_API_URL environment variable or the default will be used. api_key – API Key to connect to the Argilla Server. Defaults to None, which means that either ARGILLA_API_KEY environment variable or the default will be used. Raises ImportError – if the argilla package is not installed. ConnectionError – if the connection to Argilla fails. FileNotFoundError – if the FeedbackDataset retrieval from Argilla fails. Examples >>> from langchain.llms import OpenAI >>> from langchain.callbacks import ArgillaCallbackHandler >>> argilla_callback = ArgillaCallbackHandler( ... dataset_name="my-dataset", ... workspace_name="my-workspace", ... api_url="http://localhost:6900", ... api_key="argilla.apikey", ... ) >>> llm = OpenAI( ... temperature=0,
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
707d6c705b48-1
... ) >>> llm = OpenAI( ... temperature=0, ... callbacks=[argilla_callback], ... verbose=True, ... openai_api_key="API_KEY_HERE", ... ) >>> llm.generate([ ... "What is the best NLP-annotation tool out there? (no bias at all)", ... ]) "Argilla, no doubt about it." Initializes the ArgillaCallbackHandler. Parameters dataset_name – name of the FeedbackDataset in Argilla. Note that it must exist in advance. If you need help on how to create a FeedbackDataset in Argilla, please visit https://docs.argilla.io/en/latest/guides/llms/practical_guides/use_argilla_callback_in_langchain.html. workspace_name – name of the workspace in Argilla where the specified FeedbackDataset lives in. Defaults to None, which means that the default workspace will be used. api_url – URL of the Argilla Server that we want to use, and where the FeedbackDataset lives in. Defaults to None, which means that either ARGILLA_API_URL environment variable or the default will be used. api_key – API Key to connect to the Argilla Server. Defaults to None, which means that either ARGILLA_API_KEY environment variable or the default will be used. Raises ImportError – if the argilla package is not installed. ConnectionError – if the connection to Argilla fails. FileNotFoundError – if the FeedbackDataset retrieval from Argilla fails. Attributes BLOG_URL DEFAULT_API_URL ISSUES_URL REPO_URL ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
707d6c705b48-2
ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__(dataset_name[, workspace_name, ...]) Initializes the ArgillaCallbackHandler. on_agent_action(action, **kwargs) Do nothing when agent takes a specific action. on_agent_finish(finish, **kwargs) Do nothing on_chain_end(outputs, **kwargs) If either the parent_run_id or the run_id is in self.prompts, then log the outputs to Argilla, and pop the run from self.prompts. on_chain_error(error, **kwargs) Do nothing when LLM chain outputs an error. on_chain_start(serialized, inputs, **kwargs) If the key input is in inputs, then save it in self.prompts using either the parent_run_id or the run_id as the key. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Log records to Argilla when an LLM ends. on_llm_error(error, **kwargs) Do nothing when LLM outputs an error. on_llm_new_token(token, **kwargs) Do nothing when a new token is generated. on_llm_start(serialized, prompts, **kwargs) Save the prompts in memory when an LLM starts. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
707d6c705b48-3
on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Do nothing on_tool_end(output[, observation_prefix, ...]) Do nothing when tool ends. on_tool_error(error, **kwargs) Do nothing when tool outputs an error. on_tool_start(serialized, input_str, **kwargs) Do nothing when tool starts. __init__(dataset_name: str, workspace_name: Optional[str] = None, api_url: Optional[str] = None, api_key: Optional[str] = None) → None[source]¶ Initializes the ArgillaCallbackHandler. Parameters dataset_name – name of the FeedbackDataset in Argilla. Note that it must exist in advance. If you need help on how to create a FeedbackDataset in Argilla, please visit https://docs.argilla.io/en/latest/guides/llms/practical_guides/use_argilla_callback_in_langchain.html. workspace_name – name of the workspace in Argilla where the specified FeedbackDataset lives in. Defaults to None, which means that the default workspace will be used. api_url – URL of the Argilla Server that we want to use, and where the FeedbackDataset lives in. Defaults to None, which means that either ARGILLA_API_URL environment variable or the default will be used. api_key – API Key to connect to the Argilla Server. Defaults to None, which means that either ARGILLA_API_KEY environment variable or the default will be used. Raises ImportError – if the argilla package is not installed. ConnectionError – if the connection to Argilla fails.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
707d6c705b48-4
ConnectionError – if the connection to Argilla fails. FileNotFoundError – if the FeedbackDataset retrieval from Argilla fails. on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Do nothing when agent takes a specific action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Do nothing on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ If either the parent_run_id or the run_id is in self.prompts, then log the outputs to Argilla, and pop the run from self.prompts. The behavior differs if the output is a list or not. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when LLM chain outputs an error. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ If the key input is in inputs, then save it in self.prompts using either the parent_run_id or the run_id as the key. This is done so that we don’t log the same input prompt twice, once when the LLM starts and once when the chain starts. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Log records to Argilla when an LLM ends. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
707d6c705b48-5
on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when LLM outputs an error. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Do nothing when a new token is generated. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Save the prompts in memory when an LLM starts. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Do nothing on_tool_end(output: str, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) → None[source]¶ Do nothing when tool ends. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when tool outputs an error.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
707d6c705b48-6
Do nothing when tool outputs an error. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Do nothing when tool starts. Examples using ArgillaCallbackHandler¶ Argilla
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.argilla_callback.ArgillaCallbackHandler.html
12d59fd07b55-0
langchain.callbacks.aim_callback.AimCallbackHandler¶ class langchain.callbacks.aim_callback.AimCallbackHandler(repo: Optional[str] = None, experiment_name: Optional[str] = None, system_tracking_interval: Optional[int] = 10, log_system_params: bool = True)[source]¶ Callback Handler that logs to Aim. Parameters repo (str, optional) – Aim repository path or Repo object to which Run object is bound. If skipped, default Repo is used. experiment_name (str, optional) – Sets Run’s experiment property. ‘default’ if not specified. Can be used later to query runs/sequences. system_tracking_interval (int, optional) – Sets the tracking interval in seconds for system usage metrics (CPU, Memory, etc.). Set to None to disable system metrics tracking. log_system_params (bool, optional) – Enable/Disable logging of system params such as installed packages, git info, environment variables, etc. This handler will utilize the associated callback method called and formats the input of each callback function with metadata regarding the state of LLM run and then logs the response to Aim. Initialize callback handler. Attributes always_verbose Whether to call verbose callbacks even if verbose is False. ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__([repo, experiment_name, ...]) Initialize callback handler. flush_tracker([repo, experiment_name, ...]) Flush the tracker and reset the session. get_custom_callback_meta() on_agent_action(action, **kwargs)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.aim_callback.AimCallbackHandler.html
12d59fd07b55-1
get_custom_callback_meta() on_agent_action(action, **kwargs) Run on agent action. on_agent_finish(finish, **kwargs) Run when agent ends running. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run when LLM generates a new token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Run when agent is ending. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running. reset_callback_meta() Reset the callback metadata. setup(**kwargs)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.aim_callback.AimCallbackHandler.html
12d59fd07b55-2
reset_callback_meta() Reset the callback metadata. setup(**kwargs) __init__(repo: Optional[str] = None, experiment_name: Optional[str] = None, system_tracking_interval: Optional[int] = 10, log_system_params: bool = True) → None[source]¶ Initialize callback handler. flush_tracker(repo: Optional[str] = None, experiment_name: Optional[str] = None, system_tracking_interval: Optional[int] = 10, log_system_params: bool = True, langchain_asset: Any = None, reset: bool = True, finish: bool = False) → None[source]¶ Flush the tracker and reset the session. Parameters repo (str, optional) – Aim repository path or Repo object to which Run object is bound. If skipped, default Repo is used. experiment_name (str, optional) – Sets Run’s experiment property. ‘default’ if not specified. Can be used later to query runs/sequences. system_tracking_interval (int, optional) – Sets the tracking interval in seconds for system usage metrics (CPU, Memory, etc.). Set to None to disable system metrics tracking. log_system_params (bool, optional) – Enable/Disable logging of system params such as installed packages, git info, environment variables, etc. langchain_asset – The langchain asset to save. reset – Whether to reset the session. finish – Whether to finish the run. Returns – None get_custom_callback_meta() → Dict[str, Any]¶ on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Run when agent ends running. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.aim_callback.AimCallbackHandler.html
12d59fd07b55-3
Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run when LLM generates a new token. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.aim_callback.AimCallbackHandler.html
12d59fd07b55-4
Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Run when agent is ending. on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Run when tool starts running. reset_callback_meta() → None¶ Reset the callback metadata. setup(**kwargs: Any) → None[source]¶ Examples using AimCallbackHandler¶ Aim
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.aim_callback.AimCallbackHandler.html
b0c020ec70da-0
langchain.callbacks.openai_info.get_openai_token_cost_for_model¶ langchain.callbacks.openai_info.get_openai_token_cost_for_model(model_name: str, num_tokens: int, is_completion: bool = False) → float[source]¶ Get the cost in USD for a given model and number of tokens. Parameters model_name – Name of the model num_tokens – Number of tokens. is_completion – Whether the model is used for completion or not. Defaults to False. Returns Cost in USD.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.openai_info.get_openai_token_cost_for_model.html
1d73365b3f19-0
langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler¶ class langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler(example_id: Optional[Union[UUID, str]] = None, **kwargs: Any)[source]¶ A tracer that collects all nested runs in a list. This tracer is useful for inspection and evaluation purposes. Parameters example_id (Optional[Union[UUID, str]], default=None) – The ID of the example being traced. It can be either a UUID or a string. Initialize the RunCollectorCallbackHandler. Parameters example_id (Optional[Union[UUID, str]], default=None) – The ID of the example being traced. It can be either a UUID or a string. Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. name raise_error run_inline Methods __init__([example_id]) Initialize the RunCollectorCallbackHandler. on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, *, run_id[, inputs]) End a trace for a chain run. on_chain_error(error, *[, inputs]) Handle an error for a chain run. on_chain_start(serialized, inputs, *, run_id) Start a trace for a chain run. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler.html
1d73365b3f19-1
Run when a chat model starts running. on_llm_end(response, *, run_id, **kwargs) End a trace for an LLM run. on_llm_error(error, *, run_id, **kwargs) Handle an error for an LLM run. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Start a trace for an LLM run. on_retriever_end(documents, *, run_id, **kwargs) Run when Retriever ends running. on_retriever_error(error, *, run_id, **kwargs) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id, **kwargs) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id, **kwargs) End a trace for a tool run. on_tool_error(error, *, run_id, **kwargs) Handle an error for a tool run. on_tool_start(serialized, input_str, *, run_id) Start a trace for a tool run. __init__(example_id: Optional[Union[UUID, str]] = None, **kwargs: Any) → None[source]¶ Initialize the RunCollectorCallbackHandler. Parameters example_id (Optional[Union[UUID, str]], default=None) – The ID of the example being traced. It can be either a UUID or a string.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler.html
1d73365b3f19-2
on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → Run¶ End a trace for a chain run. on_chain_error(error: BaseException, *, inputs: Optional[Dict[str, Any]] = None, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for a chain run. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, run_type: Optional[str] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for a chain run. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, *, run_id: UUID, **kwargs: Any) → Run¶ End a trace for an LLM run. on_llm_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler.html
1d73365b3f19-3
Handle an error for an LLM run. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Run¶ Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for an LLM run. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, **kwargs: Any) → Run¶ Run on a retry event. on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, **kwargs: Any) → Run¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler.html
1d73365b3f19-4
End a trace for a tool run. on_tool_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for a tool run. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for a tool run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.run_collector.RunCollectorCallbackHandler.html
47b2042bf717-0
langchain.callbacks.base.BaseCallbackHandler¶ class langchain.callbacks.base.BaseCallbackHandler[source]¶ Base callback handler that can be used to handle callbacks from langchain. Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__() on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, *, run_id[, parent_run_id]) Run when chain ends running. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. on_chain_start(serialized, inputs, *, run_id) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id[, parent_run_id]) Run when LLM ends running. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...])
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.BaseCallbackHandler.html
47b2042bf717-1
on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__()¶ on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain ends running. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.BaseCallbackHandler.html
47b2042bf717-2
Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM ends running. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM errors. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) –
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.BaseCallbackHandler.html
47b2042bf717-3
information. (containing content and other) – on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.BaseCallbackHandler.html
47b2042bf717-4
Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when tool starts running. Examples using BaseCallbackHandler¶ Ollama Custom callback handlers Multiple callback handlers Async callbacks Streaming final agent output
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.BaseCallbackHandler.html
16106fbe5720-0
langchain.callbacks.tracers.schemas.ToolRun¶ class langchain.callbacks.tracers.schemas.ToolRun[source]¶ Bases: BaseRun Class for ToolRun. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be parsed to form a valid model. param action: str [Required]¶ param child_chain_runs: List[langchain.callbacks.tracers.schemas.ChainRun] [Optional]¶ param child_execution_order: int [Required]¶ param child_llm_runs: List[langchain.callbacks.tracers.schemas.LLMRun] [Optional]¶ param child_tool_runs: List[langchain.callbacks.tracers.schemas.ToolRun] [Optional]¶ param end_time: datetime.datetime [Optional]¶ param error: Optional[str] = None¶ param execution_order: int [Required]¶ param extra: Optional[Dict[str, Any]] = None¶ param output: Optional[str] = None¶ param parent_uuid: Optional[str] = None¶ param serialized: Dict[str, Any] [Required]¶ param session_id: int [Required]¶ param start_time: datetime.datetime [Optional]¶ param tool_input: str [Required]¶ param uuid: str [Required]¶ classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶ Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.ToolRun.html
16106fbe5720-1
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶ Duplicate a model, optionally choose which fields to include, exclude and change. Parameters include – fields to include in new model exclude – fields to exclude from new model, as with values this takes precedence over include update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) → DictStrAny¶ Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. classmethod from_orm(obj: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.ToolRun.html
16106fbe5720-2
classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ Generate a JSON representation of the model, include and exclude arguments as per dict(). encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps(). classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.ToolRun.html
c8d99b661ecb-0
langchain.callbacks.llmonitor_callback.identify¶ langchain.callbacks.llmonitor_callback.identify(user_id: str, user_props: Any = None) → UserContextManager[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.llmonitor_callback.identify.html
c6558953cadb-0
langchain.callbacks.tracers.schemas.RunTypeEnum¶ langchain.callbacks.tracers.schemas.RunTypeEnum() → RunTypeEnum[source]¶ RunTypeEnum.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.RunTypeEnum.html
2d2ef813a3f5-0
langchain.callbacks.manager.AsyncCallbackManagerForToolRun¶ class langchain.callbacks.manager.AsyncCallbackManagerForToolRun(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Async callback manager for tool run. Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Methods __init__(*, run_id, handlers, ...[, ...]) Initialize the run manager. get_child([tag]) Get a child callback manager. get_noop_manager() Return a manager that doesn't perform any operations. on_retry(retry_state, **kwargs) Run on a retry event. on_text(text, **kwargs) Run when text is received. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForToolRun.html
2d2ef813a3f5-1
on_tool_error(error, **kwargs) Run when tool errors. __init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. get_child(tag: Optional[str] = None) → AsyncCallbackManager¶ Get a child callback manager. Parameters tag (str, optional) – The tag for the child callback manager. Defaults to None. Returns The child callback manager. Return type AsyncCallbackManager classmethod get_noop_manager() → BRM¶ Return a manager that doesn’t perform any operations. Returns The noop manager. Return type BaseRunManager async on_retry(retry_state: RetryCallState, **kwargs: Any) → None¶ Run on a retry event. async on_text(text: str, **kwargs: Any) → Any¶ Run when text is received. Parameters
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForToolRun.html
2d2ef813a3f5-2
Run when text is received. Parameters text (str) – The received text. Returns The result of the callback. Return type Any async on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running. Parameters output (str) – The output of the tool. async on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. Parameters error (Exception or KeyboardInterrupt) – The error. Examples using AsyncCallbackManagerForToolRun¶ Defining Custom Tools
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForToolRun.html
29b76a19d9ae-0
langchain.callbacks.manager.AsyncRunManager¶ class langchain.callbacks.manager.AsyncRunManager(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Async Run Manager. Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Methods __init__(*, run_id, handlers, ...[, ...]) Initialize the run manager. get_noop_manager() Return a manager that doesn't perform any operations. on_retry(retry_state, **kwargs) Run on a retry event. on_text(text, **kwargs) Run when text is received.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncRunManager.html
29b76a19d9ae-1
on_text(text, **kwargs) Run when text is received. __init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. classmethod get_noop_manager() → BRM¶ Return a manager that doesn’t perform any operations. Returns The noop manager. Return type BaseRunManager async on_retry(retry_state: RetryCallState, **kwargs: Any) → None[source]¶ Run on a retry event. async on_text(text: str, **kwargs: Any) → Any[source]¶ Run when text is received. Parameters text (str) – The received text. Returns The result of the callback. Return type Any
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncRunManager.html
620ee1a16b5b-0
langchain.callbacks.openai_info.OpenAICallbackHandler¶ class langchain.callbacks.openai_info.OpenAICallbackHandler[source]¶ Callback Handler that tracks OpenAI info. Attributes always_verbose Whether to call verbose callbacks even if verbose is False. completion_tokens ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. prompt_tokens raise_error run_inline successful_requests total_cost total_tokens Methods __init__() on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, *, run_id[, parent_run_id]) Run when chain ends running. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. on_chain_start(serialized, inputs, *, run_id) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Collect token usage. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, **kwargs) Print out the token. on_llm_start(serialized, prompts, **kwargs) Print out the prompts. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.openai_info.OpenAICallbackHandler.html
620ee1a16b5b-1
Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__()¶ on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain ends running. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.openai_info.OpenAICallbackHandler.html
620ee1a16b5b-2
Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Collect token usage. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Print out the token. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Print out the prompts. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.openai_info.OpenAICallbackHandler.html
620ee1a16b5b-3
Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when tool starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.openai_info.OpenAICallbackHandler.html
5b75d92f6c53-0
langchain.callbacks.tracers.wandb.WandbRunArgs¶ class langchain.callbacks.tracers.wandb.WandbRunArgs[source]¶ Arguments for the WandbTracer. job_type: Optional[str]¶ dir: Optional[StrPath]¶ config: Union[Dict, str, None]¶ project: Optional[str]¶ entity: Optional[str]¶ reinit: Optional[bool]¶ tags: Optional[Sequence]¶ group: Optional[str]¶ name: Optional[str]¶ notes: Optional[str]¶ magic: Optional[Union[dict, str, bool]]¶ config_exclude_keys: Optional[List[str]]¶ config_include_keys: Optional[List[str]]¶ anonymous: Optional[str]¶ mode: Optional[str]¶ allow_val_change: Optional[bool]¶ resume: Optional[Union[bool, str]]¶ force: Optional[bool]¶ tensorboard: Optional[bool]¶ sync_tensorboard: Optional[bool]¶ monitor_gym: Optional[bool]¶ save_code: Optional[bool]¶ id: Optional[str]¶ settings: Union[WBSettings, Dict[str, Any], None]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.wandb.WandbRunArgs.html
4b8ec927227a-0
langchain.callbacks.labelstudio_callback.LabelStudioMode¶ class langchain.callbacks.labelstudio_callback.LabelStudioMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶ PROMPT = 'prompt'¶ CHAT = 'chat'¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.labelstudio_callback.LabelStudioMode.html
1d1c06b96bd7-0
langchain.callbacks.aim_callback.import_aim¶ langchain.callbacks.aim_callback.import_aim() → Any[source]¶ Import the aim python package and raise an error if it is not installed.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.aim_callback.import_aim.html
832683ae0041-0
langchain.callbacks.confident_callback.DeepEvalCallbackHandler¶ class langchain.callbacks.confident_callback.DeepEvalCallbackHandler(metrics: List[Any], implementation_name: Optional[str] = None)[source]¶ Callback Handler that logs into deepeval. Parameters implementation_name – name of the implementation in deepeval metrics – A list of metrics Raises ImportError – if the deepeval package is not installed. Examples >>> from langchain.llms import OpenAI >>> from langchain.callbacks import DeepEvalCallbackHandler >>> from deepeval.metrics import AnswerRelevancy >>> metric = AnswerRelevancy(minimum_score=0.3) >>> deepeval_callback = DeepEvalCallbackHandler( ... implementation_name="exampleImplementation", ... metrics=[metric], ... ) >>> llm = OpenAI( ... temperature=0, ... callbacks=[deepeval_callback], ... verbose=True, ... openai_api_key="API_KEY_HERE", ... ) >>> llm.generate([ ... "What is the best evaluation tool out there? (no bias at all)", ... ]) "Deepeval, no doubt about it." Initializes the deepevalCallbackHandler. Parameters implementation_name – Name of the implementation you want. metrics – What metrics do you want to track? Raises ImportError – if the deepeval package is not installed. ConnectionError – if the connection to deepeval fails. Attributes BLOG_URL ISSUES_URL REPO_URL ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.confident_callback.DeepEvalCallbackHandler.html
832683ae0041-1
Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__(metrics[, implementation_name]) Initializes the deepevalCallbackHandler. on_agent_action(action, **kwargs) Do nothing when agent takes a specific action. on_agent_finish(finish, **kwargs) Do nothing on_chain_end(outputs, **kwargs) Do nothing when chain ends. on_chain_error(error, **kwargs) Do nothing when LLM chain outputs an error. on_chain_start(serialized, inputs, **kwargs) Do nothing when chain starts on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Log records to deepeval when an LLM ends. on_llm_error(error, **kwargs) Do nothing when LLM outputs an error. on_llm_new_token(token, **kwargs) Do nothing when a new token is generated. on_llm_start(serialized, prompts, **kwargs) Store the prompts on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Do nothing on_tool_end(output[, observation_prefix, ...]) Do nothing when tool ends. on_tool_error(error, **kwargs)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.confident_callback.DeepEvalCallbackHandler.html
832683ae0041-2
Do nothing when tool ends. on_tool_error(error, **kwargs) Do nothing when tool outputs an error. on_tool_start(serialized, input_str, **kwargs) Do nothing when tool starts. __init__(metrics: List[Any], implementation_name: Optional[str] = None) → None[source]¶ Initializes the deepevalCallbackHandler. Parameters implementation_name – Name of the implementation you want. metrics – What metrics do you want to track? Raises ImportError – if the deepeval package is not installed. ConnectionError – if the connection to deepeval fails. on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Do nothing when agent takes a specific action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Do nothing on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Do nothing when chain ends. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when LLM chain outputs an error. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Do nothing when chain starts on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Log records to deepeval when an LLM ends.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.confident_callback.DeepEvalCallbackHandler.html
832683ae0041-3
Log records to deepeval when an LLM ends. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when LLM outputs an error. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Do nothing when a new token is generated. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Store the prompts on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Do nothing on_tool_end(output: str, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) → None[source]¶ Do nothing when tool ends. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.confident_callback.DeepEvalCallbackHandler.html
832683ae0041-4
on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when tool outputs an error. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Do nothing when tool starts. Examples using DeepEvalCallbackHandler¶ Confident
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.confident_callback.DeepEvalCallbackHandler.html
2bed9a72461d-0
langchain.callbacks.flyte_callback.FlyteCallbackHandler¶ class langchain.callbacks.flyte_callback.FlyteCallbackHandler[source]¶ This callback handler that is used within a Flyte task. Initialize callback handler. Attributes always_verbose Whether to call verbose callbacks even if verbose is False. ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__() Initialize callback handler. get_custom_callback_meta() on_agent_action(action, **kwargs) Run on agent action. on_agent_finish(finish, **kwargs) Run when agent ends running. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run when LLM generates a new token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...])
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.flyte_callback.FlyteCallbackHandler.html
2bed9a72461d-1
on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Run when agent is ending. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running. reset_callback_meta() Reset the callback metadata. __init__() → None[source]¶ Initialize callback handler. get_custom_callback_meta() → Dict[str, Any]¶ on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Run when agent ends running. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.flyte_callback.FlyteCallbackHandler.html
2bed9a72461d-2
Run when a chat model starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run when LLM generates a new token. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Run when agent is ending. on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.flyte_callback.FlyteCallbackHandler.html
2bed9a72461d-3
Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Run when tool starts running. reset_callback_meta() → None¶ Reset the callback metadata. Examples using FlyteCallbackHandler¶ Flyte
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.flyte_callback.FlyteCallbackHandler.html
7ba21ae4d03f-0
langchain.callbacks.tracers.schemas.TracerSessionBase¶ class langchain.callbacks.tracers.schemas.TracerSessionBase[source]¶ Bases: TracerSessionV1Base Base class for TracerSession. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be parsed to form a valid model. param extra: Optional[Dict[str, Any]] = None¶ param name: Optional[str] = None¶ param start_time: datetime.datetime [Optional]¶ param tenant_id: uuid.UUID [Required]¶ classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶ Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶ Duplicate a model, optionally choose which fields to include, exclude and change. Parameters include – fields to include in new model exclude – fields to exclude from new model, as with values this takes precedence over include update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data deep – set to True to make a deep copy of the model Returns new model instance
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.TracerSessionBase.html
7ba21ae4d03f-1
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) → DictStrAny¶ Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ Generate a JSON representation of the model, include and exclude arguments as per dict(). encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps(). classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.TracerSessionBase.html
7ba21ae4d03f-2
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.TracerSessionBase.html
fd5a95c83479-0
langchain.callbacks.streamlit.mutable_expander.ChildType¶ class langchain.callbacks.streamlit.mutable_expander.ChildType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶ The enumerator of the child type. MARKDOWN = 'MARKDOWN'¶ EXCEPTION = 'EXCEPTION'¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.mutable_expander.ChildType.html
fa46d69dd32d-0
langchain.callbacks.tracers.stdout.FunctionCallbackHandler¶ class langchain.callbacks.tracers.stdout.FunctionCallbackHandler(function: Callable[[str], None], **kwargs: Any)[source]¶ Tracer that calls a function with a single str parameter. Attributes ignore_agent Whether to ignore agent callbacks. ignore_chain Whether to ignore chain callbacks. ignore_chat_model Whether to ignore chat model callbacks. ignore_llm Whether to ignore LLM callbacks. ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. name raise_error run_inline Methods __init__(function, **kwargs) get_breadcrumbs(run) get_parents(run) on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, *, run_id[, inputs]) End a trace for a chain run. on_chain_error(error, *[, inputs]) Handle an error for a chain run. on_chain_start(serialized, inputs, *, run_id) Start a trace for a chain run. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id, **kwargs) End a trace for an LLM run. on_llm_error(error, *, run_id, **kwargs) Handle an error for an LLM run. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Start a trace for an LLM run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.stdout.FunctionCallbackHandler.html
fa46d69dd32d-1
Start a trace for an LLM run. on_retriever_end(documents, *, run_id, **kwargs) Run when Retriever ends running. on_retriever_error(error, *, run_id, **kwargs) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id, **kwargs) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id, **kwargs) End a trace for a tool run. on_tool_error(error, *, run_id, **kwargs) Handle an error for a tool run. on_tool_start(serialized, input_str, *, run_id) Start a trace for a tool run. __init__(function: Callable[[str], None], **kwargs: Any) → None[source]¶ get_breadcrumbs(run: Run) → str[source]¶ get_parents(run: Run) → List[Run][source]¶ on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → Run¶ End a trace for a chain run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.stdout.FunctionCallbackHandler.html
fa46d69dd32d-2
End a trace for a chain run. on_chain_error(error: BaseException, *, inputs: Optional[Dict[str, Any]] = None, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for a chain run. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, run_type: Optional[str] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for a chain run. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Run when a chat model starts running. on_llm_end(response: LLMResult, *, run_id: UUID, **kwargs: Any) → Run¶ End a trace for an LLM run. on_llm_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for an LLM run. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Run¶ Run on new LLM token. Only available when streaming is enabled.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.stdout.FunctionCallbackHandler.html
fa46d69dd32d-3
Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for an LLM run. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, **kwargs: Any) → Run¶ Run on a retry event. on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, **kwargs: Any) → Run¶ End a trace for a tool run. on_tool_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Handle an error for a tool run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.stdout.FunctionCallbackHandler.html
fa46d69dd32d-4
Handle an error for a tool run. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Start a trace for a tool run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.stdout.FunctionCallbackHandler.html
426df4f851db-0
langchain.callbacks.streamlit.streamlit_callback_handler.LLMThought¶ class langchain.callbacks.streamlit.streamlit_callback_handler.LLMThought(parent_container: DeltaGenerator, labeler: LLMThoughtLabeler, expanded: bool, collapse_on_complete: bool)[source]¶ A thought in the LLM’s thought stream. Initialize the LLMThought. Parameters parent_container – The container we’re writing into. labeler – The labeler to use for this thought. expanded – Whether the thought should be expanded by default. collapse_on_complete – Whether the thought should be collapsed. Attributes container The container we're writing into. last_tool The last tool executed by this thought Methods __init__(parent_container, labeler, ...) Initialize the LLMThought. clear() Remove the thought from the screen. complete([final_label]) Finish the thought. on_agent_action(action[, color]) on_llm_end(response, **kwargs) on_llm_error(error, **kwargs) on_llm_new_token(token, **kwargs) on_llm_start(serialized, prompts) on_tool_end(output[, color, ...]) on_tool_error(error, **kwargs) on_tool_start(serialized, input_str, **kwargs) __init__(parent_container: DeltaGenerator, labeler: LLMThoughtLabeler, expanded: bool, collapse_on_complete: bool)[source]¶ Initialize the LLMThought. Parameters parent_container – The container we’re writing into. labeler – The labeler to use for this thought. expanded – Whether the thought should be expanded by default. collapse_on_complete – Whether the thought should be collapsed. clear() → None[source]¶ Remove the thought from the screen. A cleared thought can’t be reused.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.LLMThought.html
426df4f851db-1
Remove the thought from the screen. A cleared thought can’t be reused. complete(final_label: Optional[str] = None) → None[source]¶ Finish the thought. on_agent_action(action: AgentAction, color: Optional[str] = None, **kwargs: Any) → Any[source]¶ on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ on_llm_start(serialized: Dict[str, Any], prompts: List[str]) → None[source]¶ on_tool_end(output: str, color: Optional[str] = None, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) → None[source]¶ on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.LLMThought.html