Skip to content

Commit 97f752c

Browse files
author
Erick Friis
authored
docs: more standard test stubs (langchain-ai#28202)
1 parent 0a06732 commit 97f752c

File tree

3 files changed

+127
-21
lines changed

3 files changed

+127
-21
lines changed

Diff for: docs/docs/contributing/how_to/index.mdx

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
- [**Documentation**](documentation/index.mdx): Help improve our docs, including this one!
44
- [**Code**](code/index.mdx): Help us write code, fix bugs, or improve our infrastructure.
5-
- [**Integrations**](integrations/index.mdx): Help us integrate with your favorite vendors and tools.
5+
6+
## Integrations
7+
8+
- [**Start Here**](integrations/index.mdx): Help us integrate with your favorite vendors and tools.
9+
- [**Standard Tests**](integrations/standard_tests): Ensure your integration passes an expected set of tests.

Diff for: docs/docs/contributing/how_to/integrations/standard_tests.ipynb

+121-20
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"source": [
77
"# How to add standard tests to an integration\n",
88
"\n",
9-
"Implementing standard tests \n",
10-
"\n",
11-
"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",
9+
"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",
1210
"\n",
1311
"## Setup\n",
1412
"\n",
@@ -20,7 +18,7 @@
2018
":::note\n",
2119
"\n",
2220
"Because added tests in new versions of `langchain-tests` will always break your CI/CD pipelines, we recommend pinning the \n",
23-
"version of `langchain-tests==0.3.0` to avoid unexpected changes.\n",
21+
"version of `langchain-tests==0.3.2` to avoid unexpected changes.\n",
2422
"\n",
2523
":::"
2624
]
@@ -31,7 +29,7 @@
3129
"metadata": {},
3230
"outputs": [],
3331
"source": [
34-
"%pip install -U langchain-core langchain-tests==0.3.0 pytest pytest-socket"
32+
"%pip install -U langchain-core langchain-tests==0.3.2 pytest pytest-socket"
3533
]
3634
},
3735
{
@@ -217,7 +215,11 @@
217215
"class TestChatParrotLinkUnit(ChatModelUnitTests):\n",
218216
" @property\n",
219217
" def chat_model_class(self) -> Type[ChatParrotLink]:\n",
220-
" return ChatParrotLink"
218+
" return ChatParrotLink\n",
219+
"\n",
220+
" @property\n",
221+
" def chat_model_params(self) -> dict:\n",
222+
" return {\"model\": \"bird-brain-001\", \"temperature\": 0}"
221223
]
222224
},
223225
{
@@ -248,22 +250,54 @@
248250
"metadata": {},
249251
"source": [
250252
"</details>\n",
251-
"\n",
252-
"<div style={{display:\"none\"}}>\n",
253-
"Work in progress:\n",
254253
"<details>\n",
255-
" <summary>Retrievers</summary>\n",
256-
" TODO"
254+
" <summary>Embedding Models</summary>"
257255
]
258256
},
259257
{
260-
"cell_type": "markdown",
258+
"cell_type": "code",
259+
"execution_count": null,
261260
"metadata": {},
261+
"outputs": [],
262262
"source": [
263-
"</details>\n",
264-
"<details>\n",
265-
" <summary>Vector Stores</summary>\n",
266-
" TODO"
263+
"# title=\"tests/unit_tests/test_embeddings.py\"\n",
264+
"from typing import Tuple, Type\n",
265+
"\n",
266+
"from langchain_parrot_link.embeddings import ParrotLinkEmbeddings\n",
267+
"from langchain_standard_tests.unit_tests import EmbeddingsUnitTests\n",
268+
"\n",
269+
"\n",
270+
"class TestParrotLinkEmbeddingsUnit(EmbeddingsUnitTests):\n",
271+
" @property\n",
272+
" def embeddings_class(self) -> Type[ParrotLinkEmbeddings]:\n",
273+
" return ParrotLinkEmbeddings\n",
274+
"\n",
275+
" @property\n",
276+
" def embedding_model_params(self) -> dict:\n",
277+
" return {\"model\": \"nest-embed-001\", \"temperature\": 0}"
278+
]
279+
},
280+
{
281+
"cell_type": "code",
282+
"execution_count": null,
283+
"metadata": {},
284+
"outputs": [],
285+
"source": [
286+
"# title=\"tests/integration_tests/test_embeddings.py\"\n",
287+
"from typing import Type\n",
288+
"\n",
289+
"from langchain_parrot_link.embeddings import ParrotLinkEmbeddings\n",
290+
"from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests\n",
291+
"\n",
292+
"\n",
293+
"class TestParrotLinkEmbeddingsIntegration(EmbeddingsIntegrationTests):\n",
294+
" @property\n",
295+
" def embeddings_class(self) -> Type[ParrotLinkEmbeddings]:\n",
296+
" return ParrotLinkEmbeddings\n",
297+
"\n",
298+
" @property\n",
299+
" def embedding_model_params(self) -> dict:\n",
300+
" return {\"model\": \"nest-embed-001\", \"temperature\": 0}"
267301
]
268302
},
269303
{
@@ -272,16 +306,83 @@
272306
"source": [
273307
"</details>\n",
274308
"<details>\n",
275-
" <summary>Embedding Models</summary>\n",
276-
" TODO"
309+
" <summary>Tools/Toolkits</summary>\n",
310+
" Note: The standard tests for tools/toolkits are implemented in the example in the main body of this guide too."
311+
]
312+
},
313+
{
314+
"cell_type": "code",
315+
"execution_count": null,
316+
"metadata": {},
317+
"outputs": [],
318+
"source": [
319+
"# title=\"tests/unit_tests/test_tools.py\"\n",
320+
"from typing import Type\n",
321+
"\n",
322+
"from langchain_parrot_link.tools import ParrotMultiplyTool\n",
323+
"from langchain_standard_tests.unit_tests import ToolsUnitTests\n",
324+
"\n",
325+
"\n",
326+
"class TestParrotMultiplyToolUnit(ToolsUnitTests):\n",
327+
" @property\n",
328+
" def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n",
329+
" return ParrotMultiplyTool\n",
330+
"\n",
331+
" def tool_constructor_params(self) -> dict:\n",
332+
" # if your tool constructor instead required initialization arguments like\n",
333+
" # `def __init__(self, some_arg: int):`, you would return those here\n",
334+
" # as a dictionary, e.g.: `return {'some_arg': 42}`\n",
335+
" return {}\n",
336+
"\n",
337+
" def tool_invoke_params_example(self) -> dict:\n",
338+
" \"\"\"\n",
339+
" Returns a dictionary representing the \"args\" of an example tool call.\n",
340+
"\n",
341+
" This should NOT be a ToolCall dict - i.e. it should not\n",
342+
" have {\"name\", \"id\", \"args\"} keys.\n",
343+
" \"\"\"\n",
344+
" return {\"a\": 2, \"b\": 3}"
345+
]
346+
},
347+
{
348+
"cell_type": "code",
349+
"execution_count": null,
350+
"metadata": {},
351+
"outputs": [],
352+
"source": [
353+
"# title=\"tests/integration_tests/test_tools.py\"\n",
354+
"from typing import Type\n",
355+
"\n",
356+
"from langchain_parrot_link.tools import ParrotMultiplyTool\n",
357+
"from langchain_standard_tests.integration_tests import ToolsIntegrationTests\n",
358+
"\n",
359+
"\n",
360+
"class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):\n",
361+
" @property\n",
362+
" def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n",
363+
" return ParrotMultiplyTool\n",
364+
"\n",
365+
" def tool_constructor_params(self) -> dict:\n",
366+
" # if your tool constructor instead required initialization arguments like\n",
367+
" # `def __init__(self, some_arg: int):`, you would return those here\n",
368+
" # as a dictionary, e.g.: `return {'some_arg': 42}`\n",
369+
" return {}\n",
370+
"\n",
371+
" def tool_invoke_params_example(self) -> dict:\n",
372+
" \"\"\"\n",
373+
" Returns a dictionary representing the \"args\" of an example tool call.\n",
374+
"\n",
375+
" This should NOT be a ToolCall dict - i.e. it should not\n",
376+
" have {\"name\", \"id\", \"args\"} keys.\n",
377+
" \"\"\"\n",
378+
" return {\"a\": 2, \"b\": 3}"
277379
]
278380
},
279381
{
280382
"cell_type": "markdown",
281383
"metadata": {},
282384
"source": [
283-
"</details>\n",
284-
"</div>"
385+
"</details>"
285386
]
286387
}
287388
],

Diff for: docs/docs/contributing/index.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ More coming soon! We are working on tutorials to help you make your first contri
1717
- [**Documentation**](how_to/documentation/index.mdx): Help improve our docs, including this one!
1818
- [**Code**](how_to/code/index.mdx): Help us write code, fix bugs, or improve our infrastructure.
1919
- [**Integrations**](how_to/integrations/index.mdx): Help us integrate with your favorite vendors and tools.
20+
- [**Standard Tests**](how_to/integrations/standard_tests): Ensure your integration passes an expected set of tests.
2021

2122
## Reference
2223

0 commit comments

Comments
 (0)