fix(platform): 模型能力 - 修复图片时长误判与后台默认参数同步
This commit is contained in:
1 parent
6a698129bd
commit
c7452b701d
6 files changed
+289
-46
No files matched your search
@@ -3,7 +3,7 @@ import { describe, expect, test } from "bun:test";
|
||||
import { canvasConnectionError } from "../src/lib/canvas/canvas-connection-policy";
|
||||
import { assertCanvasImageReferenceLimit, buildGenerationConfig, canvasImageReferenceLimitError, resolveCanvasGenerationModel } from "../src/lib/canvas/canvas-project-generation";
|
||||
import { defaultModelCapabilityConfig } from "../src/lib/model-capabilities";
|
||||
import { groupModelsByDisplayName, modelCompatibilityError, modelGroupReferenceLimits, resolveCompatibleModel } from "../src/lib/model-selection";
|
||||
import { groupModelsByDisplayName, modelCompatibilityError, modelGroupReferenceLimits, resolveCompatibleModel, resolveModelGenerationDefaults } from "../src/lib/model-selection";
|
||||
import { defaultConfig, type AiConfig, type ModelChannel } from "../src/stores/use-config-store";
|
||||
import { CanvasNodeType, type CanvasConnection, type CanvasNodeData } from "../src/types/canvas";
|
||||
|
||||
@@ -53,6 +53,82 @@ function node(id: string, type: CanvasNodeType, generationMode?: "image" | "vide
|
||||
}
|
||||
|
||||
describe("逻辑模型选择", () => {
|
||||
test("图片逻辑模型忽略全局视频时长,不应显示为不支持当前时长", () => {
|
||||
const model = "platform::gpt-image-2";
|
||||
const channel: ModelChannel = {
|
||||
id: "platform",
|
||||
name: "平台模型",
|
||||
baseUrl: "/api",
|
||||
apiKey: "system",
|
||||
apiFormat: "openai",
|
||||
scope: "system",
|
||||
enabled: true,
|
||||
models: ["gpt-image-2"],
|
||||
modelCosts: [{
|
||||
model: "gpt-image-2",
|
||||
displayName: "GPT Image 2",
|
||||
capability: "image",
|
||||
billingMode: "fixed_request",
|
||||
unitPriceMicrocredits: 1,
|
||||
logicalCapabilitySpec: {
|
||||
version: 1,
|
||||
capability: "image",
|
||||
options: { size: { values: ["1:1", "3:2"] } },
|
||||
},
|
||||
}],
|
||||
};
|
||||
const config: AiConfig = {
|
||||
...defaultConfig,
|
||||
channels: [channel],
|
||||
models: [model],
|
||||
imageModels: [model],
|
||||
imageModel: model,
|
||||
model,
|
||||
};
|
||||
|
||||
expect(modelCompatibilityError(config, model, {
|
||||
capability: "image",
|
||||
input: { textCount: 1, imageCount: 0, videoCount: 0, audioCount: 0, characterCount: 0 },
|
||||
videoSeconds: "6",
|
||||
imageSize: "3:2",
|
||||
options: { size: "3:2" },
|
||||
})).toBe("");
|
||||
});
|
||||
|
||||
test("后台图片默认比例优先于旧的全局 1:1 配置", () => {
|
||||
const model = "platform::managed-image";
|
||||
const profile = defaultModelCapabilityConfig(undefined, "managed-image");
|
||||
profile.image!.size = { parameter: "size", values: ["1:1", "16:9"], default: "16:9", allowCustom: false };
|
||||
const config: AiConfig = {
|
||||
...defaultConfig,
|
||||
size: "1:1",
|
||||
channels: [{ id: "platform", name: "平台模型", baseUrl: "/api", apiKey: "system", apiFormat: "openai", scope: "system", models: ["managed-image"], modelCosts: [{ model: "managed-image", capability: "image", billingMode: "fixed_request", unitPriceMicrocredits: 1, logicalModelId: "managed-image", logicalCapabilitySpec: { version: 1, capability: "image" }, capabilityConfig: profile }] }],
|
||||
models: [model],
|
||||
imageModels: [model],
|
||||
imageModel: model,
|
||||
model,
|
||||
};
|
||||
|
||||
expect(resolveModelGenerationDefaults(config, model, "image", {}, { size: "1:1" }).size).toBe("16:9");
|
||||
});
|
||||
|
||||
test("后台视频默认时长优先于旧的全局 6 秒配置", () => {
|
||||
const model = "platform::managed-video";
|
||||
const profile = defaultModelCapabilityConfig(undefined, "managed-video");
|
||||
profile.video!.duration = { selection: "enum", values: [6, 15], default: 15 };
|
||||
const config: AiConfig = {
|
||||
...defaultConfig,
|
||||
videoSeconds: "6",
|
||||
channels: [{ id: "platform", name: "平台模型", baseUrl: "/api", apiKey: "system", apiFormat: "openai", scope: "system", models: ["managed-video"], modelCosts: [{ model: "managed-video", capability: "video", billingMode: "per_second", unitPriceMicrocredits: 1, logicalModelId: "managed-video", logicalCapabilitySpec: { version: 1, capability: "video" }, capabilityConfig: profile }] }],
|
||||
models: [model],
|
||||
videoModels: [model],
|
||||
videoModel: model,
|
||||
model,
|
||||
};
|
||||
|
||||
expect(resolveModelGenerationDefaults(config, model, "video", {}, { videoSeconds: "6" }).videoSeconds).toBe("15");
|
||||
});
|
||||
|
||||
test("后台标注的视频模型不因内部标识缺少视频关键词而回退", () => {
|
||||
const config = policyConfig();
|
||||
const selectedModel = config.videoModels[0]!;
|
||||
|
||||
Reference in new issue
Block a user