Show Ollama model host sources
This commit is contained in:
+102
-29
@@ -31,9 +31,13 @@ type OllamaTag = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OllamaHostKind = "custom" | "linux" | "win" | "wsl2"
|
||||||
|
|
||||||
type OllamaProbeCandidate = {
|
type OllamaProbeCandidate = {
|
||||||
baseUrl: string
|
baseUrl: string
|
||||||
source: string
|
source: string
|
||||||
|
hostKind: OllamaHostKind
|
||||||
|
hostLabel: string
|
||||||
via: "fetch" | "windows-curl"
|
via: "fetch" | "windows-curl"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +49,24 @@ type OllamaProbeResult = OllamaProbeCandidate & {
|
|||||||
elapsedMs: number
|
elapsedMs: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OllamaModelRow = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
model: string
|
||||||
|
modifiedAt: string | null
|
||||||
|
size: number | null
|
||||||
|
sizeLabel: string | null
|
||||||
|
digest: string | null
|
||||||
|
family: string | null
|
||||||
|
parameterSize: string | null
|
||||||
|
quantization: string | null
|
||||||
|
hostKind: OllamaHostKind
|
||||||
|
hostLabel: string
|
||||||
|
source: string
|
||||||
|
baseUrl: string
|
||||||
|
via: OllamaProbeCandidate["via"]
|
||||||
|
}
|
||||||
|
|
||||||
function parsePositiveInteger(value: string | undefined, fallback: number) {
|
function parsePositiveInteger(value: string | undefined, fallback: number) {
|
||||||
const parsed = Number.parseInt(String(value || ""), 10)
|
const parsed = Number.parseInt(String(value || ""), 10)
|
||||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback
|
||||||
@@ -102,19 +124,28 @@ function formatBytes(size: unknown) {
|
|||||||
return `${value >= 10 || unit === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[unit]}`
|
return `${value >= 10 || unit === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[unit]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function modelRowsFromTags(data: any) {
|
function modelRowsFromTags(data: any, origin: OllamaProbeCandidate): OllamaModelRow[] {
|
||||||
return Array.isArray(data?.models)
|
return Array.isArray(data?.models)
|
||||||
? data.models.map((item: OllamaTag) => ({
|
? data.models.map((item: OllamaTag) => {
|
||||||
name: item.model || item.name || "",
|
const name = item.model || item.name || ""
|
||||||
model: item.model || item.name || "",
|
return {
|
||||||
modifiedAt: item.modified_at || null,
|
id: `${origin.hostKind}:${name}`,
|
||||||
size: typeof item.size === "number" ? item.size : null,
|
name,
|
||||||
sizeLabel: formatBytes(item.size),
|
model: name,
|
||||||
digest: item.digest || null,
|
modifiedAt: item.modified_at || null,
|
||||||
family: item.details?.family || null,
|
size: typeof item.size === "number" ? item.size : null,
|
||||||
parameterSize: item.details?.parameter_size || null,
|
sizeLabel: formatBytes(item.size),
|
||||||
quantization: item.details?.quantization_level || null,
|
digest: item.digest || null,
|
||||||
})).filter((item: { name: string }) => item.name)
|
family: item.details?.family || null,
|
||||||
|
parameterSize: item.details?.parameter_size || null,
|
||||||
|
quantization: item.details?.quantization_level || null,
|
||||||
|
hostKind: origin.hostKind,
|
||||||
|
hostLabel: origin.hostLabel,
|
||||||
|
source: origin.source,
|
||||||
|
baseUrl: origin.baseUrl,
|
||||||
|
via: origin.via,
|
||||||
|
}
|
||||||
|
}).filter((item: { name: string }) => item.name)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,17 +201,29 @@ function hostUrl(host: string, port = DEFAULT_OLLAMA_PORT) {
|
|||||||
return `http://${formattedHost}:${port}`
|
return `http://${formattedHost}:${port}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFetchCandidate(candidates: OllamaProbeCandidate[], value: string | undefined, source: string) {
|
function addFetchCandidate(
|
||||||
|
candidates: OllamaProbeCandidate[],
|
||||||
|
value: string | undefined,
|
||||||
|
source: string,
|
||||||
|
hostKind: OllamaHostKind,
|
||||||
|
hostLabel: string,
|
||||||
|
) {
|
||||||
const baseUrl = normalizeOllamaBaseUrl(value)
|
const baseUrl = normalizeOllamaBaseUrl(value)
|
||||||
if (!baseUrl) return
|
if (!baseUrl) return
|
||||||
candidates.push({ baseUrl, source, via: "fetch" })
|
candidates.push({ baseUrl, source, hostKind, hostLabel, via: "fetch" })
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWindowsCurlCandidate(candidates: OllamaProbeCandidate[], value: string | undefined, source: string) {
|
function addWindowsCurlCandidate(
|
||||||
|
candidates: OllamaProbeCandidate[],
|
||||||
|
value: string | undefined,
|
||||||
|
source: string,
|
||||||
|
hostKind: OllamaHostKind,
|
||||||
|
hostLabel: string,
|
||||||
|
) {
|
||||||
if (process.env.OPENSHELL_OLLAMA_WINDOWS_INTEROP === "0") return
|
if (process.env.OPENSHELL_OLLAMA_WINDOWS_INTEROP === "0") return
|
||||||
const baseUrl = normalizeOllamaBaseUrl(value)
|
const baseUrl = normalizeOllamaBaseUrl(value)
|
||||||
if (!baseUrl) return
|
if (!baseUrl) return
|
||||||
candidates.push({ baseUrl, source, via: "windows-curl" })
|
candidates.push({ baseUrl, source, hostKind, hostLabel, via: "windows-curl" })
|
||||||
}
|
}
|
||||||
|
|
||||||
function dedupeCandidates(candidates: OllamaProbeCandidate[]) {
|
function dedupeCandidates(candidates: OllamaProbeCandidate[]) {
|
||||||
@@ -211,23 +254,25 @@ async function buildProbeCandidates() {
|
|||||||
const candidates: OllamaProbeCandidate[] = []
|
const candidates: OllamaProbeCandidate[] = []
|
||||||
const wsl = await isWslRuntime()
|
const wsl = await isWslRuntime()
|
||||||
|
|
||||||
addFetchCandidate(candidates, process.env.OPENSHELL_OLLAMA_BASE_URL, "OPENSHELL_OLLAMA_BASE_URL")
|
addFetchCandidate(candidates, process.env.OPENSHELL_OLLAMA_BASE_URL, "OPENSHELL_OLLAMA_BASE_URL", "custom", "CUSTOM")
|
||||||
addFetchCandidate(candidates, process.env.OLLAMA_BASE_URL, "OLLAMA_BASE_URL")
|
addFetchCandidate(candidates, process.env.OLLAMA_BASE_URL, "OLLAMA_BASE_URL", "custom", "CUSTOM")
|
||||||
addFetchCandidate(candidates, process.env.OLLAMA_HOST, "OLLAMA_HOST")
|
addFetchCandidate(candidates, process.env.OLLAMA_HOST, "OLLAMA_HOST", "custom", "CUSTOM")
|
||||||
for (const host of customHostCandidates()) {
|
for (const host of customHostCandidates()) {
|
||||||
addFetchCandidate(candidates, customHostUrl(host), "OPENSHELL_OLLAMA_HOSTS")
|
addFetchCandidate(candidates, customHostUrl(host), "OPENSHELL_OLLAMA_HOSTS", "custom", "CUSTOM")
|
||||||
}
|
}
|
||||||
addFetchCandidate(candidates, DEFAULT_OLLAMA_URL, wsl ? "wsl-localhost" : "localhost")
|
addFetchCandidate(candidates, DEFAULT_OLLAMA_URL, wsl ? "wsl-localhost" : "localhost", wsl ? "wsl2" : "linux", wsl ? "WSL2" : "LINUX")
|
||||||
|
|
||||||
if (wsl) {
|
if (wsl) {
|
||||||
for (const host of await readWslHostCandidates()) {
|
for (const host of await readWslHostCandidates()) {
|
||||||
addFetchCandidate(candidates, hostUrl(host), "wsl-windows-host")
|
addFetchCandidate(candidates, hostUrl(host), "wsl-windows-host", "win", "WIN")
|
||||||
}
|
}
|
||||||
addFetchCandidate(candidates, hostUrl("host.docker.internal"), "host.docker.internal")
|
addFetchCandidate(candidates, hostUrl("host.docker.internal"), "host.docker.internal", "win", "WIN")
|
||||||
addWindowsCurlCandidate(
|
addWindowsCurlCandidate(
|
||||||
candidates,
|
candidates,
|
||||||
process.env.OPENSHELL_WINDOWS_OLLAMA_BASE_URL || DEFAULT_OLLAMA_URL,
|
process.env.OPENSHELL_WINDOWS_OLLAMA_BASE_URL || DEFAULT_OLLAMA_URL,
|
||||||
"windows-localhost",
|
"windows-localhost",
|
||||||
|
"win",
|
||||||
|
"WIN",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,6 +284,8 @@ function publicProbeResult(result: OllamaProbeResult) {
|
|||||||
ok: result.ok,
|
ok: result.ok,
|
||||||
baseUrl: result.baseUrl,
|
baseUrl: result.baseUrl,
|
||||||
source: result.source,
|
source: result.source,
|
||||||
|
hostKind: result.hostKind,
|
||||||
|
hostLabel: result.hostLabel,
|
||||||
via: result.via,
|
via: result.via,
|
||||||
status: result.status ?? null,
|
status: result.status ?? null,
|
||||||
elapsedMs: result.elapsedMs,
|
elapsedMs: result.elapsedMs,
|
||||||
@@ -246,6 +293,24 @@ function publicProbeResult(result: OllamaProbeResult) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function aggregateModels(results: OllamaProbeResult[]) {
|
||||||
|
const seen = new Set<string>()
|
||||||
|
const models: OllamaModelRow[] = []
|
||||||
|
for (const result of results.filter((item) => item.ok)) {
|
||||||
|
for (const model of modelRowsFromTags(result.data, result)) {
|
||||||
|
const key = `${model.hostKind}:${model.name}`
|
||||||
|
if (seen.has(key)) continue
|
||||||
|
seen.add(key)
|
||||||
|
models.push(model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return models.sort((a, b) => {
|
||||||
|
const sourceOrder = { wsl2: 0, win: 1, linux: 2, custom: 3 } as Record<OllamaHostKind, number>
|
||||||
|
const sourceDiff = sourceOrder[a.hostKind] - sourceOrder[b.hostKind]
|
||||||
|
return sourceDiff || a.name.localeCompare(b.name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function probeErrorMessage(error: unknown) {
|
function probeErrorMessage(error: unknown) {
|
||||||
if (error instanceof Error && error.name === "AbortError") return "Ollama probe timed out"
|
if (error instanceof Error && error.name === "AbortError") return "Ollama probe timed out"
|
||||||
return error instanceof Error ? error.message : "Failed to fetch Ollama models"
|
return error instanceof Error ? error.message : "Failed to fetch Ollama models"
|
||||||
@@ -344,16 +409,24 @@ export async function GET() {
|
|||||||
])
|
])
|
||||||
|
|
||||||
const results = await Promise.all(candidates.map(probeCandidate))
|
const results = await Promise.all(candidates.map(probeCandidate))
|
||||||
const available = results.find((result) => result.ok)
|
const availableResults = results.filter((result) => result.ok)
|
||||||
|
|
||||||
if (available) {
|
if (availableResults.length > 0) {
|
||||||
const models = modelRowsFromTags(available.data)
|
const models = aggregateModels(results)
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
ok: true,
|
ok: true,
|
||||||
available: true,
|
available: true,
|
||||||
baseUrl: available.baseUrl,
|
baseUrl: availableResults[0].baseUrl,
|
||||||
source: available.source,
|
source: availableResults[0].source,
|
||||||
via: available.via,
|
via: availableResults[0].via,
|
||||||
|
sources: availableResults.map((result) => ({
|
||||||
|
baseUrl: result.baseUrl,
|
||||||
|
source: result.source,
|
||||||
|
hostKind: result.hostKind,
|
||||||
|
hostLabel: result.hostLabel,
|
||||||
|
via: result.via,
|
||||||
|
count: modelRowsFromTags(result.data, result).length,
|
||||||
|
})),
|
||||||
models,
|
models,
|
||||||
count: models.length,
|
count: models.length,
|
||||||
elapsedMs: Date.now() - startedAt,
|
elapsedMs: Date.now() - startedAt,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type InferenceResponse = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OllamaModel = {
|
type OllamaModel = {
|
||||||
|
id?: string
|
||||||
name: string
|
name: string
|
||||||
model: string
|
model: string
|
||||||
modifiedAt: string | null
|
modifiedAt: string | null
|
||||||
@@ -32,6 +33,8 @@ type OllamaModel = {
|
|||||||
family: string | null
|
family: string | null
|
||||||
parameterSize: string | null
|
parameterSize: string | null
|
||||||
quantization: string | null
|
quantization: string | null
|
||||||
|
hostLabel?: string | null
|
||||||
|
hostKind?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const providerTypeOptions = [
|
const providerTypeOptions = [
|
||||||
@@ -72,6 +75,19 @@ function FieldLabel({ children }: { children: React.ReactNode }) {
|
|||||||
return <label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{children}</label>
|
return <label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{children}</label>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function OllamaHostBadge({ label }: { label?: string | null }) {
|
||||||
|
if (!label) return null
|
||||||
|
return <span className="shrink-0 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-1.5 py-0.5 text-[9px] font-mono uppercase tracking-wider text-[var(--foreground-dim)]">[{label}]</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
function ollamaModelKey(item: OllamaModel) {
|
||||||
|
return item.id || `${item.hostLabel || "LOCAL"}:${item.name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function ollamaSourceSummary(models: OllamaModel[]) {
|
||||||
|
return Array.from(new Set(models.map((item) => item.hostLabel).filter(Boolean))).join(" + ")
|
||||||
|
}
|
||||||
|
|
||||||
function VllmAdvancedConfiguration({
|
function VllmAdvancedConfiguration({
|
||||||
model,
|
model,
|
||||||
port,
|
port,
|
||||||
@@ -461,8 +477,9 @@ export default function InferenceEndpointPanel() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const models = Array.isArray(data.models) ? data.models : []
|
const models = Array.isArray(data.models) ? data.models : []
|
||||||
|
const sources = ollamaSourceSummary(models)
|
||||||
setOllamaModels(models)
|
setOllamaModels(models)
|
||||||
setOllamaMessage(models.length > 0 ? `${models.length} Ollama model${models.length === 1 ? "" : "s"} available. Click one to load the Ollama endpoint preset.` : "Ollama is reachable but has no models installed.")
|
setOllamaMessage(models.length > 0 ? `${models.length} Ollama model${models.length === 1 ? "" : "s"} available${sources ? ` from ${sources}` : ""}. Click one to load the Ollama endpoint preset.` : "Ollama is reachable but has no models installed.")
|
||||||
if (models[0]?.name) setModel((current) => current || models[0].name)
|
if (models[0]?.name) setModel((current) => current || models[0].name)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setOllamaModels([])
|
setOllamaModels([])
|
||||||
@@ -627,8 +644,8 @@ export default function InferenceEndpointPanel() {
|
|||||||
{ollamaModels.length > 0 ? (
|
{ollamaModels.length > 0 ? (
|
||||||
<div className="mt-3 grid grid-cols-1 md:grid-cols-2 gap-2">
|
<div className="mt-3 grid grid-cols-1 md:grid-cols-2 gap-2">
|
||||||
{ollamaModels.map((item) => (
|
{ollamaModels.map((item) => (
|
||||||
<button key={item.name} type="button" onClick={() => applyOllamaModelPreset(item.name)} className={`rounded-sm border p-3 text-left ${isOllamaEndpoint && model === item.name ? "border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]" : "border-[var(--border-subtle)] bg-[var(--background)] hover:border-[var(--nvidia-green)]"}`}>
|
<button key={ollamaModelKey(item)} type="button" onClick={() => applyOllamaModelPreset(item.name)} className={`rounded-sm border p-3 text-left ${isOllamaEndpoint && model === item.name ? "border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]" : "border-[var(--border-subtle)] bg-[var(--background)] hover:border-[var(--nvidia-green)]"}`}>
|
||||||
<div className="text-xs font-mono text-[var(--foreground)]">{item.name}</div>
|
<div className="flex min-w-0 items-center gap-2 text-xs font-mono text-[var(--foreground)]"><span className="truncate">{item.name}</span><OllamaHostBadge label={item.hostLabel} /></div>
|
||||||
<div className="mt-1 text-[11px] text-[var(--foreground-dim)]">
|
<div className="mt-1 text-[11px] text-[var(--foreground-dim)]">
|
||||||
{[item.parameterSize, item.quantization, item.sizeLabel].filter(Boolean).join(" · ") || item.family || "local model"}
|
{[item.parameterSize, item.quantization, item.sizeLabel].filter(Boolean).join(" · ") || item.family || "local model"}
|
||||||
</div>
|
</div>
|
||||||
@@ -655,7 +672,7 @@ export default function InferenceEndpointPanel() {
|
|||||||
<FieldLabel>Model</FieldLabel>
|
<FieldLabel>Model</FieldLabel>
|
||||||
{isOllamaEndpoint && ollamaModels.length > 0 ? (
|
{isOllamaEndpoint && ollamaModels.length > 0 ? (
|
||||||
<select value={model} onChange={(event) => setModel(event.target.value)} className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-sm font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]">
|
<select value={model} onChange={(event) => setModel(event.target.value)} className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-sm font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]">
|
||||||
{ollamaModels.map((item) => <option key={item.name} value={item.name}>{item.name}</option>)}
|
{ollamaModels.map((item) => <option key={ollamaModelKey(item)} value={item.name}>{item.hostLabel ? `[${item.hostLabel}] ` : ""}{item.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
) : (
|
) : (
|
||||||
<input value={model} onChange={(event) => setModel(event.target.value)} placeholder="provider/model-name" className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-sm font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]" />
|
<input value={model} onChange={(event) => setModel(event.target.value)} placeholder="provider/model-name" className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-sm font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]" />
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ type InferenceRouteStatus = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OllamaModel = {
|
type OllamaModel = {
|
||||||
|
id?: string
|
||||||
name: string
|
name: string
|
||||||
sizeLabel: string | null
|
sizeLabel: string | null
|
||||||
parameterSize: string | null
|
parameterSize: string | null
|
||||||
quantization: string | null
|
quantization: string | null
|
||||||
|
hostLabel?: string | null
|
||||||
|
hostKind?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type SandboxInferenceRoute = {
|
type SandboxInferenceRoute = {
|
||||||
@@ -57,6 +60,15 @@ type SandboxInferenceConfig = {
|
|||||||
updatedAt: string | null
|
updatedAt: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function OllamaHostBadge({ label }: { label?: string | null }) {
|
||||||
|
if (!label) return null
|
||||||
|
return <span className="shrink-0 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-1.5 py-0.5 text-[9px] font-mono uppercase tracking-wider text-[var(--foreground-dim)]">[{label}]</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
function ollamaModelKey(item: OllamaModel) {
|
||||||
|
return item.id || `${item.hostLabel || "LOCAL"}:${item.name}`
|
||||||
|
}
|
||||||
|
|
||||||
function makeRoute(provider: string, model: string, label = ""): SandboxInferenceRoute {
|
function makeRoute(provider: string, model: string, label = ""): SandboxInferenceRoute {
|
||||||
return {
|
return {
|
||||||
id: `${provider}::${model}`,
|
id: `${provider}::${model}`,
|
||||||
@@ -420,8 +432,8 @@ export default function SandboxInferencePanel({
|
|||||||
) : (
|
) : (
|
||||||
<div className="mt-3 grid grid-cols-1 md:grid-cols-2 gap-2">
|
<div className="mt-3 grid grid-cols-1 md:grid-cols-2 gap-2">
|
||||||
{ollamaModels.map((item) => (
|
{ollamaModels.map((item) => (
|
||||||
<button key={item.name} type="button" onClick={() => addRoute(draftProvider, item.name, "Ollama")} className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-left hover:border-[var(--nvidia-green)]">
|
<button key={ollamaModelKey(item)} type="button" onClick={() => addRoute(draftProvider, item.name, "Ollama")} className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-left hover:border-[var(--nvidia-green)]">
|
||||||
<div className="text-xs font-mono text-[var(--foreground)]">{item.name}</div>
|
<div className="flex min-w-0 items-center gap-2 text-xs font-mono text-[var(--foreground)]"><span className="truncate">{item.name}</span><OllamaHostBadge label={item.hostLabel} /></div>
|
||||||
<div className="mt-1 text-[11px] text-[var(--foreground-dim)]">
|
<div className="mt-1 text-[11px] text-[var(--foreground-dim)]">
|
||||||
{[item.parameterSize, item.quantization, item.sizeLabel].filter(Boolean).join(" · ") || "local model"}
|
{[item.parameterSize, item.quantization, item.sizeLabel].filter(Boolean).join(" · ") || "local model"}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user