{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "hdHmLCO48n-H" }, "outputs": [], "source": [ "# https://github.com/jmorganca/ollama/blob/main/examples/jupyter-notebook/ollama.ipynb" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "o5Q6OmcN0mkS", "outputId": "c7a663c4-b1d8-4354-d1f2-fac8f503f4d3" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", "100 8423 0 8423 0 0 8293 0 --:--:-- 0:00:01 --:--:-- 8298>>> Downloading ollama...\n", "100 8423 0 8423 0 0 7756 0 --:--:-- 0:00:01 --:--:-- 7763\n", "############################################################################################# 100.0%\n", ">>> Installing ollama to /usr/local/bin...\n", ">>> Creating ollama user...\n", ">>> Adding current user to ollama group...\n", ">>> Creating ollama systemd service...\n", "WARNING: Unable to detect NVIDIA GPU. Install lspci or lshw to automatically detect and install NVIDIA CUDA drivers.\n", ">>> The Ollama API is now available at 0.0.0.0:11434.\n", ">>> Install complete. Run \"ollama\" from the command line.\n", "System has not been booted with systemd as init system (PID 1). Can't operate.\n", "Failed to connect to bus: Host is down\n" ] } ], "source": [ "!curl https://ollama.ai/install.sh | sh\n", "!command -v systemctl >/dev/null && sudo systemctl stop ollama" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "TXtmzrel194r" }, "outputs": [], "source": [ "!pip install aiohttp pyngrok -q" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "GLPqSWXT3QBg", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "a7542b67-3287-4ce5-8459-2e86d8ec7dfd" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [] } ], "source": [ "from pyngrok import ngrok\n", "from google.colab import userdata\n", "\n", "# https://dashboard.ngrok.com/get-started/your-authtoken\n", "NGROK_TOKEN = userdata.get('NGROK_TOKEN')\n", "ngrok.set_auth_token(\"NGROK_TOKEN\")" ] }, { "cell_type": "code", "source": [ "\n", "\n", "import os\n", "import asyncio\n", "from aiohttp import ClientSession\n", "from google.colab import userdata\n", "\n", "# Set LD_LIBRARY_PATH so the system NVIDIA library becomes preferred\n", "# over the built-in library. This is particularly important for\n", "# Google Colab which installs older drivers\n", "os.environ.update({'LD_LIBRARY_PATH': '/usr/lib64-nvidia'})\n", "NGROK_TOKEN = userdata.get('NGROK_TOKEN')\n", "ngrok.set_auth_token(\"NGROK_TOKEN\")\n", "\n", "async def run(cmd):\n", " '''\n", " run is a helper function to run subcommands asynchronously.\n", " '''\n", " print('>>> starting', *cmd)\n", " p = await asyncio.subprocess.create_subprocess_exec(\n", " *cmd,\n", " stdout=asyncio.subprocess.PIPE,\n", " stderr=asyncio.subprocess.PIPE,\n", " )\n", "\n", " async def pipe(lines):\n", " async for line in lines:\n", " print(line.strip().decode('utf-8'))\n", "\n", " await asyncio.gather(\n", " pipe(p.stdout),\n", " pipe(p.stderr),\n", " )\n", "\n", "\n", "await asyncio.gather(\n", " run(['ollama', 'serve']),\n", " run(['ngrok', 'config', 'add-authtoken', NGROK_TOKEN]),\n", " run(['ngrok', 'http', '--log', 'stderr', '11434']),\n", " # run([\"ollama\",\"run\",\"llama2\"]),\n", " run([\"ollama\",\"run\",\"mistral\"]),\n", ")" ], "metadata": { "id": "u1PG3y83Z-u5" }, "execution_count": null, "outputs": [] } ], "metadata": { "colab": { "provenance": [], "machine_shape": "hm", "gpuType": "T4", "authorship_tag": "ABX9TyMLapRySjkHA++gSoAkRSHn", "include_colab_link": true }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" }, "accelerator": "GPU" }, "nbformat": 4, "nbformat_minor": 0 }