Enhance image and embedding provider support

- Added new image models for GPT 5.2, 5.3, and 5.4, including capabilities for text-to-image and editing.
- Updated embedding handling to include optional dimensions in requests.
- Introduced support for custom embedding providers, allowing dynamic fetching and validation of custom nodes.
- Improved image generation handling with Codex integration, including progress tracking and error handling.
- Enhanced UI components to support adding custom embeddings and displaying their status.
This commit is contained in:
decolua
2026-04-25 16:22:30 +07:00
parent cca615eaff
commit 0b8bed5793
19 changed files with 1039 additions and 130 deletions

View File

@@ -23,7 +23,7 @@ function isGeminiProvider(provider) {
* - Single input → embedContent body: { model, content: { parts: [{ text }] } }
* - Batch input → batchEmbedContents body: { requests: [{ model, content: { parts: [{ text }] } }] }
*/
function buildEmbeddingsBody(provider, model, input, encodingFormat) {
function buildEmbeddingsBody(provider, model, input, encodingFormat, dimensions) {
if (isGeminiProvider(provider)) {
// Normalize model name: Gemini API expects "models/<model>" prefix
const geminiModel = model.startsWith("models/") ? model : `models/${model}`;
@@ -50,6 +50,10 @@ function buildEmbeddingsBody(provider, model, input, encodingFormat) {
if (encodingFormat) {
body.encoding_format = encodingFormat;
}
if (dimensions != null && dimensions !== "") {
const dim = Number(dimensions);
if (Number.isFinite(dim) && dim > 0) body.dimensions = dim;
}
return body;
}
@@ -79,10 +83,12 @@ function buildEmbeddingsUrl(provider, model, credentials, input) {
case "openrouter":
return "https://openrouter.ai/api/v1/embeddings";
default:
// openai-compatible providers: use their baseUrl + /embeddings
if (provider?.startsWith?.("openai-compatible-")) {
const baseUrl = credentials?.providerSpecificData?.baseUrl || "https://api.openai.com/v1";
return `${baseUrl.replace(/\/$/, "")}/embeddings`;
// openai-compatible & custom-embedding providers: use their baseUrl + /embeddings
if (provider?.startsWith?.("openai-compatible-") || provider?.startsWith?.("custom-embedding-")) {
const rawBaseUrl = credentials?.providerSpecificData?.baseUrl || "https://api.openai.com/v1";
// Defensive: strip trailing slash and accidental /embeddings to avoid double-append
const baseUrl = rawBaseUrl.replace(/\/$/, "").replace(/\/embeddings$/, "");
return `${baseUrl}/embeddings`;
}
// For other providers, attempt to use their base URL pattern with /embeddings path
return null;
@@ -211,7 +217,7 @@ export async function handleEmbeddingsCore({
}
const headers = buildEmbeddingsHeaders(provider, credentials);
const requestBody = buildEmbeddingsBody(provider, model, input, encodingFormat);
const requestBody = buildEmbeddingsBody(provider, model, input, encodingFormat, body.dimensions);
log?.debug?.("EMBEDDINGS", `${provider.toUpperCase()} | ${model} | input_type=${Array.isArray(input) ? `array[${input.length}]` : "string"}`);