主题
在本 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)