Fix OLLAMA_HOST support (#598)

Fixes #411
This commit is contained in:
Will Chen
2025-07-08 11:37:23 -07:00
committed by GitHub
parent badab05a3a
commit b6fd985d99
2 changed files with 181 additions and 1 deletions

View File

@@ -4,7 +4,40 @@ import { LocalModelListResponse, LocalModel } from "../ipc_types";
const logger = log.scope("ollama_handler");
const OLLAMA_API_URL = process.env.OLLAMA_HOST || "http://localhost:11434";
export function parseOllamaHost(host?: string): string {
if (!host) {
return "http://localhost:11434";
}
// If it already has a protocol, use as-is
if (host.startsWith("http://") || host.startsWith("https://")) {
return host;
}
// Check for bracketed IPv6 with port: [::1]:8080
if (host.startsWith("[") && host.includes("]:")) {
return `http://${host}`;
}
// Check for regular host:port (but not plain IPv6)
if (
host.includes(":") &&
!host.includes("::") &&
host.split(":").length === 2
) {
return `http://${host}`;
}
// Check if it's a plain IPv6 address (contains :: or multiple colons)
if (host.includes("::") || host.split(":").length > 2) {
return `http://[${host}]:11434`;
}
// If it's just a hostname, add default port
return `http://${host}:11434`;
}
const OLLAMA_API_URL = parseOllamaHost(process.env.OLLAMA_HOST);
interface OllamaModel {
name: string;