Files
wehub-resource-sync a0c8464e58
Build Package / build (ubuntu-latest) (push) Failing after 1s
CodeQL / Analyze (python) (push) Failing after 1s
Core Typecheck / core-typecheck (push) Failing after 1s
Linting / lint (push) Failing after 1s
llama-dev tests / test-llama-dev (push) Failing after 1s
Publish Sub-Package to PyPI if Needed / publish_subpackage_if_needed (push) Has been skipped
Sync Docs to Developer Hub / sync-docs (push) Failing after 0s
Build Package / build (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:26:52 +08:00

107 lines
2.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/modelscope.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ModelScope LLMS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this notebook, we show how to use the ModelScope LLM models in LlamaIndex. Check out the [ModelScope site](https://www.modelscope.cn/).\n",
"\n",
"If you're opening this Notebook on colab, you will need to install LlamaIndex 🦙 and the modelscope."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index-llms-modelscope"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic Usage\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from llama_index.llms.modelscope import ModelScopeLLM\n",
"\n",
"llm = ModelScopeLLM(model_name=\"qwen/Qwen3-8B\", model_revision=\"master\")\n",
"\n",
"rsp = llm.complete(\"Hello, who are you?\")\n",
"print(rsp)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Use Message request"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.base.llms.types import MessageRole, ChatMessage\n",
"\n",
"messages = [\n",
" ChatMessage(\n",
" role=MessageRole.SYSTEM, content=\"You are a helpful assistant.\"\n",
" ),\n",
" ChatMessage(role=MessageRole.USER, content=\"How to make cake?\"),\n",
"]\n",
"resp = llm.chat(messages)\n",
"print(resp)"
]
}
],
"metadata": {
"colab": {
"name": "gemini.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}