mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 05:31:47 +00:00
- Single-source registry: oauth clientId/tokenUrl, usage URLs, image/embed configs, search defaultModel, codex fixedPort, google token url derive. - Remove 29 unused OmniRoute providers (registry 100→71); media intact. - De-adhoc: codex literals → registry format/oauth flags; reasoningInject, image/embed openrouter headers + xai bodyFields config-driven. - Add REGISTRY_TEMPLATE.js + expand PROVIDER_DEFAULTS/schema JSDoc. - Baselines updated; PROVIDERS 62 + alias 90 byte-for-byte, golden snapshots. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// OpenAI-compatible embeddings adapter (most providers)
|
|
import { bearerAuth } from "./_base.js";
|
|
import { PROVIDER_MEDIA } from "../../providers/index.js";
|
|
|
|
// media-only providers without a registry file keep URL here; rest derive from registry media.embeddingConfig.baseUrl
|
|
const ENDPOINTS = {
|
|
"voyage-ai": "https://api.voyageai.com/v1/embeddings",
|
|
"jina-ai": "https://api.jina.ai/v1/embeddings",
|
|
};
|
|
|
|
const embedCfg = (id) => PROVIDER_MEDIA[id]?.embeddingConfig || {};
|
|
const embedUrl = (id) => embedCfg(id).baseUrl || ENDPOINTS[id];
|
|
|
|
export default function createOpenAIEmbeddingAdapter(providerId) {
|
|
const cfg = embedCfg(providerId);
|
|
return {
|
|
buildUrl: () => embedUrl(providerId),
|
|
buildHeaders: (creds) => {
|
|
return { "Content-Type": "application/json", ...bearerAuth(creds), ...(cfg.headers || {}) };
|
|
},
|
|
buildBody: (model, { input, encoding_format, dimensions }) => {
|
|
const body = { model, input };
|
|
if (encoding_format) body.encoding_format = encoding_format;
|
|
if (dimensions != null && dimensions !== "") {
|
|
const dim = Number(dimensions);
|
|
if (Number.isFinite(dim) && dim > 0) body.dimensions = dim;
|
|
}
|
|
return body;
|
|
},
|
|
normalize: (responseBody) => responseBody,
|
|
};
|
|
}
|