fix(admin): 渠道模型 - 补充 1440P 分辨率并支持自定义档位
This commit is contained in:
1 parent
b9d432f218
commit
e26ed02c2e
5 files changed
+24
-3
No files matched your search
@@ -540,6 +540,9 @@ func ratioValue(value string) float64 {
|
|||||||
func normalizeResolution(value string) string {
|
func normalizeResolution(value string) string {
|
||||||
value = strings.ToLower(strings.TrimSpace(value))
|
value = strings.ToLower(strings.TrimSpace(value))
|
||||||
value = strings.TrimSuffix(value, "p")
|
value = strings.TrimSuffix(value, "p")
|
||||||
|
if value == "2k" {
|
||||||
|
return "1440p"
|
||||||
|
}
|
||||||
if value == "4k" {
|
if value == "4k" {
|
||||||
return "2160p"
|
return "2160p"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,3 +82,18 @@ func TestDefaultVideoCapabilityUsesProtocolSpecificResolutionTiers(t *testing.T)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNormalizeResolutionSupportsCommonAliases(t *testing.T) {
|
||||||
|
tests := map[string]string{
|
||||||
|
"1440": "1440p",
|
||||||
|
"1440p": "1440p",
|
||||||
|
"2K": "1440p",
|
||||||
|
"4K": "2160p",
|
||||||
|
"768P": "768p",
|
||||||
|
}
|
||||||
|
for input, want := range tests {
|
||||||
|
if got := normalizeResolution(input); got != want {
|
||||||
|
t.Fatalf("normalizeResolution(%q) = %q, want %q", input, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,9 @@ import type { ReactNode } from "react";
|
|||||||
|
|
||||||
import { defaultImageCapabilityConfig, defaultModelCapabilityConfig, type ImageCapabilityConfig, type ModelCapabilityConfig, type VideoCapabilityConfig } from "@/lib/model-capabilities";
|
import { defaultImageCapabilityConfig, defaultModelCapabilityConfig, type ImageCapabilityConfig, type ModelCapabilityConfig, type VideoCapabilityConfig } from "@/lib/model-capabilities";
|
||||||
import type { ModelProtocol } from "@/lib/model-protocols";
|
import type { ModelProtocol } from "@/lib/model-protocols";
|
||||||
|
import { VIDEO_RESOLUTION_CAPABILITY_OPTIONS } from "@/lib/video-generation-options";
|
||||||
|
|
||||||
const ratioOptions = ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"];
|
const ratioOptions = ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"];
|
||||||
const resolutionOptions = ["480p", "720p", "1080p", "2160p"];
|
|
||||||
const operationOptions = [
|
const operationOptions = [
|
||||||
{ label: "文生视频", value: "text_to_video" },
|
{ label: "文生视频", value: "text_to_video" },
|
||||||
{ label: "图生视频", value: "image_to_video" },
|
{ label: "图生视频", value: "image_to_video" },
|
||||||
@@ -35,6 +35,7 @@ export function ModelCapabilityEditor({ value, onChange, protocol, capability =
|
|||||||
const updateReferences = (patch: Partial<VideoCapabilityConfig["references"]>) => update({ references: { ...profile.references, ...patch } });
|
const updateReferences = (patch: Partial<VideoCapabilityConfig["references"]>) => update({ references: { ...profile.references, ...patch } });
|
||||||
const updateDuration = (patch: Partial<VideoCapabilityConfig["duration"]>) => update({ duration: { ...profile.duration, ...patch } });
|
const updateDuration = (patch: Partial<VideoCapabilityConfig["duration"]>) => update({ duration: { ...profile.duration, ...patch } });
|
||||||
const durationValues = (profile.duration.values || []).join(",");
|
const durationValues = (profile.duration.values || []).join(",");
|
||||||
|
const resolutionOptions = Array.from(new Set([...VIDEO_RESOLUTION_CAPABILITY_OPTIONS, ...profile.resolutions]));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
|
<div className="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
|
||||||
@@ -75,7 +76,7 @@ export function ModelCapabilityEditor({ value, onChange, protocol, capability =
|
|||||||
<div className="grid gap-2 sm:grid-cols-2">
|
<div className="grid gap-2 sm:grid-cols-2">
|
||||||
<Field label="画面比例"><Select mode="multiple" className="w-full" disabled={disabled} value={profile.ratios} options={ratioOptions.map((item) => ({ label: item, value: item }))} onChange={(ratios) => update({ ratios, defaultRatio: ratios.includes(profile.defaultRatio) ? profile.defaultRatio : ratios[0] || "16:9" })} /></Field>
|
<Field label="画面比例"><Select mode="multiple" className="w-full" disabled={disabled} value={profile.ratios} options={ratioOptions.map((item) => ({ label: item, value: item }))} onChange={(ratios) => update({ ratios, defaultRatio: ratios.includes(profile.defaultRatio) ? profile.defaultRatio : ratios[0] || "16:9" })} /></Field>
|
||||||
<Field label="默认比例"><Select className="w-full" disabled={disabled} value={profile.defaultRatio} options={profile.ratios.map((item) => ({ label: item, value: item }))} onChange={(defaultRatio) => update({ defaultRatio })} /></Field>
|
<Field label="默认比例"><Select className="w-full" disabled={disabled} value={profile.defaultRatio} options={profile.ratios.map((item) => ({ label: item, value: item }))} onChange={(defaultRatio) => update({ defaultRatio })} /></Field>
|
||||||
<Field label="输出分辨率"><Select mode="multiple" className="w-full" disabled={disabled} value={profile.resolutions} options={resolutionOptions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(resolutions) => update({ resolutions, defaultResolution: resolutions.includes(profile.defaultResolution) ? profile.defaultResolution : resolutions[0] || "720p" })} /></Field>
|
<Field label="输出分辨率"><Select mode="tags" className="w-full" disabled={disabled} value={profile.resolutions} tokenSeparators={[","]} placeholder="选择标准档位或输入 768p 等模型专属值" options={resolutionOptions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(resolutions) => update({ resolutions, defaultResolution: resolutions.includes(profile.defaultResolution) ? profile.defaultResolution : resolutions[0] || "720p" })} /></Field>
|
||||||
<Field label="默认分辨率"><Select className="w-full" disabled={disabled} value={profile.defaultResolution} options={profile.resolutions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(defaultResolution) => update({ defaultResolution })} /></Field>
|
<Field label="默认分辨率"><Select className="w-full" disabled={disabled} value={profile.defaultResolution} options={profile.resolutions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(defaultResolution) => update({ defaultResolution })} /></Field>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2 sm:grid-cols-2">
|
<div className="grid gap-2 sm:grid-cols-2">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const VIDEO_DURATION_OPTIONS = [6, 9, 10, 15] as const;
|
export const VIDEO_DURATION_OPTIONS = [6, 9, 10, 15] as const;
|
||||||
export const VIDEO_RESOLUTION_OPTIONS = [480, 720, 1080, 1440, 2160] as const;
|
export const VIDEO_RESOLUTION_OPTIONS = [480, 720, 1080, 1440, 2160] as const;
|
||||||
|
export const VIDEO_RESOLUTION_CAPABILITY_OPTIONS = VIDEO_RESOLUTION_OPTIONS.map((value) => `${value}p`);
|
||||||
export const VIDEO_DURATION_MIN = 1;
|
export const VIDEO_DURATION_MIN = 1;
|
||||||
|
|
||||||
export function normalizeVideoDuration(value: string | number | undefined) {
|
export function normalizeVideoDuration(value: string | number | undefined) {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
|
|
||||||
import { defaultModelCapabilityConfig } from "../src/lib/model-capabilities";
|
import { defaultModelCapabilityConfig } from "../src/lib/model-capabilities";
|
||||||
import { normalizeVideoResolution, VIDEO_RESOLUTION_OPTIONS } from "../src/lib/video-generation-options";
|
import { normalizeVideoResolution, VIDEO_RESOLUTION_CAPABILITY_OPTIONS, VIDEO_RESOLUTION_OPTIONS } from "../src/lib/video-generation-options";
|
||||||
|
|
||||||
describe("video generation resolution options", () => {
|
describe("video generation resolution options", () => {
|
||||||
test("统一档位包含 1440P 与 4K,并识别常见别名", () => {
|
test("统一档位包含 1440P 与 4K,并识别常见别名", () => {
|
||||||
expect(VIDEO_RESOLUTION_OPTIONS).toEqual([480, 720, 1080, 1440, 2160]);
|
expect(VIDEO_RESOLUTION_OPTIONS).toEqual([480, 720, 1080, 1440, 2160]);
|
||||||
|
expect(VIDEO_RESOLUTION_CAPABILITY_OPTIONS).toEqual(["480p", "720p", "1080p", "1440p", "2160p"]);
|
||||||
expect(normalizeVideoResolution("2k")).toBe("1440");
|
expect(normalizeVideoResolution("2k")).toBe("1440");
|
||||||
expect(normalizeVideoResolution("1440p")).toBe("1440");
|
expect(normalizeVideoResolution("1440p")).toBe("1440");
|
||||||
expect(normalizeVideoResolution("4K")).toBe("2160");
|
expect(normalizeVideoResolution("4K")).toBe("2160");
|
||||||
|
|||||||
Reference in new issue
Block a user