The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
langchain: add deepseek provider to init chat model (#29449)
Erick Friisecdc8813280f
diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.ymlindex e54bcb360f..cb20dba108 100644--- a/.github/workflows/_release.yml+++ b/.github/workflows/_release.yml@@ -217,7 +217,8 @@ jobs:# Replace all dashes in the package name with underscores,# since that's how Python imports packages with dashes in the name.- IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g)"+ # also remove _official suffix+ IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g | sed s/_official//g)"poetry run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"diff --git a/libs/langchain/langchain/chat_models/base.py b/libs/langchain/langchain/chat_models/base.pyindex 7b9418849b..47ac09e5af 100644--- a/libs/langchain/langchain/chat_models/base.py+++ b/libs/langchain/langchain/chat_models/base.py@@ -416,6 +416,11 @@ def _init_chat_model_helper(from langchain_google_vertexai.model_garden import ChatAnthropicVertexreturn ChatAnthropicVertex(model=model, **kwargs)+ elif model_provider == "deepseek":+ _check_pkg("langchain_deepseek", pkg_kebab="langchain-deepseek-official")+ from langchain_deepseek import ChatDeepSeek++ return ChatDeepSeek(model=model, **kwargs)else:supported = ", ".join(_SUPPORTED_PROVIDERS)raise ValueError(@@ -440,6 +445,7 @@ _SUPPORTED_PROVIDERS = {"bedrock","bedrock_converse","google_anthropic_vertex",+ "deepseek",}@@ -480,12 +486,11 @@ def _parse_model(model: str, model_provider: Optional[str]) -> Tuple[str, str]:return model, model_provider-def _check_pkg(pkg: str) -> None:+def _check_pkg(pkg: str, *, pkg_kebab: Optional[str] = None) -> None:if not util.find_spec(pkg):- pkg_kebab = pkg.replace("_", "-")+ pkg_kebab = pkg_kebab if pkg_kebab is not None else pkg.replace("_", "-")raise ImportError(- f"Unable to import {pkg_kebab}. Please install with "- f"`pip install -U {pkg_kebab}`"+ f"Unable to import {pkg}. Please install with `pip install -U {pkg_kebab}`")diff --git a/libs/partners/deepseek/poetry.lock b/libs/partners/deepseek/poetry.lockindex ddc85154b3..db4ca5709c 100644--- a/libs/partners/deepseek/poetry.lock+++ b/libs/partners/deepseek/poetry.lock@@ -1073,6 +1073,20 @@ files = [[package.dependencies]pytest = ">=6.2.5"+[[package]]+name = "pytest-timeout"+version = "2.3.1"+description = "pytest plugin to abort hanging tests"+optional = false+python-versions = ">=3.7"+files = [+ {file = "pytest-timeout-2.3.1.tar.gz", hash = "sha256:12397729125c6ecbdaca01035b9e5239d4db97352320af155b3f5de1ba5165d9"},+ {file = "pytest_timeout-2.3.1-py3-none-any.whl", hash = "sha256:68188cb703edfc6a18fad98dc25a3c61e9f24d644b0b70f33af545219fc7813e"},+]++[package.dependencies]+pytest = ">=7.0.0"+[[package]]name = "pytest-watcher"version = "0.3.5"@@ -1649,4 +1663,4 @@ cffi = ["cffi (>=1.11)"][metadata]lock-version = "2.0"python-versions = ">=3.9,<4.0"-content-hash = "7c03a9a824974f7e2cd363082dc2f1163488749db15f73e7b6326508c07633ae"+content-hash = "9c889754b3cb5e1044c6f7eeab3a5e4857179762c18a6d378fbb1ba72ab5b08b"diff --git a/libs/partners/deepseek/pyproject.toml b/libs/partners/deepseek/pyproject.tomlindex 9d7e74080e..ba8f2ee61e 100644--- a/libs/partners/deepseek/pyproject.toml+++ b/libs/partners/deepseek/pyproject.toml@@ -61,6 +61,7 @@ pytest-socket = "^0.7.0"pytest-watcher = "^0.3.4"langchain-tests = "^0.3.5"langchain-openai = { path = "../openai" }+pytest-timeout = "^2.3.1"[tool.poetry.group.codespell.dependencies]codespell = "^2.2.6"diff --git a/libs/partners/deepseek/tests/integration_tests/test_chat_models.py b/libs/partners/deepseek/tests/integration_tests/test_chat_models.pyindex d986edb58e..3655bca1b3 100644--- a/libs/partners/deepseek/tests/integration_tests/test_chat_models.py+++ b/libs/partners/deepseek/tests/integration_tests/test_chat_models.py@@ -2,6 +2,7 @@from typing import Type+import pytestfrom langchain_tests.integration_tests import ChatModelIntegrationTestsfrom langchain_deepseek.chat_models import ChatDeepSeek@@ -21,6 +22,7 @@ class TestChatDeepSeek(ChatModelIntegrationTests):}[email protected](reason="Reasoning API is down")def test_reasoning_content() -> None:"""Test reasoning content."""chat_model = ChatDeepSeek(model="deepseek-reasoner")