Context Lab

Ollama:供 agent 使用的本地 LLM

指南 · AI Practice · 僅供教育 · RAM/disk 數字是概數

目標:本地備有 OpenAI-compatible endpoint,context 足夠做 tool-calling。Hermes(及類似 agent)往往拒絕 64K 以下;僅有 8K chat window 不算「agent-ready」。

使用 ollama.com 官方 installer。版本與 tag 會變;上線前請再對官方 docs。

安裝 Ollama

使用 ollama.com 官方安裝程式(Linux/macOS 用 curl、Windows 用 PowerShell,或下載頁)。

確認 daemon

檢查 ollama --version 與 curl http://127.0.0.1:11434/api/tags,確認本機服務就緒後再 pull model。

Pull tool model

選擇 model card 標明 tool/function calling、且可放入 RAM 的 model。純 chat model 常令 agent 失敗。

提高 context ≥64K

預設 window 對 Hermes 往往太小。使用 -c 65536,或以 Modelfile 設定 num_ctx 65536。

OpenAI-compat endpoint

先 smoke-test /v1/models,再將 Hermes 指向本機 base URL 與 model 名;gateway 之後再加。

    主題摘要 · 原創圖示 · 無自動播放

    1)裝 Ollama

    Linux/macOS:

    curl -fsSL https://ollama.com/install.sh | sh

    Windows(PowerShell):

    irm https://ollama.com/install.ps1 | iex

    或者前往 ollama.com/download。確認 daemon:

    ollama --version
    curl -s http://127.0.0.1:11434/api/tags

    2)Pull 支援 tool 的 model

    選擇 model card 寫明 tool/function calling、又能放入 RAM 的。權重 disk 概數(非 benchmark):

    # 例 tag:換成 ollama.com/library 目前支援 tool 的 model
    ollama pull qwen2.5:14b
    ollama run qwen2.5:14b

    先看 model card。純 chat model 即使 token 流暢,Hermes 也不適用。

    3)提高 context(Hermes ≥64K)

    預設 context 多數太小。單次:

    ollama run qwen2.5:14b -c 65536

    長用 Modelfile(名稱自定):

    FROM qwen2.5:14b
    PARAMETER num_ctx 65536
    ollama create my-agent -f Modelfile
    ollama run my-agent

    Context 愈大愈耗 RAM/VRAM。若 thrash 或 OOM,改用較小 model/較小 context;不要當 8K 足夠做多步 tools。

    4)Smoke-test OpenAI-compatible API

    curl http://127.0.0.1:11434/v1/models

    用 hermes model 指向 custom/Ollama endpoint。先確認 base URL、model 名、普通 chat 可用,再開 gateway 或 cron。

    本頁不做

    來源