Initial commit: OmniAI backend server
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {
|
||||
buildDashscopeImageSuperResolveBody,
|
||||
buildDashscopeVideoStyleTransformBody,
|
||||
normalizeImageUpscaleFactor,
|
||||
normalizeVideoStyleTransformOptions,
|
||||
} = require("../src/aiUpscaleHelpers");
|
||||
const { extractVideoUrl } = require("../src/aiTaskWorker");
|
||||
|
||||
function testImageSuperResolveBody() {
|
||||
const body = buildDashscopeImageSuperResolveBody({
|
||||
imageUrl: "https://example.com/input.png",
|
||||
scale: "4x",
|
||||
});
|
||||
|
||||
assert.equal(body.model, "wanx2.1-imageedit");
|
||||
assert.deepEqual(body.input, {
|
||||
function: "super_resolution",
|
||||
prompt: "图像超分。",
|
||||
base_image_url: "https://example.com/input.png",
|
||||
});
|
||||
assert.equal(body.parameters.upscale_factor, 4);
|
||||
assert.equal(body.parameters.n, 1);
|
||||
assert.equal(Object.hasOwn(body.parameters, "watermark"), false);
|
||||
}
|
||||
|
||||
function testVideoStyleTransformBody() {
|
||||
const body = buildDashscopeVideoStyleTransformBody({
|
||||
videoUrl: "https://example.com/input.mp4",
|
||||
style: 7,
|
||||
videoFps: 99,
|
||||
minLen: 540,
|
||||
useSR: true,
|
||||
animateEmotion: false,
|
||||
});
|
||||
|
||||
assert.equal(body.model, "video-style-transform");
|
||||
assert.deepEqual(body.input, {
|
||||
video_url: "https://example.com/input.mp4",
|
||||
});
|
||||
assert.equal(body.parameters.style, 7);
|
||||
assert.equal(body.parameters.video_fps, 25);
|
||||
assert.equal(body.parameters.min_len, 540);
|
||||
assert.equal(body.parameters.use_SR, true);
|
||||
assert.equal(body.parameters.animate_emotion, false);
|
||||
}
|
||||
|
||||
function testNormalizers() {
|
||||
assert.equal(normalizeImageUpscaleFactor("4x"), 4);
|
||||
assert.equal(normalizeImageUpscaleFactor("3"), 2);
|
||||
assert.deepEqual(normalizeVideoStyleTransformOptions({ style: "9", videoFps: 8, minLen: 999 }), {
|
||||
style: 0,
|
||||
videoFps: 15,
|
||||
minLen: 720,
|
||||
useSR: true,
|
||||
animateEmotion: true,
|
||||
});
|
||||
}
|
||||
|
||||
function testVideoStyleResultExtraction() {
|
||||
assert.equal(
|
||||
extractVideoUrl({
|
||||
output: {
|
||||
task_status: "SUCCEEDED",
|
||||
output_video_url: "https://dashscope-result.example.com/result.mp4",
|
||||
},
|
||||
}),
|
||||
"https://dashscope-result.example.com/result.mp4",
|
||||
);
|
||||
}
|
||||
|
||||
function main() {
|
||||
testImageSuperResolveBody();
|
||||
testVideoStyleTransformBody();
|
||||
testNormalizers();
|
||||
testVideoStyleResultExtraction();
|
||||
console.log("ai upscale helper contract tests passed");
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user