Tony20100/langchain_full huggingface dataset:
langchain_community.callbacks.context_callback.ContextCallbackHandler¶
class langchain_community.callbacks.context_callback.ContextCallbackHandler(token: str = '', verbose: bool = False, **kwargs: Any)[source]¶
Callback Handler that records transcripts to the Context service.
(https://context.ai).
Keyword Arguments
token (optional) – The token with which to authenticate requests to Context.
Visit https://with.context.ai/settings to generate a token.
If not provided, the value of the CONTEXT_TOKEN environment
variable will be used.
Raises
ImportError – if the context-python package is not installed.
Parameters
token (str) – 
verbose (bool) – 
kwargs (Any) – 
Chat Example:>>> from langchain_community.llms import ChatOpenAI
>>> from langchain_community.callbacks import ContextCallbackHandler
>>> context_callback = ContextCallbackHandler(
...     token="<CONTEXT_TOKEN_HERE>",
... )
>>> chat = ChatOpenAI(
...     temperature=0,
...     headers={"user_id": "123"},
...     callbacks=[context_callback],
...     openai_api_key="API_KEY_HERE",
... )
>>> messages = [
...     SystemMessage(content="You translate English to French."),
...     HumanMessage(content="I love programming with LangChain."),
... ]
>>> chat.invoke(messages)
Chain Example:>>> from langchain.chains import LLMChain
>>> from langchain_community.chat_models import ChatOpenAI
>>> from langchain_community.callbacks import ContextCallbackHandler
>>> context_callback = ContextCallbackHandler(
...     token="<CONTEXT_TOKEN_HERE>",
... )
>>> human_message_prompt = HumanMessagePromptTemplate(
...     prompt=PromptTemplate(
...         template="What is a good name for a company that makes {product}?",
...         input_variables=["product"],
...    ),
... )
...         input_variables=["product"],
...    ),
... )
>>> chat_prompt_template = ChatPromptTemplate.from_messages(
...   [human_message_prompt]
... )
>>> callback = ContextCallbackHandler(token)
>>> # Note: the same callback object must be shared between the
...   LLM and the chain.
>>> chat = ChatOpenAI(temperature=0.9, callbacks=[callback])
>>> chain = LLMChain(
...   llm=chat,
...   prompt=chat_prompt_template,
...   callbacks=[callback]
... )
>>> chain.run("colorful socks")
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__([token, verbose])
on_agent_action(action, *, run_id[, ...])
Run on agent action.
on_agent_finish(finish, *, run_id[, ...])
Run on agent end.
on_chain_end(outputs, **kwargs)
Run when chain ends.
on_chain_error(error, *, run_id[, parent_run_id])
Run when chain errors.
on_chain_start(serialized, inputs, **kwargs)
Run when chain starts.
on_chat_model_start(serialized, messages, *, ...)
Run when the chat model is started.
on_llm_end(response, **kwargs)
Run when LLM ends.
on_llm_error(error, *, run_id[, parent_run_id])
on_llm_error(error, *, run_id[, parent_run_id])
Run when LLM errors. :param error: The error that occurred. :type error: BaseException :param kwargs: Additional keyword arguments. - response (LLMResult): The response which was generated before                    the error occurred. :type kwargs: Any.
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__(token: str = '', verbose: bool = False, **kwargs: Any) → None[source]¶
Parameters
token (str) – 
verbose (bool) – 
kwargs (Any) – 
Return type
None
verbose (bool) – 
kwargs (Any) – 
Return type
None
on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent action.
Parameters
action (AgentAction) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent end.
Parameters
finish (AgentFinish) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶
Run when chain ends.
Parameters
outputs (Dict[str, Any]) – 
kwargs (Any) – 
Return type
None
on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run when chain errors.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶
Run when chain starts.
Parameters
serialized (Dict[str, Any]) – 
inputs (Dict[str, Any]) – 
kwargs (Any) – 
Return type
None
kwargs (Any) – 
Return type
None
on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, **kwargs: Any) → Any[source]¶
Run when the chat model is started.
Parameters
serialized (Dict[str, Any]) – 
messages (List[List[BaseMessage]]) – 
run_id (UUID) – 
kwargs (Any) – 
Return type
Any
on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶
Run when LLM ends.
Parameters
response (LLMResult) – 
kwargs (Any) – 
Return type
None
on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run when LLM errors.
:param error: The error that occurred.
:type error: BaseException
:param kwargs: Additional keyword arguments.
response (LLMResult): The response which was generated beforethe error occurred.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
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) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) –
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
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.
ATTENTION: This method is called for non-chat models (regular LLMs). Ifyou’re implementing a handler for a chat model,
you should use on_chat_model_start instead.
Parameters
serialized (Dict[str, Any]) – 
prompts (List[str]) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
Any
on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run when Retriever ends running.
Parameters
documents (Sequence[Document]) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run when Retriever errors.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
kwargs (Any) – 
Return type
Any
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.
Parameters
serialized (Dict[str, Any]) – 
query (str) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
Any
on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on a retry event.
Parameters
retry_state (RetryCallState) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on arbitrary text.
Parameters
text (str) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
on_tool_end(output: Any, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run when tool ends running.
Parameters
output (Any) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
kwargs (Any) – 
Return type
Any
on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run when tool errors.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
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, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶
Run when tool starts running.
Parameters
serialized (Dict[str, Any]) – 
input_str (str) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
inputs (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
Any
Examples using ContextCallbackHandler¶
Context
langchain_core.callbacks.manager.AsyncCallbackManagerForToolRun¶
class langchain_core.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.
get_sync()
Get the equivalent sync RunManager.
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.
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.
Return type
None
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
get_sync() → CallbackManagerForToolRun[source]¶
Get the equivalent sync RunManager.
Returns
The sync RunManager.
Return type
CallbackManagerForToolRun
Returns
The sync RunManager.
Return type
CallbackManagerForToolRun
async on_retry(retry_state: RetryCallState, **kwargs: Any) → None¶
Run on a retry event.
Parameters
retry_state (RetryCallState) – 
kwargs (Any) – 
Return type
None
async on_text(text: str, **kwargs: Any) → Any¶
Run when text is received.
Parameters
text (str) – The received text.
kwargs (Any) – 
Returns
The result of the callback.
Return type
Any
async on_tool_end(output: Any, **kwargs: Any) → None[source]¶
Run when tool ends running.
Parameters
output (Any) – The output of the tool.
kwargs (Any) – 
Return type
None
async on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶
Run when tool errors.
Parameters
error (Exception or KeyboardInterrupt) – The error.
kwargs (Any) – 
Return type
None
Examples using AsyncCallbackManagerForToolRun¶
How to add a semantic layer over graph database
How to create custom tools
langchain.callbacks.streaming_aiter.AsyncIteratorCallbackHandler¶
class langchain.callbacks.streaming_aiter.AsyncIteratorCallbackHandler[source]¶
Callback handler that returns an async iterator.
Attributes
always_verbose
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
queue
done
Methods
__init__()
aiter()
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[, ...])
Run when chain ends running.
on_chain_error(error, *, 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)
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 on retriever end.
on_retriever_error(error, *, run_id[, ...])
Run on retriever error.
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]¶
Return type
None
async aiter() → AsyncIterator[str][source]¶
Return type
AsyncIterator[str]
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.
Parameters
action (AgentAction) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
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.
Parameters
finish (AgentFinish) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
kwargs (Any) – 
Return type
None
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.
Parameters
outputs (Dict[str, Any]) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
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.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
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.
Parameters
serialized (Dict[str, Any]) – 
inputs (Dict[str, Any]) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
None
kwargs (Any) – 
Return type
None
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.
ATTENTION: This method is called for chat models. If you’re implementinga handler for a non-chat model, you should use on_llm_start instead.
Parameters
serialized (Dict[str, Any]) – 
messages (List[List[BaseMessage]]) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
Any
async on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶
Run when LLM ends running.
Parameters
response (LLMResult) – 
kwargs (Any) – 
Return type
None
async on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶
Run when LLM errors.
Parameters
error (BaseException) – The error that occurred.
kwargs (Any) – Additional keyword arguments.
- response (LLMResult): The response which was generated before
the error occurred.
Return type
None
async on_llm_new_token(token: str, **kwargs: Any) → None[source]¶
Run on new LLM token. Only available when streaming is enabled.
Parameters
token (str) – 
kwargs (Any) – 
Return type
None
token (str) – 
kwargs (Any) – 
Return type
None
async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶
Run when LLM starts running.
ATTENTION: This method is called for non-chat models (regular LLMs). Ifyou’re implementing a handler for a chat model,
you should use on_chat_model_start instead.
Parameters
serialized (Dict[str, Any]) – 
prompts (List[str]) – 
kwargs (Any) – 
Return type
None
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.
Parameters
documents (Sequence[Document]) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
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.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
kwargs (Any) – 
Return type
None
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.
Parameters
serialized (Dict[str, Any]) – 
query (str) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
None
async on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on a retry event.
Parameters
retry_state (RetryCallState) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
kwargs (Any) – 
Return type
Any
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.
Parameters
text (str) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
async on_tool_end(output: Any, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None¶
Run when tool ends running.
Parameters
output (Any) –
Run when tool ends running.
Parameters
output (Any) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
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.
Parameters
error (BaseException) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
kwargs (Any) – 
Return type
None
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, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → None¶
Run when tool starts running.
Parameters
serialized (Dict[str, Any]) – 
input_str (str) – 
run_id (UUID) – 
parent_run_id (Optional[UUID]) – 
tags (Optional[List[str]]) – 
metadata (Optional[Dict[str, Any]]) – 
inputs (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
None
langchain_community.callbacks.infino_callback.get_num_tokens¶
langchain_community.callbacks.infino_callback.get_num_tokens(string: str, openai_model_name: str) → int[source]¶
Calculate num tokens for OpenAI with tiktoken package.
Official documentation: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
Parameters
string (str) – 
openai_model_name (str) – 
Return type
int