|
6 | 6 | "source": [
|
7 | 7 | "# How to add standard tests to an integration\n",
|
8 | 8 | "\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", |
12 | 10 | "\n",
|
13 | 11 | "## Setup\n",
|
14 | 12 | "\n",
|
|
20 | 18 | ":::note\n",
|
21 | 19 | "\n",
|
22 | 20 | "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", |
24 | 22 | "\n",
|
25 | 23 | ":::"
|
26 | 24 | ]
|
|
31 | 29 | "metadata": {},
|
32 | 30 | "outputs": [],
|
33 | 31 | "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" |
35 | 33 | ]
|
36 | 34 | },
|
37 | 35 | {
|
|
217 | 215 | "class TestChatParrotLinkUnit(ChatModelUnitTests):\n",
|
218 | 216 | " @property\n",
|
219 | 217 | " 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}" |
221 | 223 | ]
|
222 | 224 | },
|
223 | 225 | {
|
|
248 | 250 | "metadata": {},
|
249 | 251 | "source": [
|
250 | 252 | "</details>\n",
|
251 |
| - "\n", |
252 |
| - "<div style={{display:\"none\"}}>\n", |
253 |
| - "Work in progress:\n", |
254 | 253 | "<details>\n",
|
255 |
| - " <summary>Retrievers</summary>\n", |
256 |
| - " TODO" |
| 254 | + " <summary>Embedding Models</summary>" |
257 | 255 | ]
|
258 | 256 | },
|
259 | 257 | {
|
260 |
| - "cell_type": "markdown", |
| 258 | + "cell_type": "code", |
| 259 | + "execution_count": null, |
261 | 260 | "metadata": {},
|
| 261 | + "outputs": [], |
262 | 262 | "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}" |
267 | 301 | ]
|
268 | 302 | },
|
269 | 303 | {
|
|
272 | 306 | "source": [
|
273 | 307 | "</details>\n",
|
274 | 308 | "<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}" |
277 | 379 | ]
|
278 | 380 | },
|
279 | 381 | {
|
280 | 382 | "cell_type": "markdown",
|
281 | 383 | "metadata": {},
|
282 | 384 | "source": [
|
283 |
| - "</details>\n", |
284 |
| - "</div>" |
| 385 | + "</details>" |
285 | 386 | ]
|
286 | 387 | }
|
287 | 388 | ],
|
|
0 commit comments