From 17c4ec481255823fd00cef68f1c888460466de0c Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Wed, 14 Jun 2023 22:01:58 +0100 Subject: [PATCH] Add docs for tags (#6155) Fixes # (issue) #### Before submitting #### Who can review? Tag maintainers/contributors who might be interested: --- docs/modules/callbacks/getting_started.ipynb | 34 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/modules/callbacks/getting_started.ipynb b/docs/modules/callbacks/getting_started.ipynb index f48c418aa2..c57b55dfe7 100644 --- a/docs/modules/callbacks/getting_started.ipynb +++ b/docs/modules/callbacks/getting_started.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "23234b50-e6c6-4c87-9f97-259c15f36894", "metadata": { @@ -11,6 +12,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "29dd6333-307c-43df-b848-65001c01733b", "metadata": {}, @@ -28,6 +30,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "2b6d7dba-cd20-472a-ae05-f68675cc9ea4", "metadata": {}, @@ -36,6 +39,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "e4592215-6604-47e2-89ff-5db3af6d1e40", "metadata": { @@ -50,6 +54,11 @@ " self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any\n", " ) -> Any:\n", " \"\"\"Run when LLM starts running.\"\"\"\n", + " \n", + " def on_chat_model_start(\n", + " self, serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs: Any\n", + " ) -> Any:\n", + " \"\"\"Run when Chat Model starts running.\"\"\"\n", "\n", " def on_llm_new_token(self, token: str, **kwargs: Any) -> Any:\n", " \"\"\"Run on new LLM token. Only available when streaming is enabled.\"\"\"\n", @@ -100,6 +109,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "cbccd7d1", "metadata": {}, @@ -108,8 +118,8 @@ "\n", "The `callbacks` argument is available on most objects throughout the API (Chains, Models, Tools, Agents, etc.) in two different places:\n", "\n", - "- **Constructor callbacks**: defined in the constructor, eg. `LLMChain(callbacks=[handler])`, which will be used for all calls made on that object, and will be scoped to that object only, eg. if you pass a handler to the `LLMChain` constructor, it will not be used by the Model attached to that chain.\n", - "- **Request callbacks**: defined in the `call()`/`run()`/`apply()` methods used for issuing a request, eg. `chain.call(inputs, callbacks=[handler])`, which 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 in the `call()` method).\n", + "- **Constructor callbacks**: defined in the constructor, eg. `LLMChain(callbacks=[handler], tags=['a-tag'])`, which will be used for all calls made on that object, and will be scoped to that object only, eg. if you pass a handler to the `LLMChain` constructor, it will not be used by the Model attached to that chain.\n", + "- **Request callbacks**: defined in the `call()`/`run()`/`apply()` methods used for issuing a request, eg. `chain.call(inputs, callbacks=[handler], tags=['a-tag'])`, which 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 in the `call()` method).\n", "\n", "The `verbose` argument is available on most objects throughout the API (Chains, Models, Tools, Agents, etc.) as a constructor argument, eg. `LLMChain(verbose=True)`, and it is equivalent to passing a `ConsoleCallbackHandler` to the `callbacks` argument of that object and all child objects. This is useful for debugging, as it will log all events to the console.\n", "\n", @@ -120,6 +130,18 @@ ] }, { + "attachments": {}, + "cell_type": "markdown", + "id": "46128fb4", + "metadata": {}, + "source": [ + "## Tags\n", + "\n", + "You can add tags to your callbacks by passing a `tags` argument to the `call()`/`run()`/`apply()` methods. This is useful for filtering your logs, eg. if you want to log all requests made to a specific LLMChain, you can add a tag, and then filter your logs by that tag. You can pass tags to both constructor and request callbacks, see the examples above for details. These tags are then passed to the `tags` argument of the \"start\" callback methods, ie. `on_llm_start`, `on_chat_model_start`, `on_chain_start`, `on_tool_start`." + ] + }, + { + "attachments": {}, "cell_type": "markdown", "id": "d3bf3304-43fb-47ad-ae50-0637a17018a2", "metadata": {}, @@ -201,6 +223,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "389c8448-5283-49e3-8c04-dbe1522e202c", "metadata": {}, @@ -268,6 +291,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "bc9785fa-4f71-4797-91a3-4fe7e57d0429", "metadata": { @@ -363,6 +387,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "d26dbb34-fcc3-401c-a115-39c7620d2d65", "metadata": {}, @@ -548,6 +573,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "32b29135-f852-4492-88ed-547275c72c53", "metadata": {}, @@ -556,6 +582,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "fbb606d6-2863-46c5-8347-9f0bdb3805bb", "metadata": {}, @@ -564,6 +591,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "f62cd10c-494c-47d6-aa98-6e926cb9c456", "metadata": {}, @@ -572,6 +600,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "d5a74b3f-3769-4a4f-99c7-b6a3b20a94e2", "metadata": {}, @@ -829,6 +858,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "254fef1b-6b6e-4352-9cf4-363fba895ac7", "metadata": {},