>ModelScope 是一个大型的模型和数据集仓库。
本页面介绍如何在 LangChain 中使用 modelscope 生态系统。 它分为两部分:安装和设置,然后是特定 modelscope 包装器的参考。
安装
pip install -U langchain-modelscope-integration
uv add langchain-modelscope-integration
前往 ModelScope 注册 ModelScope 并生成 SDK 令牌。完成此操作后,设置 MODELSCOPE_SDK_TOKEN 环境变量:
聊天模型
ModelScopeChatEndpoint 类公开了来自 ModelScope 的聊天模型。请参阅 ModelScope API 文档中的可用模型.
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?")
## LLMs ModelScopeEndpoint 类公开了来自 ModelScope 的 LLMs。
from langchain_modelscope import ModelScopeEndpoint
llm = ModelScopeEndpoint(model="Qwen/Qwen2.5-Coder-32B-Instruct")
llm.invoke("The meaning of life is")