jpskill.com
🛠️ 開発・MCP コミュニティ

ollama

Ollamaは、AIモデルを自分のパソコンで動かし、オフライン環境でのテキスト生成やチャットボット構築、データ送信なしでのAI利用を可能にし、モデルのカスタマイズやLangChain等との連携も実現するSkill。

📜 元の英語説明(参考)

Run LLMs locally with Ollama. Use when a user asks to run AI models locally, self-host a language model, use LLaMA or Mistral on their machine, run offline AI, build a local chatbot, avoid sending data to cloud AI providers, generate text without API costs, fine-tune or customize local models, or set up a private AI inference server. Covers model management, API usage, Modelfile customization, GPU acceleration, and integration with LangChain and other frameworks.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Ollamaは、AIモデルを自分のパソコンで動かし、オフライン環境でのテキスト生成やチャットボット構築、データ送信なしでのAI利用を可能にし、モデルのカスタマイズやLangChain等との連携も実現するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o ollama.zip https://jpskill.com/download/15192.zip && unzip -o ollama.zip && rm ollama.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15192.zip -OutFile "$d\ollama.zip"; Expand-Archive "$d\ollama.zip" -DestinationPath $d -Force; ri "$d\ollama.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して ollama.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → ollama フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Ollama

概要

Ollama を使うと、ollama run llama3 のように簡単に大規模言語モデルをローカルで実行できます。クラウド API、API キー、トークンごとのコストは不要で、モデルはすべてあなたのハードウェア上で実行されます。LLaMA 3、Mistral、Phi、Gemma、CodeLlama、その他多数のオープンモデルをサポートしています。このスキルでは、モデル管理、API 連携、カスタムモデル構成、GPU セットアップ、ローカル LLM を使用したアプリケーションの構築について説明します。

手順

ステップ 1: インストール

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

# macOS
brew install ollama

# Docker
docker run -d --gpus all -v ollama_data:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

# 検証
ollama --version

ステップ 2: モデルのダウンロードと実行

# ダウンロードしてチャットを開始
ollama run llama3.1              # Meta LLaMA 3.1 8B
ollama run mistral               # Mistral 7B
ollama run codellama              # コードに特化した LLaMA
ollama run phi3                   # Microsoft Phi-3 (小型、高速)
ollama run gemma2                 # Google Gemma 2
ollama run llama3.1:70b           # より大きな 70B モデル (約 40GB の RAM が必要)
ollama run deepseek-r1:8b         # DeepSeek R1 推論モデル

# ダウンロードしたモデルをリスト表示
ollama list

# モデルを削除
ollama rm mistral

# モデル情報
ollama show llama3.1

ステップ 3: REST API

Ollama は、http://localhost:11434 で OpenAI 互換の API を公開します。

# 補完を生成
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.1",
  "prompt": "Explain recursion in one paragraph.",
  "stream": false
}'

# チャット補完 (OpenAI 互換)
curl http://localhost:11434/v1/chat/completions -d '{
  "model": "llama3.1",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is a closure in JavaScript?"}
  ]
}'

# 埋め込みを生成
curl http://localhost:11434/api/embed -d '{
  "model": "llama3.1",
  "input": "How to deploy a Node.js app"
}'

ステップ 4: Node.js 連携

// lib/local-ai.ts — OpenAI 互換 API 経由で Node.js から Ollama を使用
// 任意の OpenAI SDK が動作します — ベース URL を変更するだけです
import OpenAI from 'openai'

const ollama = new OpenAI({
  baseURL: 'http://localhost:11434/v1',
  apiKey: 'ollama',    // SDK で必須ですが、Ollama では使用されません
})

// チャット補完 (OpenAI と同じ API)
const response = await ollama.chat.completions.create({
  model: 'llama3.1',
  messages: [
    { role: 'system', content: 'You are a code review assistant.' },
    { role: 'user', content: 'Review this function:\n\nfunction add(a, b) { return a + b; }' },
  ],
  temperature: 0.3,
})

console.log(response.choices[0].message.content)

// ストリーミング
const stream = await ollama.chat.completions.create({
  model: 'llama3.1',
  messages: [{ role: 'user', content: 'Write a haiku about coding.' }],
  stream: true,
})

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '')
}

ステップ 5: Python 連携

# local_chat.py — Python から Ollama を使用
import ollama

# 簡単な生成
response = ollama.chat(
    model='llama3.1',
    messages=[
        {'role': 'system', 'content': 'You are a data analysis expert.'},
        {'role': 'user', 'content': 'Explain the difference between L1 and L2 regularization.'},
    ],
)
print(response['message']['content'])

# ストリーミング
stream = ollama.chat(
    model='llama3.1',
    messages=[{'role': 'user', 'content': 'Explain MapReduce.'}],
    stream=True,
)
for chunk in stream:
    print(chunk['message']['content'], end='', flush=True)

# 埋め込み
result = ollama.embed(model='llama3.1', input='How to use PostgreSQL indexes')
print(len(result['embeddings'][0]))    # 埋め込みの次元

ステップ 6: Modelfile を使用したカスタムモデル

# Modelfile — 特定の動作を持つカスタムモデルを作成
FROM llama3.1

# モデルに組み込まれたシステムプロンプト
SYSTEM """
あなたはベテランの Python 開発者です。PEP 8 に従い、クリーンでドキュメントが整備されたコードを書きます。
常に型ヒントとドキュメンテーション文字列を含めます。
コードを書くように求められた場合は、完全で実行可能な例を提供してください。
"""

# パラメータ
PARAMETER temperature 0.3
PARAMETER top_p 0.9
PARAMETER num_ctx 8192
# カスタムモデルを構築して使用
ollama create python-coder -f Modelfile
ollama run python-coder

ステップ 7: GPU 構成

# GPU 検出の確認
ollama ps    # 実行中のモデルと GPU メモリ使用量を表示

# GPU 制御のための環境変数
OLLAMA_GPU_LAYERS=35    # GPU にオフロードするレイヤー数
CUDA_VISIBLE_DEVICES=0  # 特定の GPU を選択

# メモリ要件 (概算):
# 7B モデル:  ~4GB RAM (GPU) または ~8GB RAM (CPU)
# 13B モデル: ~8GB RAM (GPU) または ~16GB RAM (CPU)
# 70B モデル: ~40GB RAM (GPU) または ~64GB RAM (CPU)

例 1: プライベートなコードアシスタントを構築する

ユーザープロンプト: 「コードがクラウドに送信されない、完全に自分のマシン上で実行されるコードアシスタントが欲しいです。Python と TypeScript を処理できる必要があります。」

エージェントは以下を行います:

  1. Ollama をインストールし、codellama:13b または deepseek-coder:6.7b をダウンロードします。
  2. コーディング用に最適化されたシステムプロンプトを含む Modelfile を作成します。
  3. OpenAI 互換 API を使用して、簡単な CLI または Web インターフェースを構築します。
  4. すべての推論はローカルで実行されます — データは一切マシンから出ません。

例 2: ローカルの RAG パイプラインを実行する

ユーザープロンプト: 「会社の内部ドキュメントをインデックス化し、従業員が AI でクエリできるようにしたいのですが、コンプライアンス上の理由からデータを OpenAI に送信することはできません。」

エージェントは以下を行います:

  1. 生成と埋め込みのために llama3.1 で Ollama をセットアップします。
  2. ドキュメントをチャンク化し、ローカルのベクトルデータベース (ChromaDB) に埋め込みを保存します。
  3. 検索パイプラインを構築します: クエリ → 埋め込み → 検索 → 回答の生成。
  4. 内部 Web アプリとしてデプロイします。すべての処理はオンプレミスで行われます。

ガイドライン

  • ハードウェアによるモデルの選択: 7B モデルは 8GB 以上の RAM を搭載したマシンでうまく動作します。13B は 16GB 以上が必要です。70B は 64GB 以上またはハイエンド GPU が必要です。品質要件を満たす最小のモデルから始めてください。
  • Ollama の API は OpenAI 互換です — OpenAI SDK、Lang
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Ollama

Overview

Ollama makes running large language models locally as simple as ollama run llama3. No cloud API, no API keys, no per-token costs — models run entirely on your hardware. It supports LLaMA 3, Mistral, Phi, Gemma, CodeLlama, and dozens of other open models. This skill covers model management, API integration, custom model configuration, GPU setup, and building applications with local LLMs.

Instructions

Step 1: Installation

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

# macOS
brew install ollama

# Docker
docker run -d --gpus all -v ollama_data:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

# Verify
ollama --version

Step 2: Download and Run Models

# Download and start chatting
ollama run llama3.1              # Meta LLaMA 3.1 8B
ollama run mistral               # Mistral 7B
ollama run codellama              # Code-focused LLaMA
ollama run phi3                   # Microsoft Phi-3 (small, fast)
ollama run gemma2                 # Google Gemma 2
ollama run llama3.1:70b           # Larger 70B model (needs ~40GB RAM)
ollama run deepseek-r1:8b         # DeepSeek R1 reasoning model

# List downloaded models
ollama list

# Remove a model
ollama rm mistral

# Model info
ollama show llama3.1

Step 3: REST API

Ollama exposes an OpenAI-compatible API at http://localhost:11434.

# Generate completion
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.1",
  "prompt": "Explain recursion in one paragraph.",
  "stream": false
}'

# Chat completion (OpenAI-compatible)
curl http://localhost:11434/v1/chat/completions -d '{
  "model": "llama3.1",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is a closure in JavaScript?"}
  ]
}'

# Generate embeddings
curl http://localhost:11434/api/embed -d '{
  "model": "llama3.1",
  "input": "How to deploy a Node.js app"
}'

Step 4: Node.js Integration

// lib/local-ai.ts — Use Ollama from Node.js via OpenAI-compatible API
// Any OpenAI SDK works — just change the base URL
import OpenAI from 'openai'

const ollama = new OpenAI({
  baseURL: 'http://localhost:11434/v1',
  apiKey: 'ollama',    // required by SDK but not used by Ollama
})

// Chat completion (same API as OpenAI)
const response = await ollama.chat.completions.create({
  model: 'llama3.1',
  messages: [
    { role: 'system', content: 'You are a code review assistant.' },
    { role: 'user', content: 'Review this function:\n\nfunction add(a, b) { return a + b; }' },
  ],
  temperature: 0.3,
})

console.log(response.choices[0].message.content)

// Streaming
const stream = await ollama.chat.completions.create({
  model: 'llama3.1',
  messages: [{ role: 'user', content: 'Write a haiku about coding.' }],
  stream: true,
})

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '')
}

Step 5: Python Integration

# local_chat.py — Use Ollama from Python
import ollama

# Simple generation
response = ollama.chat(
    model='llama3.1',
    messages=[
        {'role': 'system', 'content': 'You are a data analysis expert.'},
        {'role': 'user', 'content': 'Explain the difference between L1 and L2 regularization.'},
    ],
)
print(response['message']['content'])

# Streaming
stream = ollama.chat(
    model='llama3.1',
    messages=[{'role': 'user', 'content': 'Explain MapReduce.'}],
    stream=True,
)
for chunk in stream:
    print(chunk['message']['content'], end='', flush=True)

# Embeddings
result = ollama.embed(model='llama3.1', input='How to use PostgreSQL indexes')
print(len(result['embeddings'][0]))    # embedding dimensions

Step 6: Custom Models with Modelfile

# Modelfile — Create a custom model with specific behavior
FROM llama3.1

# System prompt baked into the model
SYSTEM """
You are a senior Python developer. You write clean, well-documented code
following PEP 8. You always include type hints and docstrings.
When asked to write code, provide complete, runnable examples.
"""

# Parameters
PARAMETER temperature 0.3
PARAMETER top_p 0.9
PARAMETER num_ctx 8192
# Build and use custom model
ollama create python-coder -f Modelfile
ollama run python-coder

Step 7: GPU Configuration

# Check GPU detection
ollama ps    # shows running models and GPU memory usage

# Environment variables for GPU control
OLLAMA_GPU_LAYERS=35    # number of layers to offload to GPU
CUDA_VISIBLE_DEVICES=0  # select specific GPU

# Memory requirements (approximate):
# 7B model:  ~4GB RAM (GPU) or ~8GB RAM (CPU)
# 13B model: ~8GB RAM (GPU) or ~16GB RAM (CPU)
# 70B model: ~40GB RAM (GPU) or ~64GB RAM (CPU)

Examples

Example 1: Build a private code assistant

User prompt: "I want a code assistant that runs entirely on my machine — no code sent to the cloud. Should handle Python and TypeScript."

The agent will:

  1. Install Ollama and download codellama:13b or deepseek-coder:6.7b.
  2. Create a Modelfile with a system prompt optimized for coding.
  3. Build a simple CLI or web interface using the OpenAI-compatible API.
  4. All inference runs locally — zero data leaves the machine.

Example 2: Run a local RAG pipeline

User prompt: "Index my company's internal docs and let employees query them with an AI — but we can't send data to OpenAI due to compliance."

The agent will:

  1. Set up Ollama with llama3.1 for generation and embeddings.
  2. Chunk documents and store embeddings in a local vector database (ChromaDB).
  3. Build a retrieval pipeline: query → embed → search → generate answer.
  4. Deploy as an internal web app. All processing stays on-premises.

Guidelines

  • Model selection by hardware: 7B models run well on 8GB+ RAM machines; 13B needs 16GB+; 70B needs 64GB+ or a high-end GPU. Start with the smallest model that meets quality requirements.
  • Ollama's API is OpenAI-compatible — the OpenAI SDK, LangChain, LlamaIndex, and most AI frameworks work by just changing the base URL to http://localhost:11434/v1.
  • Use GPU acceleration whenever available — inference is 5-10x faster on GPU than CPU. Ollama auto-detects NVIDIA GPUs with CUDA and Apple Silicon's Metal.
  • Create custom Modelfiles for specific use cases — baking a system prompt and temperature into the model saves tokens and ensures consistent behavior.
  • For production deployments, run Ollama behind a reverse proxy (nginx, Traefik) with authentication. The default API has no auth.
  • Keep models updated (ollama pull model_name) — the community frequently releases improved quantizations and fine-tunes.