From e87f81b3ec21d343a1349800f1e2439a0f3916a9 Mon Sep 17 00:00:00 2001 From: Ankush Gola <9536492+agola11@users.noreply.github.com> Date: Sun, 30 Apr 2023 19:13:01 -0700 Subject: [PATCH] add more color to callbacks docs (#3856) --- docs/modules/callbacks/getting_started.ipynb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/modules/callbacks/getting_started.ipynb b/docs/modules/callbacks/getting_started.ipynb index 109907bd..f48c418a 100644 --- a/docs/modules/callbacks/getting_started.ipynb +++ b/docs/modules/callbacks/getting_started.ipynb @@ -15,9 +15,16 @@ "id": "29dd6333-307c-43df-b848-65001c01733b", "metadata": {}, "source": [ - "LangChain provides a callback system that allows you to hook into the various stages of your LLM application. This is useful for logging, [monitoring](https://python.langchain.com/en/latest/tracing.html), [streaming](https://python.langchain.com/en/latest/modules/models/llms/examples/streaming_llm.html), and other tasks.\n", + "LangChain provides a callbacks system that allows you to hook into the various stages of your LLM application. This is useful for logging, [monitoring](https://python.langchain.com/en/latest/tracing.html), [streaming](https://python.langchain.com/en/latest/modules/models/llms/examples/streaming_llm.html), and other tasks.\n", "\n", - "You can subscribe to these events by using the `callbacks` argument available throughout the API. This argument list of handler objects, which are expected to implement one or more of the methods described in the API docs." + "You can subscribe to these events by using the `callbacks` argument available throughout the API. This argument is list of handler objects, which are expected to implement one or more of the methods described below in more detail. There are two main callbacks mechanisms:\n", + "\n", + "* *Constructor callbacks* will be used for all calls made on that object, and will be scoped to that object only, i.e. if you pass a handler to the `LLMChain` constructor, it will not be used by the model attached to that chain. \n", + "* *Request callbacks* will be used for that specific request only, and all sub-requests that it contains (eg. a call to an `LLMChain` triggers a call to a Model, which uses the same handler passed through). These are explicitly passed through.\n", + "\n", + "\n", + "**Advanced:** When you create a custom chain you can easily set it up to use the same callback system as all the built-in chains. \n", + "`_call`, `_generate`, `_run`, and equivalent async methods on Chains / LLMs / Chat Models / Agents / Tools now receive a 2nd argument called `run_manager` which is bound to that run, and contains the logging methods that can be used by that object (i.e. `on_llm_new_token`). This is useful when constructing a custom chain. See this guide for more information on how to [create custom chains and use callbacks inside them.](https://python.langchain.com/en/latest/modules/chains/generic/custom_chain.html)" ] }, {