Skip to content

jersoe/sync_opencode_ollama

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“– Opencode Ollama Sync Script (sync_opencode_ollama.py) Guide

This script synchronizes the list of models configured for the "Ollama" provider within your opencode.json file with the models actually installed on your local Ollama server instance. This ensures that your development environment is always pointing to the correct and current set of available models, preventing "Model not found" type errors in OpenCode.

βš™οΈ Setup & Prerequisites

Before running the script, ensure you have:

  1. Python 3: The script requires Python 3 to run.
  2. Requests Library: Install the necessary Python dependency: pip install requests
  3. Running Ollama Instance: Your local Ollama server must be running in the background (ollama serve).

✨ How It Works

The sync_opencode_ollama.py script performs three main functions:

  1. Discovery: It connects to the configured Ollama API endpoint (defaulting to http://localhost:11434/api/tags) and automatically pulls a list of every model currently available on your Ollama machine (e.g., llava:latest, qwen2:7b).
  2. Loading: It loads the existing configuration from opencode.json (or creates a default one if it doesn't exist).
  3. Synchronization: It updates the specific section for the Ollama provider (provider.ollama.models) to match the discovered list of models.

πŸš€ Usage Guide

1. Basic Sync (Standard Use)

This command connects to Ollama and syncs all current model names into opencode.json.

python3 sync_opencode_ollama.py

2. Specifying a Config File

If your configuration file is not in the default location (~/.config/opencode/opencode.json), use the --config flag:

python3 sync_opencode_ollama.py --config /path/to/your/project/opencode.json

3. Specifying a Custom Ollama Host

If your Ollama server is running on a different machine or port, use --ollama-host:

python3 sync_opencode_ollama.py --ollama-host http://192.168.1.50:11434

πŸ›‘οΈ Maintenance Commands (Highly Recommended)

  • Pruning: If you delete a local model through the ollama rm command, it remains listed in opencode.json. Running the sync with --prune removes orphaned entries from your configuration:

    python3 sync_opencode_ollama.py --prune
  • Dry Run: To see exactly what changes will be made without actually touching your configuration file:

    python3 sync_opencode_ollama.py --dry-run

About

Syncs opencode.json to available Ollama models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages