Skip to content

Commit

Permalink
Merge branch 'master' into snova-jorgep/bind_tools_sambanova_chat_models
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpiedrahitao authored Nov 19, 2024
2 parents 2897b4e + 5599a0a commit 16d5486
Show file tree
Hide file tree
Showing 67 changed files with 236 additions and 133 deletions.
36 changes: 20 additions & 16 deletions .github/scripts/prep_api_docs_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
def load_packages_yaml() -> Dict[str, Any]:
"""Load and parse the packages.yml file."""
with open("langchain/libs/packages.yml", "r") as f:
return yaml.safe_load(f)
all_packages = yaml.safe_load(f)

return {k: v for k, v in all_packages.items() if k["repo"]}


def get_target_dir(package_name: str) -> Path:
Expand All @@ -23,24 +25,19 @@ def get_target_dir(package_name: str) -> Path:
return base_path / "partners" / package_name_short


def clean_target_directories(packages: Dict[str, Any]) -> None:
def clean_target_directories(packages: list) -> None:
"""Remove old directories that will be replaced."""
for package in packages["packages"]:
if package["repo"] != "langchain-ai/langchain":
target_dir = get_target_dir(package["name"])
if target_dir.exists():
print(f"Removing {target_dir}")
shutil.rmtree(target_dir)
for package in packages:

target_dir = get_target_dir(package["name"])
if target_dir.exists():
print(f"Removing {target_dir}")
shutil.rmtree(target_dir)


def move_libraries(packages: Dict[str, Any]) -> None:
def move_libraries(packages: list) -> None:
"""Move libraries from their source locations to the target directories."""
for package in packages["packages"]:
# Skip if it's the main langchain repo or disabled
if package["repo"] == "langchain-ai/langchain" or package.get(
"disabled", False
):
continue
for package in packages:

repo_name = package["repo"].split("/")[1]
source_path = package["path"]
Expand Down Expand Up @@ -68,7 +65,14 @@ def main():
"""Main function to orchestrate the library sync process."""
try:
# Load packages configuration
packages = load_packages_yaml()
package_yaml = load_packages_yaml()
packages = [
p
for p in package_yaml["packages"]
if not p.get("disabled", False)
and p["repo"].startswith("langchain-ai/")
and p["repo"] != "langchain-ai/langchain"
]

# Clean target directories
clean_target_directories(packages)
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ jobs:
# Replace all dashes in the package name with underscores,
# since that's how Python imports packages with dashes in the name.
if [ "$PKG_NAME" == "langchain-tests" ]; then
IMPORT_NAME="langchain_standard_tests"
else
IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g)"
fi
IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g)"
poetry run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/api_doc_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
# Get unique repositories
REPOS=$(echo "$REPOS_UNSORTED" | sort -u)
# Checkout each unique repository
# Checkout each unique repository that is in langchain-ai org
for repo in $REPOS; do
if [ "$repo" != "langchain-ai/langchain" ]; then
if [[ "$repo" != "langchain-ai/langchain" && "$repo" == langchain-ai/* ]]; then
REPO_NAME=$(echo $repo | cut -d'/' -f2)
echo "Checking out $repo to $REPO_NAME"
git clone --depth 1 https://github.com/$repo.git $REPO_NAME
Expand Down
6 changes: 5 additions & 1 deletion docs/docs/contributing/how_to/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

- [**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.
- [**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.
10 changes: 4 additions & 6 deletions docs/docs/contributing/how_to/integrations/community.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
## How to add a community integration (deprecated guide)
## How to add a community integration (not recommended)

:::danger

We are no longer accepting new community integrations. Please see the
[main integration guide](./index.mdx) for more information on contributing new
integrations.
We recommend following the [main integration guide](./index.mdx) to add new integrations instead.

Note that `langchain-community` is **not** deprecated. Only
the process for adding new community integrations is deprecated.
If you follow this guide, there is a high likelihood we will close your PR with the above
guide linked without much discussion.

:::

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/contributing/how_to/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ that will render on this site (https://python.langchain.com/).

As a prerequisite to adding your integration to our documentation, you must:

1. Confirm that your integration is in the list of components we are currently accepting.
1. Confirm that your integration is in the [list of components](#components-to-integrate) we are currently accepting.
2. Ensure that your integration is in a separate package that can be installed with `pip install <your-package>`.
3. Implement the standard tests for your integration and successfully run them.
3. Write documentation for your integration in the `docs/docs/integrations` directory of the LangChain monorepo.
3. [Implement the standard tests](/docs/contributing/how_to/integrations/standard_tests) for your integration and successfully run them.
3. Write documentation for your integration in the `docs/docs/integrations/<component_type>` directory of the LangChain monorepo.
4. Add a provider page for your integration in the `docs/docs/integrations/providers` directory of the LangChain monorepo.

Once you have completed these steps, you can submit a PR to the LangChain monorepo to add your integration to the documentation.
Expand Down
161 changes: 128 additions & 33 deletions docs/docs/contributing/how_to/integrations/standard_tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,19 @@
"source": [
"# How to add standard tests to an integration\n",
"\n",
"Implementing standard tests \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",
"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",
"## Setup\n",
"\n",
"First, let's install 2 dependencies:\n",
"\n",
"- `langchain-core` will define the interfaces we want to import to define our custom tool.\n",
"- `langchain-tests==0.3.0` will provide the standard tests we want to use.\n",
"- `langchain-tests==0.3.2` will provide the standard tests we want to use.\n",
"\n",
":::note\n",
"\n",
"The `langchain-tests` package contains the module `langchain_standard_tests`. This name\n",
"mistmatch is due to this package historically being called `langchain_standard_tests` and\n",
"the name not being available on PyPi. This will either be reconciled by our \n",
"[PEP 541 request](https://github.com/pypi/support/issues/5062) (we welcome upvotes!), \n",
"or in a new release of `langchain-tests`.\n",
"\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",
":::"
]
Expand All @@ -37,7 +29,7 @@
"metadata": {},
"outputs": [],
"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"
]
},
{
Expand Down Expand Up @@ -91,8 +83,8 @@
"\n",
"There are 2 namespaces in the `langchain-tests` package: \n",
"\n",
"- unit tests (`langchain_standard_tests.unit_tests`): designed to be used to test the tool in isolation and without access to external services\n",
"- integration tests (`langchain_standard_tests.integration_tests`): designed to be used to test the tool with access to external services (in particular, the external service that the tool is designed to interact with).\n",
"- unit tests (`langchain_tests.unit_tests`): designed to be used to test the tool in isolation and without access to external services\n",
"- integration tests (`langchain_tests.integration_tests`): designed to be used to test the tool with access to external services (in particular, the external service that the tool is designed to interact with).\n",
"\n",
":::note\n",
"\n",
Expand Down Expand Up @@ -122,7 +114,7 @@
"from typing import Type\n",
"\n",
"from langchain_parrot_link.tools import ParrotMultiplyTool\n",
"from langchain_standard_tests.unit_tests import ToolsUnitTests\n",
"from langchain_tests.unit_tests import ToolsUnitTests\n",
"\n",
"\n",
"class TestParrotMultiplyToolUnit(ToolsUnitTests):\n",
Expand Down Expand Up @@ -156,7 +148,7 @@
"from typing import Type\n",
"\n",
"from langchain_parrot_link.tools import ParrotMultiplyTool\n",
"from langchain_standard_tests.integration_tests import ToolsIntegrationTests\n",
"from langchain_tests.integration_tests import ToolsIntegrationTests\n",
"\n",
"\n",
"class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):\n",
Expand Down Expand Up @@ -217,13 +209,17 @@
"from typing import Tuple, Type\n",
"\n",
"from langchain_parrot_link.chat_models import ChatParrotLink\n",
"from langchain_standard_tests.unit_tests import ChatModelUnitTests\n",
"from langchain_tests.unit_tests import ChatModelUnitTests\n",
"\n",
"\n",
"class TestChatParrotLinkUnit(ChatModelUnitTests):\n",
" @property\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}"
]
},
{
Expand All @@ -236,7 +232,7 @@
"from typing import Type\n",
"\n",
"from langchain_parrot_link.chat_models import ChatParrotLink\n",
"from langchain_standard_tests.integration_tests import ChatModelIntegrationTests\n",
"from langchain_tests.integration_tests import ChatModelIntegrationTests\n",
"\n",
"\n",
"class TestChatParrotLinkIntegration(ChatModelIntegrationTests):\n",
Expand All @@ -254,22 +250,54 @@
"metadata": {},
"source": [
"</details>\n",
"\n",
"<div style={{display:\"none\"}}>\n",
"Work in progress:\n",
"<details>\n",
" <summary>Retrievers</summary>\n",
" TODO"
" <summary>Embedding Models</summary>"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"</details>\n",
"<details>\n",
" <summary>Vector Stores</summary>\n",
" TODO"
"# title=\"tests/unit_tests/test_embeddings.py\"\n",
"from typing import Tuple, Type\n",
"\n",
"from langchain_parrot_link.embeddings import ParrotLinkEmbeddings\n",
"from langchain_standard_tests.unit_tests import EmbeddingsUnitTests\n",
"\n",
"\n",
"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}"
]
},
{
Expand All @@ -278,16 +306,83 @@
"source": [
"</details>\n",
"<details>\n",
" <summary>Embedding Models</summary>\n",
" TODO"
" <summary>Tools/Toolkits</summary>\n",
" 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",
"metadata": {},
"source": [
"</details>\n",
"</div>"
"</details>"
]
}
],
Expand Down
1 change: 1 addition & 0 deletions docs/docs/contributing/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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!
- [**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.
- [**Standard Tests**](how_to/integrations/standard_tests): Ensure your integration passes an expected set of tests.

## Reference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
from langchain_core.language_models import BaseChatModel
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests
from langchain_tests.integration_tests import ChatModelIntegrationTests

from langchain_community.chat_models.litellm import ChatLiteLLM

Expand Down
Loading

0 comments on commit 16d5486

Please sign in to comment.