mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 05:43:55 +00:00
docs: more standard test stubs (#28202)
This commit is contained in:
parent
0a06732d3e
commit
97f752c92d
@ -2,4 +2,8 @@
|
|||||||
|
|
||||||
- [**Documentation**](documentation/index.mdx): Help improve our docs, including this one!
|
- [**Documentation**](documentation/index.mdx): Help improve our docs, including this one!
|
||||||
- [**Code**](code/index.mdx): Help us write code, fix bugs, or improve our infrastructure.
|
- [**Code**](code/index.mdx): Help us write code, fix bugs, or improve our infrastructure.
|
||||||
- [**Integrations**](integrations/index.mdx): Help us integrate with your favorite vendors and tools.
|
|
||||||
|
## Integrations
|
||||||
|
|
||||||
|
- [**Start Here**](integrations/index.mdx): Help us integrate with your favorite vendors and tools.
|
||||||
|
- [**Standard Tests**](integrations/standard_tests): Ensure your integration passes an expected set of tests.
|
||||||
|
@ -6,9 +6,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# How to add standard tests to an integration\n",
|
"# How to add standard tests to an integration\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Implementing standard tests \n",
|
"When creating either a custom class for yourself or a new tool to publish in a LangChain integration, it is important to add standard tests to ensure it works as expected. This guide will show you how to add standard tests to a tool, and you can **[Skip to the test templates](#standard-test-templates-per-component)** for implementing tests for each integration.\n",
|
||||||
"\n",
|
|
||||||
"When creating either a custom class for yourself or a new tool to publish in a LangChain integration, it is important to add standard tests to ensure it works as expected. This guide will show you how to add standard tests to a tool, and the templates for implementing each different kind of integration are linked [at the bottom](#standard-test-templates-per-component).\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"## Setup\n",
|
"## Setup\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -20,7 +18,7 @@
|
|||||||
":::note\n",
|
":::note\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Because added tests in new versions of `langchain-tests` will always break your CI/CD pipelines, we recommend pinning the \n",
|
"Because added tests in new versions of `langchain-tests` will always break your CI/CD pipelines, we recommend pinning the \n",
|
||||||
"version of `langchain-tests==0.3.0` to avoid unexpected changes.\n",
|
"version of `langchain-tests==0.3.2` to avoid unexpected changes.\n",
|
||||||
"\n",
|
"\n",
|
||||||
":::"
|
":::"
|
||||||
]
|
]
|
||||||
@ -31,7 +29,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%pip install -U langchain-core langchain-tests==0.3.0 pytest pytest-socket"
|
"%pip install -U langchain-core langchain-tests==0.3.2 pytest pytest-socket"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -217,7 +215,11 @@
|
|||||||
"class TestChatParrotLinkUnit(ChatModelUnitTests):\n",
|
"class TestChatParrotLinkUnit(ChatModelUnitTests):\n",
|
||||||
" @property\n",
|
" @property\n",
|
||||||
" def chat_model_class(self) -> Type[ChatParrotLink]:\n",
|
" def chat_model_class(self) -> Type[ChatParrotLink]:\n",
|
||||||
" return ChatParrotLink"
|
" return ChatParrotLink\n",
|
||||||
|
"\n",
|
||||||
|
" @property\n",
|
||||||
|
" def chat_model_params(self) -> dict:\n",
|
||||||
|
" return {\"model\": \"bird-brain-001\", \"temperature\": 0}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -248,12 +250,54 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"</details>\n",
|
"</details>\n",
|
||||||
|
"<details>\n",
|
||||||
|
" <summary>Embedding Models</summary>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# title=\"tests/unit_tests/test_embeddings.py\"\n",
|
||||||
|
"from typing import Tuple, Type\n",
|
||||||
"\n",
|
"\n",
|
||||||
"<div style={{display:\"none\"}}>\n",
|
"from langchain_parrot_link.embeddings import ParrotLinkEmbeddings\n",
|
||||||
"Work in progress:\n",
|
"from langchain_standard_tests.unit_tests import EmbeddingsUnitTests\n",
|
||||||
"<details>\n",
|
"\n",
|
||||||
" <summary>Retrievers</summary>\n",
|
"\n",
|
||||||
" TODO"
|
"class TestParrotLinkEmbeddingsUnit(EmbeddingsUnitTests):\n",
|
||||||
|
" @property\n",
|
||||||
|
" def embeddings_class(self) -> Type[ParrotLinkEmbeddings]:\n",
|
||||||
|
" return ParrotLinkEmbeddings\n",
|
||||||
|
"\n",
|
||||||
|
" @property\n",
|
||||||
|
" def embedding_model_params(self) -> dict:\n",
|
||||||
|
" return {\"model\": \"nest-embed-001\", \"temperature\": 0}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# title=\"tests/integration_tests/test_embeddings.py\"\n",
|
||||||
|
"from typing import Type\n",
|
||||||
|
"\n",
|
||||||
|
"from langchain_parrot_link.embeddings import ParrotLinkEmbeddings\n",
|
||||||
|
"from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"class TestParrotLinkEmbeddingsIntegration(EmbeddingsIntegrationTests):\n",
|
||||||
|
" @property\n",
|
||||||
|
" def embeddings_class(self) -> Type[ParrotLinkEmbeddings]:\n",
|
||||||
|
" return ParrotLinkEmbeddings\n",
|
||||||
|
"\n",
|
||||||
|
" @property\n",
|
||||||
|
" def embedding_model_params(self) -> dict:\n",
|
||||||
|
" return {\"model\": \"nest-embed-001\", \"temperature\": 0}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -262,26 +306,83 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"</details>\n",
|
"</details>\n",
|
||||||
"<details>\n",
|
"<details>\n",
|
||||||
" <summary>Vector Stores</summary>\n",
|
" <summary>Tools/Toolkits</summary>\n",
|
||||||
" TODO"
|
" Note: The standard tests for tools/toolkits are implemented in the example in the main body of this guide too."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# title=\"tests/unit_tests/test_tools.py\"\n",
|
||||||
|
"from typing import Type\n",
|
||||||
|
"\n",
|
||||||
|
"from langchain_parrot_link.tools import ParrotMultiplyTool\n",
|
||||||
|
"from langchain_standard_tests.unit_tests import ToolsUnitTests\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"class TestParrotMultiplyToolUnit(ToolsUnitTests):\n",
|
||||||
|
" @property\n",
|
||||||
|
" def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n",
|
||||||
|
" return ParrotMultiplyTool\n",
|
||||||
|
"\n",
|
||||||
|
" def tool_constructor_params(self) -> dict:\n",
|
||||||
|
" # if your tool constructor instead required initialization arguments like\n",
|
||||||
|
" # `def __init__(self, some_arg: int):`, you would return those here\n",
|
||||||
|
" # as a dictionary, e.g.: `return {'some_arg': 42}`\n",
|
||||||
|
" return {}\n",
|
||||||
|
"\n",
|
||||||
|
" def tool_invoke_params_example(self) -> dict:\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" Returns a dictionary representing the \"args\" of an example tool call.\n",
|
||||||
|
"\n",
|
||||||
|
" This should NOT be a ToolCall dict - i.e. it should not\n",
|
||||||
|
" have {\"name\", \"id\", \"args\"} keys.\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" return {\"a\": 2, \"b\": 3}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# title=\"tests/integration_tests/test_tools.py\"\n",
|
||||||
|
"from typing import Type\n",
|
||||||
|
"\n",
|
||||||
|
"from langchain_parrot_link.tools import ParrotMultiplyTool\n",
|
||||||
|
"from langchain_standard_tests.integration_tests import ToolsIntegrationTests\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):\n",
|
||||||
|
" @property\n",
|
||||||
|
" def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n",
|
||||||
|
" return ParrotMultiplyTool\n",
|
||||||
|
"\n",
|
||||||
|
" def tool_constructor_params(self) -> dict:\n",
|
||||||
|
" # if your tool constructor instead required initialization arguments like\n",
|
||||||
|
" # `def __init__(self, some_arg: int):`, you would return those here\n",
|
||||||
|
" # as a dictionary, e.g.: `return {'some_arg': 42}`\n",
|
||||||
|
" return {}\n",
|
||||||
|
"\n",
|
||||||
|
" def tool_invoke_params_example(self) -> dict:\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" Returns a dictionary representing the \"args\" of an example tool call.\n",
|
||||||
|
"\n",
|
||||||
|
" This should NOT be a ToolCall dict - i.e. it should not\n",
|
||||||
|
" have {\"name\", \"id\", \"args\"} keys.\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" return {\"a\": 2, \"b\": 3}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"</details>\n",
|
"</details>"
|
||||||
"<details>\n",
|
|
||||||
" <summary>Embedding Models</summary>\n",
|
|
||||||
" TODO"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"</details>\n",
|
|
||||||
"</div>"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -17,6 +17,7 @@ More coming soon! We are working on tutorials to help you make your first contri
|
|||||||
- [**Documentation**](how_to/documentation/index.mdx): Help improve our docs, including this one!
|
- [**Documentation**](how_to/documentation/index.mdx): Help improve our docs, including this one!
|
||||||
- [**Code**](how_to/code/index.mdx): Help us write code, fix bugs, or improve our infrastructure.
|
- [**Code**](how_to/code/index.mdx): Help us write code, fix bugs, or improve our infrastructure.
|
||||||
- [**Integrations**](how_to/integrations/index.mdx): Help us integrate with your favorite vendors and tools.
|
- [**Integrations**](how_to/integrations/index.mdx): Help us integrate with your favorite vendors and tools.
|
||||||
|
- [**Standard Tests**](how_to/integrations/standard_tests): Ensure your integration passes an expected set of tests.
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user