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 — opencode: added logic to probe loaded models from lmstudio, ollama an… by goniz · Pull Request #11951 · anomalyco/opencode

opencode: added logic to probe loaded models from lmstudio, ollama an… #11951

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
goniz wants to merge 13 commits into anomalyco:models-endpoint from goniz:models-endpoint-pr

Uh oh!

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

Closed

opencode: added logic to probe loaded models from lmstudio, ollama an… #11951

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
9a47124
opencode: added logic to probe loaded models from lmstudio, ollama an…
goniz Jan 15, 2026
7cd5036
opencode: added local provider url detection
goniz Feb 3, 2026
d07ee24
fix: prevent authorization header from using dummy API key
goniz Feb 3, 2026
10ff727
opencode: initial integration of ProviderModelDetection and LocalProv…
goniz Feb 3, 2026
d54adfb
fix: normalize local provider base urls
goniz Feb 3, 2026
8c10e02
fix: set api id for detected models
goniz Feb 3, 2026
4e4d154
refactor: updated debug provider commands
goniz Feb 3, 2026
fd5aede
fix: comment out adding new models
goniz Feb 3, 2026
75ded5e
fix: prevent local provider detection from running on cloud providers
goniz Feb 3, 2026
2c215da
fix: correct command order and naming for provider commands
goniz Feb 3, 2026
ff2f866
fix: remove 'object' field from OpenAICompatibleResponse causing errors
goniz Feb 3, 2026
1cd128d
add vLLM local provider support
goniz Feb 12, 2026
04a3e4e
add local provider setup in auth login
goniz Feb 13, 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
opencode: added logic to probe loaded models from lmstudio, ollama an…
…d llama-server
  • Loading branch information

Uh oh!

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

@goniz
goniz committed Feb 3, 2026
commit 9a47124e8db7dcfb5484f787e7392b6828c3ce40

There are no files selected for viewing

2 changes: 2 additions & 0 deletions 2 packages/opencode/src/cli/cmd/debug/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { cmd } from "../cmd"
import { ConfigCommand } from "./config"
import { FileCommand } from "./file"
import { LSPCommand } from "./lsp"
import { ProviderCommand } from "./provider"
import { RipgrepCommand } from "./ripgrep"
import { ScrapCommand } from "./scrap"
import { SkillCommand } from "./skill"
Expand All @@ -17,6 +18,7 @@ export const DebugCommand = cmd({
yargs
.command(ConfigCommand)
.command(LSPCommand)
.command(ProviderCommand)
.command(RipgrepCommand)
.command(FileCommand)
.command(ScrapCommand)
Expand Down
31 changes: 31 additions & 0 deletions 31 packages/opencode/src/cli/cmd/debug/provider.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EOL } from "os"
import { LocalProvider, type LocalModel } from "../../../provider/local"
import { cmd } from "../cmd"

export const ProviderCommand = cmd({
command: "provider",
describe: "probe local LLM providers",
builder: (yargs) =>
yargs.command({
command: "probe <type> <url>",
describe: "probe a local provider for loaded models",
builder: (yargs) =>
yargs
.positional("type", {
describe: "provider type",
type: "string",
choices: Object.values(LocalProvider).filter((v) => typeof v === "string") as LocalProvider[],
})
.positional("url", {
describe: "provider URL",
type: "string",
}),
async handler(args) {
const type = args.type as LocalProvider
const url = args.url as string
const result = await LocalProvider.probe(type, url)
process.stdout.write(JSON.stringify(result, null, 2) + EOL)
},
}),
async handler() {},
})
34 changes: 34 additions & 0 deletions 34 packages/opencode/src/provider/local/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Log } from "../../util/log"
import { ollama_probe_loaded_models } from "./ollama"
import { lmstudio_probe_loaded_models } from "./lmstudio"
import { llamaccpp_probe_loaded_models } from "./llamacpp"

export enum LocalProvider {
Ollama = "ollama",
LMStudio = "lmstudio",
LlamaCPP = "llamacpp",
}

export interface LocalModel {
id: string
context_length: number
tool_call: boolean
vision: boolean
}

export namespace LocalProvider {
const log = Log.create({ service: "localprovider" })

export async function probe(provider: LocalProvider, url: string): Promise<LocalModel[]> {
switch (provider) {
case LocalProvider.Ollama:
return await ollama_probe_loaded_models(url)
case LocalProvider.LMStudio:
return await lmstudio_probe_loaded_models(url)
case LocalProvider.LlamaCPP:
return await llamaccpp_probe_loaded_models(url)
default:
throw new Error(`Unsupported provider: ${provider}`)
}
}
}
143 changes: 143 additions & 0 deletions 143 packages/opencode/src/provider/local/llamacpp.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { type LocalModel } from "./index"

export interface LlamaCppModelStatus {
value?: "loaded" | "loading" | "unloaded"
args?: string[]
failed?: boolean
exit_code?: number
}

export interface LlamaCppModelInfo {
id: string
status?: LlamaCppModelStatus
}

export interface LlamaCppModelsResponse {
data?: LlamaCppModelInfo[]
}

export interface LlamaCppV1Model {
id: string
object?: string
meta?: Record<string, unknown> | null
}

export interface LlamaCppV1ModelsResponse {
data?: LlamaCppV1Model[]
object?: string
}

export interface LlamaCppPropsResponse {
default_generation_settings?: {
n_ctx?: number
}
modalities?: {
vision?: boolean
}
chat_template_caps?: Record<string, unknown>
}

function llamaccpp_base_url(url: string): string {
return url.replace(/\/$/, "")
}

function llamaccpp_tool_capable(caps?: Record<string, unknown>): boolean {
if (!caps) return false
const value = caps.supports_tool_calls
return value === true || value === "true"
}

function llamaccpp_context_from_meta(meta?: Record<string, unknown> | null): number {
if (!meta) return 0
const ctxTrain = meta.n_ctx_train
if (typeof ctxTrain === "number" && ctxTrain > 0) return ctxTrain
const ctx = meta.n_ctx
if (typeof ctx === "number" && ctx > 0) return ctx
return 0
}

async function llamaccpp_fetch_models(url: string): Promise<LlamaCppModelsResponse | null> {
const endpoint = llamaccpp_base_url(url) + "/models"
const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) return null
return res.json() as Promise<LlamaCppModelsResponse>
}

async function llamaccpp_fetch_v1_models(url: string): Promise<LlamaCppV1ModelsResponse> {
const endpoint = llamaccpp_base_url(url) + "/v1/models"
const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) {
const respText = await res.text()
throw new Error(`LlamaCPP probe failed with status ${res.status}: ${respText}`)
}

return res.json() as Promise<LlamaCppV1ModelsResponse>
}

async function llamaccpp_fetch_props(url: string, model?: string): Promise<LlamaCppPropsResponse> {
const base = llamaccpp_base_url(url)
const query = model ? `?model=${encodeURIComponent(model)}` : ""
const endpoint = `${base}/props${query}`
const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) {
const respText = await res.text()
throw new Error(`LlamaCPP props failed with status ${res.status}: ${respText}`)
}

return res.json() as Promise<LlamaCppPropsResponse>
}

async function llamaccpp_model_from_props(url: string, id: string, model?: string): Promise<LocalModel> {
const props = await llamaccpp_fetch_props(url, model)
const context = props.default_generation_settings?.n_ctx ?? 0
const vision = props.modalities?.vision === true
const tool_call = llamaccpp_tool_capable(props.chat_template_caps)

return {
id,
context_length: context,
tool_call,
vision,
}
}

async function llamaccpp_model_from_props_or_meta(
url: string,
id: string,
model: string | undefined,
meta?: Record<string, unknown> | null,
): Promise<LocalModel> {
return llamaccpp_model_from_props(url, id, model).catch(() => ({
id,
context_length: llamaccpp_context_from_meta(meta),
tool_call: false,
vision: false,
}))
}

export async function llamaccpp_probe_loaded_models(url: string): Promise<LocalModel[]> {
const models = await llamaccpp_fetch_models(url).catch(() => null)
if (models) {
const items = models.data ?? []
const router = items.some((m) => m.status)
if (router) {
const loaded = items.filter((m) => m.status?.value === "loaded")
if (loaded.length === 0) return []
const v1 = await llamaccpp_fetch_v1_models(url).catch(() => ({ data: [] }) as LlamaCppV1ModelsResponse)
const map = new Map(v1.data?.map((m) => [m.id, m.meta]) ?? [])
return Promise.all(
loaded.map((m) => {
const id = m.id
const meta = map.get(id) ?? null
return llamaccpp_model_from_props_or_meta(url, id, id, meta)
}),
)
}
}

const v1 = await llamaccpp_fetch_v1_models(url)
const v1items = v1.data ?? []
if (v1items.length === 0) return []

return Promise.all(v1items.map((m) => llamaccpp_model_from_props_or_meta(url, m.id, m.id, m.meta)))
}
47 changes: 47 additions & 0 deletions 47 packages/opencode/src/provider/local/lmstudio.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { type LocalModel } from "./index"

export interface LMStudioModel {
id: string
object: "model"
type: "llm" | "vlm" | "embeddings"
publisher: string
arch: string
compatibility_type: string
quantization: string
state: "loaded" | "loading" | "not-loaded"
max_context_length: number
loaded_context_length?: number
capabilities?: string[]
}

export interface LMStudioModelsResponse {
data: LMStudioModel[]
object: "list"
}

export async function lmstudio_probe_loaded_models(url: string): Promise<LocalModel[]> {
const endpoint = url.replace(/\/$/, "") + "/api/v0/models"

const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) {
const respText = await res.text()
throw new Error(`LMStudio probe failed with status ${res.status}: ${respText}`)
}

const body = (await res.json()) as LMStudioModelsResponse
if (!body.data) {
throw new Error("LMStudio probe failed: no data field in response")
}

const loaded_models = body.data
.filter((m) => m.state === "loaded")
.filter((m) => m.type === "llm" || m.type === "vlm")
.filter((m) => m.loaded_context_length && m.loaded_context_length > 0)

return loaded_models.map((m) => ({
id: m.id,
context_length: m.loaded_context_length as number,
tool_call: m.capabilities ? m.capabilities.includes("tool_use") : false,
vision: m.type === "vlm",
}))
}
84 changes: 84 additions & 0 deletions 84 packages/opencode/src/provider/local/ollama.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { type LocalModel } from "./index"

export interface OllamaModelDetails {
parent_model?: string
format?: string
family?: string
families?: string[]
parameter_size?: string
quantization_level?: string
}

export interface OllamaLoadedModel {
name: string
model: string
size: number
digest: string
details?: OllamaModelDetails
expires_at?: string
size_vram: number
context_length: number
}

export interface OllamaLoadedModelsResponse {
models: OllamaLoadedModel[]
}

export interface OllamaModelShowResponse {
parameters?: string
license?: string
capabilities?: string[]
modified_at?: string
details?: OllamaModelDetails
template?: string
model_info?: Record<string, any>
}

async function ollama_show_model(url: string, model: string): Promise<OllamaModelShowResponse> {
const endpoint = url.replace(/\/$/, "") + "/api/show"

const res = await fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model }),
signal: AbortSignal.timeout(3000),
})

if (!res.ok) {
const respText = await res.text()
throw new Error(`Ollama show model failed with status ${res.status}: ${respText}`)
}

return res.json() as Promise<OllamaModelShowResponse>
}

export async function ollama_probe_loaded_models(url: string): Promise<LocalModel[]> {
const endpoint = url.replace(/\/$/, "") + "/api/ps"

const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) {
const respText = await res.text()
throw new Error(`Ollama probe failed with status ${res.status}: ${respText}`)
}

const body = (await res.json()) as OllamaLoadedModelsResponse
if (body.models === undefined) {
throw new Error("Ollama probe failed: no models field in response")
}

const models: LocalModel[] = await Promise.all(
body.models.map(async (m) => {
const show = await ollama_show_model(url, m.model).catch(() => ({} as OllamaModelShowResponse))
const caps = show.capabilities ?? []

return {
id: m.name,
context_length: m.context_length,
tool_call: caps.includes("tools"),
vision: caps.includes("vision"),
}
})
)

return models
}
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.