amin-tehrani/ollama-colab
关于
Serve Ollama LLMs on Google Colab (free plan) using Ngrok
人工智能与机器学习实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文ollama-colab
Run Ollama LLMs on Google Colab's free GPU — exposed as a public API endpoint via Ngrok.
Why this exists
Running LLMs locally requires hardware most people don't have. Paying for OpenAI, Anthropic, or Llama API adds up fast. Google Colab offers free T4/A100 GPUs sitting idle. This notebook bridges the gap: spin up Ollama on Colab and expose it as a standard REST API endpoint you can hit from anywhere — your laptop, a LangChain app, a Python script, anything.
How it works
Google Colab (free GPU)
└─ Ollama server (:11434)
└─ Ngrok tunnel ──► https://xxxx.ngrok-free.app (public endpoint)
Ollama's API is OpenAI-compatible, so any client that speaks OpenAI can point at this endpoint with zero changes.
Prerequisites
- Google account — to run Colab notebooks
- Ngrok account — free tier is enough. Get your auth token at dashboard.ngrok.com
Usage
1. Open the notebook in Colab
Click the badge above, or open ollama-server.ipynb directly in Google Colab.
2. Set your Ngrok auth token
In the notebook, find this cell and replace the placeholder:
!./ngrok authtoken <NGROK_AUTH_TOKEN>
3. Run all cells
The final cell starts the Ollama server, pulls llama3, and opens a Ngrok tunnel on port 11434.
4. Get your endpoint
Find your public URL in the cell output or at dashboard.ngrok.com/cloud-edge:
https://xxxx.ngrok-free.app
Using the endpoint
curl
curl https://xxxx.ngrok-free.app/api/generate \
-d '{"model": "llama3", "prompt": "Hello!", "stream": false}'
LangChain
from langchain_ollama.llms import OllamaLLM
llm = OllamaLLM(
base_url="https://xxxx.ngrok-free.app",
model="llama3"
)
print(llm.invoke("What is the capital of France?"))
OpenAI-compatible client
from openai import OpenAI
client = OpenAI(
base_url="https://xxxx.ngrok-free.app/v1",
api_key="ollama" # any non-empty string
)
response = client.chat.completions.create(
model="llama3",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Changing the model
Edit the final cell — replace llama3 with any model from ollama.com/library:
ollama serve & ./ngrok http 11434 --host-header="localhost:11434" --log stdout & sleep 5s && ollama run mistral
Popular choices: llama3, mistral, gemma2, phi3, codellama, deepseek-coder
Limitations
- Colab free sessions time out after ~12 hours of inactivity
- Free Ngrok gives one public URL per session (resets on restart)
- Model weights are re-downloaded each session unless you mount Google Drive
License
MIT © Amin Tehrani
探索相关项目
加载中…