mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 13:52:09 +03:00
feat(providers): add Qiniu OpenAI-compatible provider (#5966)
* feat(providers): add Qiniu OpenAI-compatible provider Wires Qiniu (七牛云) AI inference gateway as a BYOK API-key provider. Qiniu proxies many upstream models (DeepSeek V3/V4, Claude, Kimi and more) behind a single key, so it ships with an empty static seed and relies on passthroughModels + the live /v1/models catalog instead of a single stale hardcoded model id. - metadata: src/shared/constants/providers/apikey/gateways.ts - registry entry: open-sse/config/providers/registry/qiniu/index.ts (format openai, executor default, bearer auth, baseUrl https://api.qnaigc.com/v1/chat/completions, modelsUrl https://api.qnaigc.com/v1/models) - added to NAMED_OPENAI_STYLE_PROVIDERS so model import serves the live catalog and falls back to the (empty) local catalog on error, same pattern as the existing dgrid/zenmux/orcarouter gateways - tests: tests/unit/qiniu-provider.test.ts (metadata, registry resolution, passthrough validation, live /v1/models fetch + fallback) Co-authored-by: JiangZhuo <jiangzhuo@qiniu.com> Inspired-by: https://github.com/decolua/9router/pull/911 * chore(changelog): restore release entries + add qiniu bullet * test(golden): regenerate translate-path for qiniu provider * test(providers): bump APIKEY count 160→161 for qiniu --------- Co-authored-by: JiangZhuo <jiangzhuo@qiniu.com>
This commit is contained in:
committed by
GitHub
parent
7aaf109c0c
commit
a518ce8f8a
@@ -21,6 +21,7 @@
|
||||
- **feat(providers):** add NVIDIA NIM image generation (FLUX models). (thanks @eng2007)
|
||||
- **feat(providers):** add Augment (Auggie CLI) as a local no-auth provider. (thanks @chamdanilukman)
|
||||
- **feat(providers):** add ModelScope as an OpenAI-compatible (API-key) provider. (thanks @tn5052)
|
||||
- **feat(providers):** add Qiniu as an OpenAI-compatible (API-key) provider. (thanks @JackChiang233)
|
||||
|
||||
### 🔧 Bug Fixes
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import { yiProvider } from "./registry/yi/index.ts";
|
||||
import { deepseekProvider } from "./registry/deepseek/index.ts";
|
||||
import { deepseek_webProvider } from "./registry/deepseek/web/index.ts";
|
||||
import { dgridProvider } from "./registry/dgrid/index.ts";
|
||||
import { qiniuProvider } from "./registry/qiniu/index.ts";
|
||||
import { kimi_coding_apikeyProvider } from "./registry/kimi/coding-apikey/index.ts";
|
||||
import { kimi_codingProvider } from "./registry/kimi/coding/index.ts";
|
||||
import { kimiProvider } from "./registry/kimi/index.ts";
|
||||
@@ -215,6 +216,7 @@ export const REGISTRY: Record<string, RegistryEntry> = {
|
||||
deepseek: deepseekProvider,
|
||||
"deepseek-web": deepseek_webProvider,
|
||||
dgrid: dgridProvider,
|
||||
qiniu: qiniuProvider,
|
||||
"kimi-coding-apikey": kimi_coding_apikeyProvider,
|
||||
"kimi-coding": kimi_codingProvider,
|
||||
kimi: kimiProvider,
|
||||
|
||||
15
open-sse/config/providers/registry/qiniu/index.ts
Normal file
15
open-sse/config/providers/registry/qiniu/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { RegistryEntry } from "../../shared.ts";
|
||||
|
||||
export const qiniuProvider: RegistryEntry = {
|
||||
id: "qiniu",
|
||||
alias: "qiniu",
|
||||
format: "openai",
|
||||
executor: "default",
|
||||
baseUrl: "https://api.qnaigc.com/v1/chat/completions",
|
||||
authType: "apikey",
|
||||
authHeader: "bearer",
|
||||
modelsUrl: "https://api.qnaigc.com/v1/models",
|
||||
defaultContextLength: 128000,
|
||||
models: [],
|
||||
passthroughModels: true,
|
||||
};
|
||||
@@ -56,6 +56,10 @@ export const NAMED_OPENAI_STYLE_PROVIDERS = new Set([
|
||||
// DGrid is an OpenAI-compatible gateway whose default seed is the free auto-router;
|
||||
// the full model catalog is discovered live from https://api.dgrid.ai/v1/models.
|
||||
"dgrid",
|
||||
// Qiniu (七牛云 AI inference) is an OpenAI-compatible gateway with no static seed —
|
||||
// it proxies many upstream models (DeepSeek, Claude, Kimi...) behind one key, so the
|
||||
// full catalog is discovered live from https://api.qnaigc.com/v1/models.
|
||||
"qiniu",
|
||||
]);
|
||||
|
||||
export function isNamedOpenAIStyleProvider(provider: string): boolean {
|
||||
|
||||
@@ -5,6 +5,7 @@ export const PROVIDER_ENDPOINTS = {
|
||||
agentrouter: "https://agentrouter.org/v1/chat/completions",
|
||||
openrouter: "https://openrouter.ai/api/v1/chat/completions",
|
||||
dgrid: "https://api.dgrid.ai/v1/chat/completions",
|
||||
qiniu: "https://api.qnaigc.com/v1/chat/completions",
|
||||
glm: "https://api.z.ai/api/anthropic/v1/messages",
|
||||
glmt: "https://api.z.ai/api/anthropic/v1/messages",
|
||||
"bailian-coding-plan": "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1/messages",
|
||||
|
||||
@@ -71,6 +71,20 @@ export const APIKEY_PROVIDERS_GATEWAYS = {
|
||||
"Create a DGrid API key at https://dgrid.ai, then use https://api.dgrid.ai/v1 " +
|
||||
"as the OpenAI-compatible base URL.",
|
||||
},
|
||||
qiniu: {
|
||||
id: "qiniu",
|
||||
alias: "qiniu",
|
||||
name: "Qiniu",
|
||||
icon: "cloud",
|
||||
color: "#1E88E5",
|
||||
textIcon: "QN",
|
||||
passthroughModels: true,
|
||||
website: "https://www.qiniu.com",
|
||||
apiHint:
|
||||
"Create a Qiniu AI inference API key at https://portal.qiniu.com/ai-inference/api-key, " +
|
||||
"then paste it here as a Bearer token. OpenAI-compatible endpoint " +
|
||||
"at https://api.qnaigc.com/v1, proxying DeepSeek, Claude, Kimi and more behind one key.",
|
||||
},
|
||||
orcarouter: {
|
||||
id: "orcarouter",
|
||||
alias: "orcarouter",
|
||||
|
||||
@@ -3388,6 +3388,29 @@
|
||||
"stream": "https://qianfan.baidubce.com/v2/chat/completions"
|
||||
}
|
||||
},
|
||||
"qiniu": {
|
||||
"format": "openai",
|
||||
"headers": {
|
||||
"apiKey": {
|
||||
"Accept": "text/event-stream",
|
||||
"Authorization": "Bearer <TOK>",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
"nonStream": {
|
||||
"Authorization": "Bearer <TOK>",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
"oauth": {
|
||||
"Accept": "text/event-stream",
|
||||
"Authorization": "Bearer <TOK>",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"nonStream": "https://api.qnaigc.com/v1/chat/completions",
|
||||
"stream": "https://api.qnaigc.com/v1/chat/completions"
|
||||
}
|
||||
},
|
||||
"qoder": {
|
||||
"format": "openai",
|
||||
"headers": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Characterization of the providers.ts catalog split (god-file decomposition): the host became a
|
||||
// barrel that re-exports 10 data catalogs now living under constants/providers/*, and APIKEY is
|
||||
// merged from 6 semantic family files (apikey/<family>.ts). Locks: the public surface (every catalog
|
||||
// + helpers still exported), the spread-merge integrity (160 APIKEY entries, no loss/dup), and that
|
||||
// + helpers still exported), the spread-merge integrity (161 APIKEY entries, no loss/dup), and that
|
||||
// load-time Zod validation still runs. Pure-data move → behavior must be identical.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
@@ -31,12 +31,12 @@ test("barrel still exports every catalog + key helpers", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("APIKEY_PROVIDERS merges the 6 family files into 160 entries (no loss / no dup)", async () => {
|
||||
test("APIKEY_PROVIDERS merges the 6 family files into 161 entries (no loss / no dup)", async () => {
|
||||
const keys = Object.keys((P as Record<string, object>).APIKEY_PROVIDERS);
|
||||
assert.equal(keys.length, 160);
|
||||
assert.equal(new Set(keys).size, 160, "duplicate keys after spread-merge");
|
||||
assert.equal(keys.length, 161);
|
||||
assert.equal(new Set(keys).size, 161, "duplicate keys after spread-merge");
|
||||
// the merged object's entry-count equals the sum of the 6 semantic family files; families are a
|
||||
// strict partition (every provider in exactly one), so the sum must be exactly 160.
|
||||
// strict partition (every provider in exactly one), so the sum must be exactly 161.
|
||||
const families: [string, string][] = [
|
||||
["gateways", "APIKEY_PROVIDERS_GATEWAYS"],
|
||||
["frontier-labs", "APIKEY_PROVIDERS_FRONTIER"],
|
||||
@@ -56,7 +56,7 @@ test("APIKEY_PROVIDERS merges the 6 family files into 160 entries (no loss / no
|
||||
seen.add(k);
|
||||
}
|
||||
}
|
||||
assert.equal(famTotal, 160, "families must partition all 160 providers");
|
||||
assert.equal(famTotal, 161, "families must partition all 161 providers");
|
||||
});
|
||||
|
||||
test("AI_PROVIDERS Proxy aggregates all sections; lookups resolve", () => {
|
||||
|
||||
148
tests/unit/qiniu-provider.test.ts
Normal file
148
tests/unit/qiniu-provider.test.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
const { APIKEY_PROVIDERS } = await import("../../src/shared/constants/providers.ts");
|
||||
const { PROVIDER_ENDPOINTS } = await import("../../src/shared/constants/config.ts");
|
||||
const { REGISTRY: providerRegistry } = await import("../../open-sse/config/providerRegistry.ts");
|
||||
const { isValidModel } = await import("../../src/shared/constants/models.ts");
|
||||
|
||||
const QINIU_CHAT_URL = "https://api.qnaigc.com/v1/chat/completions";
|
||||
const QINIU_MODELS_URL = "https://api.qnaigc.com/v1/models";
|
||||
|
||||
test("Qiniu is registered as an API-key provider", () => {
|
||||
const entry = APIKEY_PROVIDERS.qiniu;
|
||||
assert.ok(entry, "APIKEY_PROVIDERS.qiniu must be defined");
|
||||
assert.equal(entry.id, "qiniu");
|
||||
assert.equal(entry.alias, "qiniu");
|
||||
assert.equal(entry.name, "Qiniu");
|
||||
assert.equal(entry.website, "https://www.qiniu.com");
|
||||
assert.equal(entry.passthroughModels, true);
|
||||
});
|
||||
|
||||
test("Qiniu exposes the OpenAI-compatible chat completions endpoint", () => {
|
||||
assert.equal(PROVIDER_ENDPOINTS.qiniu, QINIU_CHAT_URL);
|
||||
});
|
||||
|
||||
test("Qiniu registry entry uses OpenAI format with bearer API-key auth", () => {
|
||||
const entry = providerRegistry.qiniu;
|
||||
assert.ok(entry, "providerRegistry.qiniu must be defined");
|
||||
assert.equal(entry.id, "qiniu");
|
||||
assert.equal(entry.alias, "qiniu");
|
||||
assert.equal(entry.format, "openai");
|
||||
assert.equal(entry.executor, "default");
|
||||
assert.equal(entry.authType, "apikey");
|
||||
assert.equal(entry.authHeader, "bearer");
|
||||
assert.equal(entry.baseUrl, QINIU_CHAT_URL);
|
||||
assert.equal(entry.modelsUrl, QINIU_MODELS_URL);
|
||||
assert.equal(entry.passthroughModels, true);
|
||||
});
|
||||
|
||||
test("Qiniu ships no static model seed — relies fully on passthrough + live catalog", () => {
|
||||
const models = providerRegistry.qiniu.models;
|
||||
assert.deepEqual(models, []);
|
||||
});
|
||||
|
||||
test("Qiniu accepts any model id via passthrough models (DeepSeek/Claude/Kimi behind one key)", () => {
|
||||
assert.equal(isValidModel("qiniu", "deepseek-v3"), true);
|
||||
assert.equal(isValidModel("qiniu", "deepseek-v3.2"), true);
|
||||
assert.equal(isValidModel("qiniu", "claude-sonnet-4-5"), true);
|
||||
assert.equal(isValidModel("qiniu", "kimi-k2"), true);
|
||||
});
|
||||
|
||||
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-qiniu-"));
|
||||
process.env.DATA_DIR = TEST_DATA_DIR;
|
||||
|
||||
const core = await import("../../src/lib/db/core.ts");
|
||||
const providersDb = await import("../../src/lib/db/providers.ts");
|
||||
const modelsRoute = await import("../../src/app/api/providers/[id]/models/route.ts");
|
||||
|
||||
async function resetStorage() {
|
||||
core.resetDbInstance();
|
||||
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
test.after(() => {
|
||||
core.resetDbInstance();
|
||||
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
interface ModelsBody {
|
||||
provider: string;
|
||||
connectionId: string;
|
||||
models: Array<{ id: string }>;
|
||||
source?: string;
|
||||
}
|
||||
|
||||
test("Qiniu import fetches the live /v1/models catalog", async () => {
|
||||
await resetStorage();
|
||||
const connection = await providersDb.createProviderConnection({
|
||||
provider: "qiniu",
|
||||
authType: "apikey",
|
||||
name: "qiniu-live",
|
||||
apiKey: "qiniu-key",
|
||||
});
|
||||
|
||||
let fetched = false;
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url) => {
|
||||
if (String(url) === QINIU_MODELS_URL) {
|
||||
fetched = true;
|
||||
return Response.json({
|
||||
object: "list",
|
||||
data: [{ id: "deepseek-v3" }, { id: "deepseek-v4" }, { id: "kimi-k2" }],
|
||||
});
|
||||
}
|
||||
return new Response("not found", { status: 404 });
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await modelsRoute.GET(
|
||||
new Request(`http://localhost/api/providers/${connection.id}/models?refresh=true`),
|
||||
{ params: { id: connection.id } }
|
||||
);
|
||||
assert.equal(response.status, 200);
|
||||
const body = (await response.json()) as ModelsBody;
|
||||
assert.equal(body.provider, "qiniu");
|
||||
assert.equal(body.source, "api", "should serve the live upstream catalog");
|
||||
assert.ok(fetched, `should have probed ${QINIU_MODELS_URL}`);
|
||||
const ids = body.models.map((model) => model.id);
|
||||
assert.ok(ids.includes("deepseek-v3"), `live catalog model missing: ${ids.join(",")}`);
|
||||
assert.ok(ids.includes("kimi-k2"), `live catalog model missing: ${ids.join(",")}`);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test("Qiniu import falls back to an empty local catalog when live fetch fails", async () => {
|
||||
await resetStorage();
|
||||
const connection = await providersDb.createProviderConnection({
|
||||
provider: "qiniu",
|
||||
authType: "apikey",
|
||||
name: "qiniu-fallback",
|
||||
apiKey: "qiniu-key-2",
|
||||
});
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async () => new Response("bad gateway", { status: 502 });
|
||||
|
||||
try {
|
||||
const response = await modelsRoute.GET(
|
||||
new Request(`http://localhost/api/providers/${connection.id}/models?refresh=true`),
|
||||
{ params: { id: connection.id } }
|
||||
);
|
||||
assert.equal(response.status, 200);
|
||||
const body = (await response.json()) as ModelsBody;
|
||||
assert.equal(body.provider, "qiniu");
|
||||
assert.equal(body.source, "local_catalog", "import must not break when upstream is down");
|
||||
assert.deepEqual(
|
||||
body.models.map((model) => model.id),
|
||||
[]
|
||||
);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user