Skip to content
LlamaIndex 文档版本 跟随上游 源快照 88641eab 更新于 2026-10-18

在本 notebook 中,我们展示如何在 LlamaIndex 中使用 ModelScope LLM 模型。请查看 ModelScope 网站。

如果你在 Colab 中打开这个 Notebook,需要安装 LlamaIndex 🦙 和 modelscope。

!pip install llama-index-llms-modelscope

基本用法

import sys
from llama_index.llms.modelscope import ModelScopeLLM

llm = ModelScopeLLM(model_name="qwen/Qwen3-8B", model_revision="master")

rsp = llm.complete("Hello, who are you?")
print(rsp)

使用消息请求

from llama_index.core.base.llms.types import MessageRole, ChatMessage

messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful assistant."
    ),
    ChatMessage(role=MessageRole.USER, content="How to make cake?"),
]
resp = llm.chat(messages)
print(resp)

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。