nat.plugins.langchain.callback_handler#
Attributes#
Classes#
Callback Handler that tracks NIM info. |
Functions#
|
Module Contents#
- logger#
- class LangchainProfilerHandler#
Bases:
langchain_core.callbacks.AsyncCallbackHandler,nat.data_models.profiler_callback.BaseProfilerCallbackCallback Handler that tracks NIM info.
- raise_error = True#
Whether to raise an error if an exception occurs.
- run_inline = True#
Whether to run the callback inline.
- _lock#
- last_call_ts#
- step_manager#
- _state#
- _run_id_to_model_name#
- _run_id_to_llm_input#
- _run_id_to_tool_input#
- _run_id_to_start_time#
- _extract_token_base_model( ) nat.data_models.token_usage.TokenUsageBaseModel#
- async on_llm_start(serialized: dict[str, Any], prompts: list[str], \*\*kwargs: Any) None#
Run when the model starts running.
- Args:
serialized: The serialized LLM. prompts: The prompts. run_id: The ID of the current run. parent_run_id: The ID of the parent run. tags: The tags. metadata: The metadata. **kwargs: Additional keyword arguments.
- async on_chat_model_start(serialized: dict[str, Any], messages: list[list[langchain_core.messages.BaseMessage]], *, run_id: uuid.UUID, parent_run_id: uuid.UUID | None = None, tags: list[str] | None = None, metadata: dict[str, Any] | None = None, \*\*kwargs: Any) Any#
Run when a chat model starts running.
- Args:
serialized: The serialized chat model. messages: The messages. Must be a list of message lists — this is a required positional argument and must be present in any override. run_id: The ID of the current run. parent_run_id: The ID of the parent run. tags: The tags. metadata: The metadata. **kwargs: Additional keyword arguments.
- async on_llm_end(
- response: langchain_core.outputs.LLMResult,
- \*\*kwargs: Any,
Collect token usage.
- async on_tool_start(serialized: dict[str, Any], input_str: str, *, run_id: uuid.UUID, parent_run_id: uuid.UUID | None = None, tags: list[str] | None = None, metadata: dict[str, Any] | None = None, inputs: dict[str, Any] | None = None, \*\*kwargs: Any) Any#
Run when the tool starts running.
- Args:
serialized: The serialized tool. input_str: The input string. run_id: The ID of the current run. parent_run_id: The ID of the parent run. tags: The tags. metadata: The metadata. inputs: The inputs. **kwargs: Additional keyword arguments.
- async on_tool_end(
- output: Any,
- *,
- run_id: uuid.UUID,
- parent_run_id: uuid.UUID | None = None,
- \*\*kwargs: Any,
Run when the tool ends running.
- Args:
output: The output of the tool. run_id: The ID of the current run. parent_run_id: The ID of the parent run. tags: The tags. **kwargs: Additional keyword arguments.