Skip to main content
Open In ColabOpen on GitHub

ChatNetmind

这将帮助您开始使用 Netmind 聊天模型。关于 ChatNetmind 所有功能和配置的详细文档,请访问 API 参考

概述

集成详情

包名本地可序列化JS 支持包下载量包最新版本
ChatNetmindlangchain-netmindPyPI - DownloadsPyPI - Version

模型特性

工具调用结构化输出JSON 模式图像输入音频输入视频输入Token 级别流式传输原生异步Token 使用情况Logprobs

设置

要访问 Netmind 模型,您需要创建一个 Netmind 账户,获取 API 密钥,并安装 langchain-netmind 集成包。

凭证

前往 https://www.netmind.ai/ 注册 Netmind 并生成 API 密钥。完成此操作后,设置 NETMIND_API_KEY 环境变量:

import getpass
import os

if not os.getenv("NETMIND_API_KEY"):
os.environ["NETMIND_API_KEY"] = getpass.getpass("Enter your Netmind API key: ")

如果你想自动跟踪模型调用,你也可以通过取消下面行的注释来设置你的 LangSmith API 密钥:

# os.environ["LANGCHAIN_TRACING_V2"] = "true"
# os.environ["LANGCHAIN_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")

安装

LangChain Netmind 集成位于 langchain-netmind 包中:

%pip install -qU langchain-netmind

[notice] A new release of pip is available: 24.0 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.

实例化

现在我们可以实例化我们的模型对象并生成聊天补全:

from langchain_netmind import ChatNetmind

llm = ChatNetmind(
model="deepseek-ai/DeepSeek-V3",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
# other params...
)

调用

messages = [
(
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
),
("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
AIMessage(content="J'adore programmer.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 13, 'prompt_tokens': 31, 'total_tokens': 44, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'deepseek-ai/DeepSeek-V3', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-ca6c2010-844d-4bf6-baac-6e248491b000-0', usage_metadata={'input_tokens': 31, 'output_tokens': 13, 'total_tokens': 44, 'input_token_details': {}, 'output_token_details': {}})
print(ai_msg.content)
J'adore programmer.

链式调用

我们可以像这样将我们的模型与提示模板进行链式调用

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate(
[
(
"system",
"You are a helpful assistant that translates {input_language} to {output_language}.",
),
("human", "{input}"),
]
)

chain = prompt | llm
chain.invoke(
{
"input_language": "English",
"output_language": "German",
"input": "I love programming.",
}
)
API Reference:ChatPromptTemplate
AIMessage(content='Ich liebe es zu programmieren.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 14, 'prompt_tokens': 26, 'total_tokens': 40, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'deepseek-ai/DeepSeek-V3', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-d63adcc6-53ba-4caa-9a79-78d640b39274-0', usage_metadata={'input_tokens': 26, 'output_tokens': 14, 'total_tokens': 40, 'input_token_details': {}, 'output_token_details': {}})

API 参考

有关 ChatNetmind 所有功能和配置的详细文档,请前往 API 参考: