feat(ollama): Add Ollama provider support with models and configuration, including API endpoints and UI updates.

This commit is contained in:
decolua
2026-03-12 15:24:02 +07:00
parent a224f68e5c
commit 32e3980a13
10 changed files with 158 additions and 28 deletions

View File

@@ -424,6 +424,10 @@ export const PROVIDERS = {
baseUrl: "https://api.hyperbolic.xyz/v1/chat/completions",
format: "openai"
},
ollama: {
baseUrl: "https://ollama.com/api/chat",
format: "openai"
},
deepgram: {
baseUrl: "https://api.deepgram.com/v1/listen",
format: "openai"

View File

@@ -301,6 +301,9 @@ export const PROVIDER_MODELS = {
{ id: "Qwen/Qwen2.5-Coder-32B-Instruct", name: "Qwen 2.5 Coder 32B" },
{ id: "NousResearch/Hermes-3-Llama-3.1-70B", name: "Hermes 3 70B" },
],
ollama: [
{ id: "gpt-oss:120b", name: "GPT OSS 120B" },
],
};
// Helper functions
@@ -372,6 +375,7 @@ export const PROVIDER_ID_TO_ALIAS = {
nebius: "nebius",
siliconflow: "siliconflow",
hyperbolic: "hyperbolic",
ollama: "ollama",
};
export function getModelsByProviderId(providerId) {

BIN
public/providers/ollama.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -214,8 +214,7 @@ export default function ProvidersPage() {
<button
onClick={() => handleBatchTest("oauth")}
disabled={!!testingMode}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${
testingMode === "oauth"
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${testingMode === "oauth"
? "bg-primary/20 border-primary/40 text-primary animate-pulse"
: "bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"
}`}
@@ -252,8 +251,7 @@ export default function ProvidersPage() {
<button
onClick={() => handleBatchTest("free")}
disabled={!!testingMode}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${
testingMode === "free"
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${testingMode === "free"
? "bg-primary/20 border-primary/40 text-primary animate-pulse"
: "bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"
}`}
@@ -289,8 +287,7 @@ export default function ProvidersPage() {
<button
onClick={() => handleBatchTest("apikey")}
disabled={!!testingMode}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${
testingMode === "apikey"
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${testingMode === "apikey"
? "bg-primary/20 border-primary/40 text-primary animate-pulse"
: "bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"
}`}
@@ -328,8 +325,7 @@ export default function ProvidersPage() {
<button
onClick={() => handleBatchTest("compatible")}
disabled={!!testingMode}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${
testingMode === "compatible"
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${testingMode === "compatible"
? "bg-primary/20 border-primary/40 text-primary animate-pulse"
: "bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"
}`}
@@ -449,7 +445,7 @@ function ProviderCard({ providerId, provider, stats, authType, onToggle }) {
<div className="flex items-center gap-3">
<div
className="size-8 rounded-lg flex items-center justify-center"
style={{ backgroundColor: `${provider.color}15` }}
style={{ backgroundColor: `${provider.color?.length > 7 ? provider.color : provider.color + "15"}` }}
>
{imgError ? (
<span className="text-xs font-bold" style={{ color: provider.color }}>
@@ -561,7 +557,7 @@ function ApiKeyProviderCard({ providerId, provider, stats, authType, onToggle })
<div className="flex items-center gap-3">
<div
className="size-8 rounded-lg flex items-center justify-center"
style={{ backgroundColor: `${provider.color}15` }}
style={{ backgroundColor: `${provider.color?.length > 7 ? provider.color : provider.color + "15"}` }}
>
{imgError ? (
<span className="text-xs font-bold" style={{ color: provider.color }}>
@@ -955,8 +951,7 @@ function ProviderTestResultsView({ results }) {
<span className="text-text-muted font-mono tabular-nums">{r.latencyMs}ms</span>
)}
<span
className={`text-[10px] uppercase font-bold px-1.5 py-0.5 rounded ${
r.valid ? "bg-emerald-500/15 text-emerald-400" : "bg-red-500/15 text-red-400"
className={`text-[10px] uppercase font-bold px-1.5 py-0.5 rounded ${r.valid ? "bg-emerald-500/15 text-emerald-400" : "bg-red-500/15 text-red-400"
}`}
>
{r.valid ? "OK" : r.diagnosis?.type || "ERROR"}

View File

@@ -162,6 +162,7 @@ const PROVIDER_MODELS_CONFIG = {
nebius: createOpenAIModelsConfig("https://api.studio.nebius.ai/v1/models"),
siliconflow: createOpenAIModelsConfig("https://api.siliconflow.cn/v1/models"),
hyperbolic: createOpenAIModelsConfig("https://api.hyperbolic.xyz/v1/models"),
ollama: createOpenAIModelsConfig("https://ollama.com/api/tags"),
nanobanana: createOpenAIModelsConfig("https://api.nanobananaapi.ai/v1/models"),
chutes: createOpenAIModelsConfig("https://llm.chutes.ai/v1/models"),
nvidia: createOpenAIModelsConfig("https://integrate.api.nvidia.com/v1/models"),

View File

@@ -460,6 +460,10 @@ async function testApiKeyConnection(connection, effectiveProxy = null) {
const res = await fetchWithConnectionProxy("https://api.hyperbolic.xyz/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
}
case "ollama": {
const res = await fetch("https://ollama.com/api/tags", { headers: { Authorization: `Bearer ${connection.apiKey}` } });
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
}
case "deepgram": {
const res = await fetchWithConnectionProxy("https://api.deepgram.com/v1/projects", { headers: { Authorization: `Token ${connection.apiKey}` } }, effectiveProxy);
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };

View File

@@ -163,6 +163,7 @@ export async function POST(request) {
case "nebius":
case "siliconflow":
case "hyperbolic":
case "ollama":
case "assemblyai":
case "nanobanana":
case "chutes":
@@ -180,6 +181,7 @@ export async function POST(request) {
nebius: "https://api.studio.nebius.ai/v1/models",
siliconflow: "https://api.siliconflow.cn/v1/models",
hyperbolic: "https://api.hyperbolic.xyz/v1/models",
ollama: "https://ollama.com/api/tags",
assemblyai: "https://api.assemblyai.com/v1/account",
nanobanana: "https://api.nanobananaapi.ai/v1/models",
chutes: "https://llm.chutes.ai/v1/models",

View File

@@ -47,6 +47,7 @@ export const PROVIDER_ENDPOINTS = {
openai: "https://api.openai.com/v1/chat/completions",
anthropic: "https://api.anthropic.com/v1/messages",
gemini: "https://generativelanguage.googleapis.com/v1beta/models",
ollama: "https://ollama.com/api/chat",
};
// Re-export from providers.js for backward compatibility

View File

@@ -47,8 +47,9 @@ export const APIKEY_PROVIDERS = {
hyperbolic: { id: "hyperbolic", alias: "hyp", name: "Hyperbolic", icon: "bolt", color: "#00D4FF", textIcon: "HY", website: "https://hyperbolic.xyz" },
deepgram: { id: "deepgram", alias: "dg", name: "Deepgram", icon: "mic", color: "#13EF93", textIcon: "DG", website: "https://deepgram.com" },
assemblyai: { id: "assemblyai", alias: "aai", name: "AssemblyAI", icon: "record_voice_over", color: "#0062FF", textIcon: "AA", website: "https://assemblyai.com" },
ollama: { id: "ollama", alias: "ollama", name: "Ollama Cloud", icon: "cloud", color: "#ffffffff", textIcon: "OL", website: "https://ollama.com" },
nanobanana: { id: "nanobanana", alias: "nb", name: "NanoBanana", icon: "image", color: "#FFD700", textIcon: "NB", website: "https://nanobananaapi.ai" },
chutes: { id: "chutes", alias: "ch", name: "Chutes AI", icon: "water_drop", color: "#5B6EF5", textIcon: "CH", website: "https://chutes.ai" },
chutes: { id: "chutes", alias: "ch", name: "Chutes AI", icon: "water_drop", color: "#ffffffff", textIcon: "CH", website: "https://chutes.ai" },
};
export const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";

View File

@@ -0,0 +1,118 @@
import { describe, it, expect } from "vitest";
import { FORMATS } from "../../open-sse/translator/formats.js";
import { translateRequest } from "../../open-sse/translator/index.js";
import { claudeToOpenAIRequest } from "../../open-sse/translator/request/claude-to-openai.js";
import { filterToOpenAIFormat } from "../../open-sse/translator/helpers/openaiHelper.js";
import { parseSSELine } from "../../open-sse/utils/streamHelpers.js";
describe("request normalization", () => {
it("claudeToOpenAIRequest flattens text-only content arrays into string", () => {
const body = {
messages: [
{
role: "user",
content: [
{ type: "text", text: "hi" },
{ type: "text", text: "there" },
],
},
],
};
const result = claudeToOpenAIRequest("gpt-oss:120b", body, true);
expect(result.messages[0].content).toBe("hi\nthere");
});
it("claudeToOpenAIRequest preserves multimodal arrays", () => {
const body = {
messages: [
{
role: "user",
content: [
{ type: "text", text: "describe" },
{
type: "image",
source: {
type: "base64",
media_type: "image/png",
data: "ZmFrZQ==",
},
},
],
},
],
};
const result = claudeToOpenAIRequest("gpt-4o", body, true);
expect(Array.isArray(result.messages[0].content)).toBe(true);
});
it("filterToOpenAIFormat flattens text-only arrays to string", () => {
const body = {
messages: [
{
role: "user",
content: [
{ type: "text", text: "a" },
{ type: "text", text: "b" },
],
},
],
};
const result = filterToOpenAIFormat(JSON.parse(JSON.stringify(body)));
expect(result.messages[0].content).toBe("a\nb");
});
it("translateRequest keeps /v1/messages Claude->OpenAI text payloads string-safe", () => {
const body = {
model: "ollama/gpt-oss:120b",
system: [{ type: "text", text: "You are helpful." }],
messages: [
{
role: "user",
content: [
{ type: "text", text: "hello" },
{ type: "text", text: "world" },
],
},
],
stream: true,
};
const result = translateRequest(
FORMATS.CLAUDE,
FORMATS.OPENAI,
"gpt-oss:120b",
JSON.parse(JSON.stringify(body)),
true,
null,
"ollama",
);
const userMessage = result.messages.find((m) => m.role === "user");
expect(typeof userMessage.content).toBe("string");
expect(userMessage.content).toBe("hello\nworld");
});
it("parseSSELine supports provider raw NDJSON stream lines", () => {
const raw = JSON.stringify({
model: "gpt-oss:120b",
message: { role: "assistant", content: "hello" },
done: false,
});
const parsed = parseSSELine(raw);
expect(parsed).toEqual({
model: "gpt-oss:120b",
message: { role: "assistant", content: "hello" },
done: false,
});
});
it("parseSSELine still supports SSE data lines", () => {
const parsed = parseSSELine('data: {"choices":[{"delta":{"content":"hi"}}]}');
expect(parsed.choices[0].delta.content).toBe("hi");
});
});