Skip to main content
ModelScope 是一个大型模型和数据集仓库。
本页介绍如何在 LangChain 中使用 ModelScope 生态系统。 内容分两个部分:安装,以及对特定 ModelScope 封装器的说明。

安装

pip install -U langchain-modelscope-integration
前往 ModelScope 注册并生成 SDK token。完成后设置 MODELSCOPE_SDK_TOKEN 环境变量:
export MODELSCOPE_SDK_TOKEN=<your_sdk_token>

对话模型

ModelScopeChatEndpoint 类提供来自 ModelScope 的对话模型。可用模型请参阅这里
from langchain_modelscope import ModelScopeChatEndpoint

llm = ModelScopeChatEndpoint(model="Qwen/Qwen2.5-Coder-32B-Instruct")
llm.invoke("Sing a ballad of LangChain.")

嵌入

ModelScopeEmbeddings 类提供来自 ModelScope 的嵌入。
from langchain_modelscope import ModelScopeEmbeddings

embeddings = ModelScopeEmbeddings(model_id="damo/nlp_corom_sentence-embedding_english-base")
embeddings.embed_query("What is the meaning of life?")

LLM

ModelScopeEndpoint 类提供来自 ModelScope 的 LLM。
from langchain_modelscope import ModelScopeEndpoint

llm = ModelScopeEndpoint(model="Qwen/Qwen2.5-Coder-32B-Instruct")
llm.invoke("The meaning of life is")