LangChain Python 提供了一个庞大的生态系统,拥有 1000 多个集成,涵盖聊天与嵌入模型、工具与工具包、文档加载器、向量存储等。
详细的介绍可以点击下面的链接查看:https://docs.langchain.com/oss/python/integrations/providers/overview
现在看一下怎么通过python脚本使用langchain-deepseek连接deepseek模型进行对话:
https://reference.langchain.com/python/integrations/langchain_deepseek/
链接中还有流式输出、非流式输出、结构化输出、异步调用和工具调用的相关用法介绍,感兴趣的可以自己研究:
def get_deepseek_model():
# pip install -U langchain-deepseek
os.environ["DEEPSEEK_API_KEY"] = "sk-xxxxxxxxx" # 也可以在下面的api_key设置key
model = ChatDeepSeek(
model="deepseek-reasoner", # deepseek-chat, deepseek-reasoner
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
#api_key="...",
# other params...
)
return model
llm = get_deepseek_model()
response = llm.invoke("你好,你是谁? ")
print(response) 


一句话总结:
“想闲聊、写文案、快响应”用 deepseek-chat;“要解题、写算法、看推理步骤”用 deepseek-reasoner——其实就是同一个模型,只是让不让它“先想后答”
LangChain 支持通过统一的接口,从任意支持的模型提供商进行初始化聊天模型。
from langchain.chat_models import init_chat_model
init_chat_model(
model: str | None = None,
*,
model_provider: str | None = None,
configurable_fields: Literal["any"] | list[str] | tuple[str, ...] | None = None,
config_prefix: str | None = None,
**kwargs: Any,
) -> BaseChatModel | _ConfigurableModel
https://reference.langchain.com/python/langchain/models
从上面的文档中可以看到相关的model_provider的介绍,点击相关的链接可以看模型的相关使用介绍:

看完上面的内容的话,基本上就可以写一个简单的基于langchain的大模型基础对话的简单脚本了,关注我,后面会不定期更新其他内容。