{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open" ] }, { "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 }