Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

langchain: add deepseek provider to init chat model #29449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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))"

Expand Down
13 changes: 9 additions & 4 deletions libs/langchain/langchain/chat_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ def _init_chat_model_helper(
from langchain_google_vertexai.model_garden import ChatAnthropicVertex

return 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(
Expand All @@ -440,6 +445,7 @@ def _init_chat_model_helper(
"bedrock",
"bedrock_converse",
"google_anthropic_vertex",
"deepseek",
}


Expand Down Expand Up @@ -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}`"
)


Expand Down
16 changes: 15 additions & 1 deletion libs/partners/deepseek/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/partners/deepseek/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Type

import pytest
from langchain_tests.integration_tests import ChatModelIntegrationTests

from langchain_deepseek.chat_models import ChatDeepSeek
Expand All @@ -21,6 +22,7 @@ def chat_model_params(self) -> dict:
}


@pytest.mark.xfail(reason="Reasoning API is down")
def test_reasoning_content() -> None:
"""Test reasoning content."""
chat_model = ChatDeepSeek(model="deepseek-reasoner")
Expand Down
Loading