DeepSeek Integration for LangChain
langchain-deepseek is an official LangChain partner package that integrates DeepSeek's large language models (LLMs) and embeddings into the LangChain ecosystem. It allows developers to easily use DeepSeek models for chat completions and text embeddings within their LangChain applications. The current version is 1.0.1, and it follows the rapid development and release cadence typical of LangChain's partner libraries, often aligning with `langchain-core` updates.
Warnings
- gotcha The DeepSeek API key is required for authentication. It can be provided either as an environment variable `DEEPSEEK_API_KEY` or directly as a `deepseek_api_key` argument to the `ChatDeepSeek` or `DeepSeekEmbeddings` constructors. The argument takes precedence.
- gotcha This library has strict Python version requirements: `>=3.10.0` and `<4.0.0`. Using incompatible Python versions will lead to installation or runtime errors.
- gotcha `langchain-deepseek` depends on `langchain-core` with specific version constraints (e.g., `langchain-core>=0.1.0,<0.2.0`). Mismatches between `langchain-deepseek`'s declared `langchain-core` dependency and other `langchain` packages in your environment can cause runtime issues or unexpected behavior. Use `pip install` with care in mixed LangChain environments.
Install
-
pip install langchain-deepseek
Imports
- ChatDeepSeek
from langchain_deepseek import ChatDeepSeek
- DeepSeekEmbeddings
from langchain_deepseek import DeepSeekEmbeddings
Quickstart
import os
from langchain_deepseek import ChatDeepSeek
from langchain_core.messages import HumanMessage
# Ensure your DeepSeek API key is set as an environment variable
# or passed directly to the ChatDeepSeek constructor.
# os.environ["DEEPSEEK_API_KEY"] = "your-deepseek-api-key"
deepseek_api_key = os.environ.get("DEEPSEEK_API_KEY")
if not deepseek_api_key:
raise ValueError("DEEPSEEK_API_KEY environment variable not set.")
chat_model = ChatDeepSeek(deepseek_api_key=deepseek_api_key)
messages = [
HumanMessage(content="Tell me a short story about a brave knight.")
]
response = chat_model.invoke(messages)
print(response.content)