GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add ollama integration by Kheiden · Pull Request #21271 · anomalyco/opencode

feat: add ollama integration #21271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kheiden wants to merge 3 commits into anomalyco:dev from kheiden-com:feature/ollama-integration

Uh oh!

There was an error while loading. Please reload this page.

Closed

feat: add ollama integration #21271

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
b332891
feat: add ollama integration
Apr 7, 2026
b5439a0
fix: ollama integration fixes and documentation
Apr 7, 2026
374127d
fix(provider): correctly initialize ollama provider for dynamic disco…
Apr 7, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
feat: add ollama integration
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

opencode-agent
opencode-agent committed Apr 7, 2026
commit b332891c65323e81cc50b5cf53bd33a8c94070f7

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 packages/app/src/hooks/use-providers.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const popularProviders = [
"google",
"openrouter",
"vercel",
"ollama",
]
const popularProviderSet = new Set(popularProviders)

Expand Down
18 changes: 9 additions & 9 deletions 18 packages/opencode/bin/opencode
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

const childProcess = require("child_process")
const fs = require("fs")
const path = require("path")
const os = require("os")
import { spawnSync } from "child_process"
import fs from "fs"
import path from "path"
import os from "os"

function run(target) {
const result = childProcess.spawnSync(target, process.argv.slice(2), {
const result = spawnSync(target, process.argv.slice(2), {
stdio: "inherit",
})
if (result.error) {
Expand All @@ -22,7 +22,7 @@ if (envPath) {
run(envPath)
}

const scriptPath = fs.realpathSync(__filename)
const scriptPath = fs.realpathSync(import.meta.url.replace('file://', ''))
const scriptDir = path.dirname(scriptPath)

//
Expand Down Expand Up @@ -66,7 +66,7 @@ function supportsAvx2() {

if (platform === "darwin") {
try {
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
const result = spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
encoding: "utf8",
timeout: 1500,
})
Expand All @@ -83,7 +83,7 @@ function supportsAvx2() {

for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
try {
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
const result = spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
encoding: "utf8",
timeout: 3000,
windowsHide: true,
Expand Down Expand Up @@ -116,7 +116,7 @@ const names = (() => {
}

try {
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
const result = spawnSync("ldd", ["--version"], { encoding: "utf8" })
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
if (text.includes("musl")) return true
} catch {
Expand Down
7 changes: 7 additions & 0 deletions 7 packages/opencode/src/config/config.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,13 @@ export namespace Config {
.describe("Timeout in milliseconds for model context protocol (MCP) requests"),
})
.optional(),
ollama: z
.object({
host: z.string().optional().describe("Ollama server host URL"),
port: z.number().int().positive().optional().describe("Ollama server port"),
})
.optional()
.describe("Ollama server configuration"),
})
.strict()
.meta({
Expand Down
74 changes: 68 additions & 6 deletions 74 packages/opencode/src/provider/provider.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,61 @@ export namespace Provider {
},
},
}),
ollama: Effect.fnUntraced(function* (input: Info) {
const config = (yield* dep.config()).ollama
if (!config || !config.host) return { autoload: false }

const baseURL = `${config.host}:${config.port ?? 11434}/api`

return {
autoload: true,
options: {
baseURL,
},
async discoverModels(): Promise<Record<string, Model>> {
try {
const response = await fetch(`${baseURL}/tags`)
const data = await response.json()
const models: Record<string, Model> = {}
for (const model of data.models) {
models[model.name] = {
id: ModelID.make(model.name),
providerID: ProviderID.make("ollama"),
name: model.name,
api: {
id: model.name,
url: baseURL,
npm: "@ai-sdk/openai-compatible",
},
status: "active",
headers: {},
options: {},
cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
limit: { context: 8192, output: 2048 },
capabilities: {
temperature: true,
reasoning: false,
attachment: true,
toolcall: true,
input: { text: true, audio: false, image: true, video: false, pdf: false },
output: { text: true, audio: false, image: false, video: false, pdf: false },
interleaved: false,
},
release_date: model.modified_at,
variants: {},
}
}
return models
} catch (e) {
log.warn("ollama model discovery failed", { error: e })
return {}
}
},
async getModel(sdk: any, modelID: string) {
return sdk.chat(modelID)
},
}
}),
}
}

Expand Down Expand Up @@ -1231,22 +1286,29 @@ export namespace Provider {
mergeProvider(providerID, partial)
}

const gitlab = ProviderID.make("gitlab")
if (discoveryLoaders[gitlab] && providers[gitlab] && isProviderAllowed(gitlab)) {
// Run discovery for all providers that have a loader
for (const [id, loader] of Object.entries(discoveryLoaders)) {
if (!providers[id as ProviderID] || !isProviderAllowed(id as ProviderID)) continue
yield* Effect.promise(async () => {
try {
const discovered = await discoveryLoaders[gitlab]()
const discovered = await loader()
for (const [modelID, model] of Object.entries(discovered)) {
if (!providers[gitlab].models[modelID]) {
providers[gitlab].models[modelID] = model
if (!providers[id as ProviderID].models[modelID]) {
providers[id as ProviderID].models[modelID] = model
}
}
} catch (e) {
log.warn("state discovery error", { id: "gitlab", error: e })
log.warn("state discovery error", { id, error: e })
}
})
}

const gitlab = ProviderID.make("gitlab")
if (discoveryLoaders[gitlab] && providers[gitlab] && isProviderAllowed(gitlab)) {
// GitLab is already handled above by the generic loop, but keep here if needed for specific logic.
// Or remove redundant logic if generic loop suffices.
}

for (const hook of plugins) {
const p = hook.provider
const models = p?.models
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.