> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Modelscope 集成

> 使用 LangChain Python 与 Modelscope 集成。

> [ModelScope](https://www.modelscope.cn/home) 是一个包含模型和数据集的大型仓库。

本页面介绍了如何在 LangChain 中使用 ModelScope 生态系统。
它分为两个部分：安装和设置，然后是特定 ModelScope 包装器的参考。

## 安装

```bash pip theme={null}
pip install -U langchain-modelscope-integration
```

```bash uv theme={null}
uv add langchain-modelscope-integration
```

前往 [ModelScope](https://modelscope.cn/) 注册 ModelScope 并生成 [SDK token](https://modelscope.cn/my/myaccesstoken)。完成这些操作后，设置 `MODELSCOPE_SDK_TOKEN` 环境变量：

```bash theme={null}
export MODELSCOPE_SDK_TOKEN=<your_sdk_token>
```

## 对话模型

`ModelScopeChatEndpoint` 类暴露了来自 ModelScope 的对话模型。参见 [ModelScope API 文档中的可用模型](https://www.modelscope.cn/docs/model-service/API-Inference/intro)。

```python theme={null}
from langchain_modelscope import ModelScopeChatEndpoint

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

## 嵌入

`ModelScopeEmbeddings` 类暴露了来自 ModelScope 的嵌入。

```python theme={null}
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。

```python theme={null}
from langchain_modelscope import ModelScopeEndpoint

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

***

> 官方原文：[src/oss/python/integrations/providers/modelscope.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/providers/modelscope.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.