Add docs for tags (#6155)

<!--
Thank you for contributing to LangChain! Your PR will appear in our
release under the title you set. Please make sure it highlights your
valuable contribution.

Replace this with a description of the change, the issue it fixes (if
applicable), and relevant context. List any dependencies required for
this change.

After you're done, someone will review your PR. They may suggest
improvements. If no one reviews your PR within a few days, feel free to
@-mention the same people again, as notifications can get lost.

Finally, we'd love to show appreciation for your contribution - if you'd
like us to shout you out on Twitter, please also include your handle!
-->

<!-- Remove if not applicable -->

Fixes # (issue)

#### Before submitting

<!-- If you're adding a new integration, please include:

1. a test for the integration - favor unit tests that does not rely on
network access.
2. an example notebook showing its use


See contribution guidelines for more information on how to write tests,
lint
etc:


https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
-->

#### Who can review?

Tag maintainers/contributors who might be interested:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11

  Async
  - @agola11

  DataLoaders
  - @eyurtsev

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
This commit is contained in:
Nuno Campos 2023-06-14 22:01:58 +01:00 committed by GitHub
parent 4a649e3b14
commit 17c4ec4812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
{ {
"cells": [ "cells": [
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "23234b50-e6c6-4c87-9f97-259c15f36894", "id": "23234b50-e6c6-4c87-9f97-259c15f36894",
"metadata": { "metadata": {
@ -11,6 +12,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "29dd6333-307c-43df-b848-65001c01733b", "id": "29dd6333-307c-43df-b848-65001c01733b",
"metadata": {}, "metadata": {},
@ -28,6 +30,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "2b6d7dba-cd20-472a-ae05-f68675cc9ea4", "id": "2b6d7dba-cd20-472a-ae05-f68675cc9ea4",
"metadata": {}, "metadata": {},
@ -36,6 +39,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "e4592215-6604-47e2-89ff-5db3af6d1e40", "id": "e4592215-6604-47e2-89ff-5db3af6d1e40",
"metadata": { "metadata": {
@ -50,6 +54,11 @@
" self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any\n", " self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any\n",
" ) -> Any:\n", " ) -> Any:\n",
" \"\"\"Run when LLM starts running.\"\"\"\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", "\n",
" def on_llm_new_token(self, token: str, **kwargs: Any) -> Any:\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", " \"\"\"Run on new LLM token. Only available when streaming is enabled.\"\"\"\n",
@ -100,6 +109,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "cbccd7d1", "id": "cbccd7d1",
"metadata": {}, "metadata": {},
@ -108,8 +118,8 @@
"\n", "\n",
"The `callbacks` argument is available on most objects throughout the API (Chains, Models, Tools, Agents, etc.) in two different places:\n", "The `callbacks` argument is available on most objects throughout the API (Chains, Models, Tools, Agents, etc.) in two different places:\n",
"\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", "- **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])`, 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", "- **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", "\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", "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", "\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", "cell_type": "markdown",
"id": "d3bf3304-43fb-47ad-ae50-0637a17018a2", "id": "d3bf3304-43fb-47ad-ae50-0637a17018a2",
"metadata": {}, "metadata": {},
@ -201,6 +223,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "389c8448-5283-49e3-8c04-dbe1522e202c", "id": "389c8448-5283-49e3-8c04-dbe1522e202c",
"metadata": {}, "metadata": {},
@ -268,6 +291,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "bc9785fa-4f71-4797-91a3-4fe7e57d0429", "id": "bc9785fa-4f71-4797-91a3-4fe7e57d0429",
"metadata": { "metadata": {
@ -363,6 +387,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "d26dbb34-fcc3-401c-a115-39c7620d2d65", "id": "d26dbb34-fcc3-401c-a115-39c7620d2d65",
"metadata": {}, "metadata": {},
@ -548,6 +573,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "32b29135-f852-4492-88ed-547275c72c53", "id": "32b29135-f852-4492-88ed-547275c72c53",
"metadata": {}, "metadata": {},
@ -556,6 +582,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "fbb606d6-2863-46c5-8347-9f0bdb3805bb", "id": "fbb606d6-2863-46c5-8347-9f0bdb3805bb",
"metadata": {}, "metadata": {},
@ -564,6 +591,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "f62cd10c-494c-47d6-aa98-6e926cb9c456", "id": "f62cd10c-494c-47d6-aa98-6e926cb9c456",
"metadata": {}, "metadata": {},
@ -572,6 +600,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "d5a74b3f-3769-4a4f-99c7-b6a3b20a94e2", "id": "d5a74b3f-3769-4a4f-99c7-b6a3b20a94e2",
"metadata": {}, "metadata": {},
@ -829,6 +858,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "254fef1b-6b6e-4352-9cf4-363fba895ac7", "id": "254fef1b-6b6e-4352-9cf4-363fba895ac7",
"metadata": {}, "metadata": {},