fix: preserve AtlasCloud model aliases
This commit is contained in:
parent
1a91b8ada9
commit
6ccf04a786
@ -1,6 +1,9 @@
|
|||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { fetchAtlasCloudImagePresets } from "@/lib/ai/atlascloud-models";
|
import {
|
||||||
|
fetchAtlasCloudImagePresets,
|
||||||
|
resolveAtlasCloudDisplayName,
|
||||||
|
} from "@/lib/ai/atlascloud-models";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { getAiProviderById } from "@/lib/db/queries";
|
import { getAiProviderById } from "@/lib/db/queries";
|
||||||
import { type AiModel, aiModel } from "@/lib/db/schema";
|
import { type AiModel, aiModel } from "@/lib/db/schema";
|
||||||
@ -75,7 +78,11 @@ export async function POST(request: Request) {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
const values = {
|
const values = {
|
||||||
displayName: preset.displayName,
|
displayName: resolveAtlasCloudDisplayName(
|
||||||
|
existing?.displayName,
|
||||||
|
preset.displayName,
|
||||||
|
preset.modelId
|
||||||
|
),
|
||||||
avatarUrl: preset.avatarUrl || null,
|
avatarUrl: preset.avatarUrl || null,
|
||||||
description: preset.description,
|
description: preset.description,
|
||||||
supportsVision: preset.supportsVision,
|
supportsVision: preset.supportsVision,
|
||||||
|
|||||||
@ -95,6 +95,17 @@ type JsonRecord = Record<string, any>;
|
|||||||
|
|
||||||
export type AtlasCloudMediaKind = "image" | "video" | "3d";
|
export type AtlasCloudMediaKind = "image" | "video" | "3d";
|
||||||
|
|
||||||
|
export function resolveAtlasCloudDisplayName(
|
||||||
|
existingDisplayName: unknown,
|
||||||
|
catalogDisplayName: unknown,
|
||||||
|
modelId: string
|
||||||
|
) {
|
||||||
|
const existing = String(existingDisplayName || "").trim();
|
||||||
|
if (existing) return existing;
|
||||||
|
|
||||||
|
return String(catalogDisplayName || "").trim() || modelId;
|
||||||
|
}
|
||||||
|
|
||||||
function asRecord(value: unknown): JsonRecord {
|
function asRecord(value: unknown): JsonRecord {
|
||||||
return value && typeof value === "object" && !Array.isArray(value)
|
return value && typeof value === "object" && !Array.isArray(value)
|
||||||
? (value as JsonRecord)
|
? (value as JsonRecord)
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import { and, eq, inArray } from "drizzle-orm";
|
import { and, eq, inArray } from "drizzle-orm";
|
||||||
import { fetchAtlasCloudImagePresets } from "../lib/ai/atlascloud-models";
|
import {
|
||||||
|
fetchAtlasCloudImagePresets,
|
||||||
|
resolveAtlasCloudDisplayName,
|
||||||
|
} from "../lib/ai/atlascloud-models";
|
||||||
import { db } from "../lib/db";
|
import { db } from "../lib/db";
|
||||||
import { aiModel, aiProvider } from "../lib/db/schema";
|
import { aiModel, aiProvider } from "../lib/db/schema";
|
||||||
|
|
||||||
@ -36,7 +39,11 @@ async function main() {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
const values = {
|
const values = {
|
||||||
displayName: preset.displayName,
|
displayName: resolveAtlasCloudDisplayName(
|
||||||
|
existing?.displayName,
|
||||||
|
preset.displayName,
|
||||||
|
preset.modelId
|
||||||
|
),
|
||||||
avatarUrl: preset.avatarUrl || null,
|
avatarUrl: preset.avatarUrl || null,
|
||||||
description: preset.description,
|
description: preset.description,
|
||||||
supportsVision: preset.supportsVision,
|
supportsVision: preset.supportsVision,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { expect, test } from "@playwright/test";
|
|||||||
import {
|
import {
|
||||||
createAtlasCloudImagePreset,
|
createAtlasCloudImagePreset,
|
||||||
inferAtlasCloudMediaKind,
|
inferAtlasCloudMediaKind,
|
||||||
|
resolveAtlasCloudDisplayName,
|
||||||
} from "@/lib/ai/atlascloud-models";
|
} from "@/lib/ai/atlascloud-models";
|
||||||
import { createAtlasCloudRequestBody } from "@/lib/ai/atlascloud-request";
|
import { createAtlasCloudRequestBody } from "@/lib/ai/atlascloud-request";
|
||||||
import {
|
import {
|
||||||
@ -19,6 +20,23 @@ const atlasHunyuan3D = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test.describe("AI model media classification", () => {
|
test.describe("AI model media classification", () => {
|
||||||
|
test("preserves administrator-defined AtlasCloud display names", () => {
|
||||||
|
expect(
|
||||||
|
resolveAtlasCloudDisplayName(
|
||||||
|
"视觉 Flux Kontext Pro",
|
||||||
|
"Flux Kontext Pro",
|
||||||
|
"black-forest-labs/flux-kontext-pro"
|
||||||
|
)
|
||||||
|
).toBe("视觉 Flux Kontext Pro");
|
||||||
|
expect(
|
||||||
|
resolveAtlasCloudDisplayName(
|
||||||
|
"",
|
||||||
|
"Flux Kontext Pro",
|
||||||
|
"black-forest-labs/flux-kontext-pro"
|
||||||
|
)
|
||||||
|
).toBe("Flux Kontext Pro");
|
||||||
|
});
|
||||||
|
|
||||||
test("keeps multi-reference BananaImage models classified as image models", () => {
|
test("keeps multi-reference BananaImage models classified as image models", () => {
|
||||||
const descriptor = {
|
const descriptor = {
|
||||||
providerType: "bananaimage",
|
providerType: "bananaimage",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user