From 3d15498612932b9fdd0b1ac6bd05d6f9301e8d44 Mon Sep 17 00:00:00 2001 From: aditya thomas Date: Mon, 11 Mar 2024 20:10:11 +0530 Subject: [PATCH] docs: Update callbacks documentation (#18899) **Description:** Update callbacks documentation **Issue:** Change some module imports and a method invocation to reflect the current LangChainAPI **Dependencies:** None --- docs/docs/modules/callbacks/custom_callbacks.ipynb | 4 ++-- docs/docs/modules/callbacks/index.mdx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/docs/modules/callbacks/custom_callbacks.ipynb b/docs/docs/modules/callbacks/custom_callbacks.ipynb index 8adaafd6e0..b3cb2fb192 100644 --- a/docs/docs/modules/callbacks/custom_callbacks.ipynb +++ b/docs/docs/modules/callbacks/custom_callbacks.ipynb @@ -52,7 +52,7 @@ } ], "source": [ - "from langchain.callbacks.base import BaseCallbackHandler\n", + "from langchain_core.callbacks import BaseCallbackHandler\n", "from langchain_core.messages import HumanMessage\n", "from langchain_openai import ChatOpenAI\n", "\n", @@ -66,7 +66,7 @@ "# Additionally, we pass in a list with our custom handler\n", "chat = ChatOpenAI(max_tokens=25, streaming=True, callbacks=[MyCustomHandler()])\n", "\n", - "chat([HumanMessage(content=\"Tell me a joke\")])" + "chat.invoke([HumanMessage(content=\"Tell me a joke\")])" ] }, { diff --git a/docs/docs/modules/callbacks/index.mdx b/docs/docs/modules/callbacks/index.mdx index 817e3c0794..7be32ccd0e 100644 --- a/docs/docs/modules/callbacks/index.mdx +++ b/docs/docs/modules/callbacks/index.mdx @@ -79,15 +79,15 @@ class BaseCallbackHandler: ## Get started -LangChain provides a few built-in handlers that you can use to get started. These are available in the `langchain/callbacks` module. The most basic handler is the `StdOutCallbackHandler`, which simply logs all events to `stdout`. +LangChain provides a few built-in handlers that you can use to get started. These are available in the `langchain_core/callbacks` module. The most basic handler is the `StdOutCallbackHandler`, which simply logs all events to `stdout`. **Note**: when the `verbose` flag on the object is set to true, the `StdOutCallbackHandler` will be invoked even without being explicitly passed in. ```python -from langchain.callbacks import StdOutCallbackHandler +from langchain_core.callbacks import StdOutCallbackHandler from langchain.chains import LLMChain from langchain_openai import OpenAI -from langchain.prompts import PromptTemplate +from langchain_core.prompts import PromptTemplate handler = StdOutCallbackHandler() llm = OpenAI() @@ -160,5 +160,5 @@ The `verbose` argument is available on most objects throughout the API (Chains, ### When do you want to use each of these? - Constructor callbacks are most useful for use cases such as logging, monitoring, etc., which are _not specific to a single request_, but rather to the entire chain. For example, if you want to log all the requests made to an `LLMChain`, you would pass a handler to the constructor. -- Request callbacks are most useful for use cases such as streaming, where you want to stream the output of a single request to a specific websocket connection, or other similar use cases. For example, if you want to stream the output of a single request to a websocket, you would pass a handler to the `call()` method +- Request callbacks are most useful for use cases such as streaming, where you want to stream the output of a single request to a specific websocket connection, or other similar use cases. For example, if you want to stream the output of a single request to a websocket, you would pass a handler to the `invoke()` method