Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/pixverse/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function pixversePortTable(model: PixverseModel): GenerationPortTable {
// continuous shot rather than several cuts.
{ kind: "atMostOneOf", ports: ["multiClip", "lastFrame"] },
{ kind: "atMostOneOf", ports: ["multiClip", "referenceImage"] },
{ kind: "atMostOneOf", ports: ["multiClip", "referenceVideo"] },
// The reference videos carry the length of the generated run.
{ kind: "atMostOneOf", ports: ["duration", "referenceVideo"] },
]
Expand Down Expand Up @@ -132,10 +133,15 @@ const pixverseCommonAttributes: readonly SurfaceAttributeVocabulary[] = [
];

const pixverseAspectRatio: SurfaceAttributeVocabulary = {
name: "aspect-ratio", kind: "literal", required: false, values: [...PIXVERSE_V6_ASPECT_RATIOS],
name: "aspect-ratio", kind: "literal", required: false, values: [...PIXVERSE_ASPECT_RATIOS],
summary: "The Frame shape of the generated video.",
};

const pixverseReferenceAspectRatio: SurfaceAttributeVocabulary = {
...pixverseAspectRatio, values: [...PIXVERSE_V6_ASPECT_RATIOS],
summary: "The Frame shape of the generated video; `auto` takes the shape of the V6 video references.",
};

const pixverseVideoPort: readonly SurfacePortVocabulary[] = [{
name: "video",
type: blobTypes.blob,
Expand Down Expand Up @@ -197,7 +203,7 @@ export const pixverseMarkupSurfaces = [
...pixverseCommonAttributes,
{ name: "duration", kind: "literal" as const, required: false,
summary: "How many seconds of video to render, from 1 to 15; video references carry their own length." },
pixverseAspectRatio,
pixverseReferenceAspectRatio,
],
children: [{
tag: "Reference",
Expand All @@ -220,7 +226,7 @@ export const pixverseMarkupSurfaces = [
pixverseModelNote,
"The prompt addresses the references in order as `@ref_1`, `@ref_2` and so on.",
"`Reference` carries exactly one of `image` or `video`, and is empty.",
"V6 accepts up to two video references totalling 15 seconds, which carry the length of the run in place of `duration`; `aspect-ratio=\"auto\"` takes their shape.",
"V6 accepts up to two video references totalling 15 seconds, which carry the length of the run in place of `duration`; `aspect-ratio=\"auto\"` takes their shape and requires at least one video reference.",
pixversePromptNote,
],
},
Expand Down
6 changes: 5 additions & 1 deletion packages/pixverse/src/surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export const decodePixverseVideoSurface: StructuredSurfaceHandler = ({ element,
exact(element, VIDEO_ATTRIBUTES, ["id", "model", "prompt", "duration", "quality"]);
empty(element);
const { endpoint } = selectModel(element);
const frames = ([["firstFrame", "first-frame"], ["lastFrame", "last-frame"]] as const)
assert(element.attributes["aspect-ratio"] !== "auto",
`${element.name}.aspect-ratio auto requires video references; use ReferenceVideo`);
const frames =([["firstFrame", "first-frame"], ["lastFrame", "last-frame"]] as const)
.filter(([, attribute]) => element.attributes[attribute] !== undefined)
.map(([port, attribute]) => ({
port, role: "image" as const, source: media(element, attribute, "image", resolveReference),
Expand Down Expand Up @@ -234,6 +236,8 @@ export const decodePixverseReferenceVideoSurface: StructuredSurfaceHandler = ({
capacity(element, endpoint, port, references.filter((item) => item.port === port).length);
}
const videos = references.some((item) => item.port === "referenceVideo");
assert(videos || element.attributes["aspect-ratio"] !== "auto",
`${element.name}.aspect-ratio auto requires a video Reference`);
if (videos) {
assert(element.attributes["duration"] === undefined,
`${element.name} takes no duration; its video references carry the length of the run`);
Expand Down
9 changes: 7 additions & 2 deletions packages/pixverse/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import type { PixverseModel } from "./index.js";

/**
* Reference videos carry the length of the run, so that mode states no duration.
* Every other mode states its own.
* Every other mode states its own. `aspectRatio` `auto` takes the shape of the
* reference videos, so it requires at least one.
*/
export function pixverseRequestValidator(model: PixverseModel): (request: GenerationRequest) => void {
return (request) => {
if (request.ports.referenceVideo !== undefined || request.ports.duration !== undefined) return;
const videos = (request.ports.referenceVideo?.length ?? 0) > 0;
if (request.ports.aspectRatio?.[0] === "auto" && !videos) {
throw new Error(`${model} aspectRatio auto requires a reference video`);
}
if (videos || request.ports.duration !== undefined) return;
throw new Error(`${model} requires duration`);
};
}
16 changes: 11 additions & 5 deletions packages/provider-hypihub/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const seedance = (name: string): GenerationWireMapping => ({

/**
* PixVerse V6 and C1 on `POST /v1/videos`. Both take the same body; V6 additionally accepts
* reference videos, which carry the length of the run in place of `seconds`. The model's own
* `quality` band is HypiHub's `resolution`.
* reference videos, which carry the length of the run in place of `seconds`, a sampling `seed`
* and the `multi_clip` switch. The model's own `quality` band is HypiHub's `resolution`.
*/
const pixverse = (name: string, model: string): GenerationWireMapping => ({
capability: { module: PIXVERSE, name }, result: "video", routes: [{ model }],
Expand All @@ -43,7 +43,11 @@ const pixverse = (name: string, model: string): GenerationWireMapping => ({
firstFrame: { as: "url", field: "first_frame" },
lastFrame: { as: "url", field: "last_frame" },
referenceImage: { as: "urlArray", field: "reference_image_urls" },
...(name === "pixverse-v6" ? { referenceVideo: { as: "urlArray" as const, field: "reference_videos" } } : {}),
...(name === "pixverse-v6" ? {
referenceVideo: { as: "urlArray" as const, field: "reference_videos" },
seed: { as: "value" as const, field: "seed" },
multiClip: { as: "value" as const, field: "multi_clip" },
} : {}),
duration: { as: "value", field: "seconds" },
quality: { as: "value", field: "resolution" },
aspectRatio: { as: "value", field: "aspect_ratio" },
Expand All @@ -63,8 +67,10 @@ export const hypiHubMappings: readonly GenerationWireMapping[] = [
seed: { as: "value", field: "seed" },
firstFrame: { as: "url", field: "first_frame" },
lastFrame: { as: "url", field: "last_frame" },
referenceImage: { as: "urlArray", field: "reference_image_urls" },
referenceAudio: { as: "urlArray", field: "reference_audios" },
// Each reference may carry a `start_time` offset, sent as `{ url, start_time }`.
referenceImage: { as: "itemObject", field: "reference_image_urls", urlKey: "url", fieldKeys: { startTime: "start_time" } },
referenceVideo: { as: "itemObject", field: "reference_videos", urlKey: "url", fieldKeys: { startTime: "start_time" } },
referenceAudio: { as: "itemObject", field: "reference_audios", urlKey: "url", fieldKeys: { startTime: "start_time" } },
},
},
{
Expand Down
18 changes: 12 additions & 6 deletions packages/provider-hypihub/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ function hypiHubGenerationRejection(
pendingPorts: readonly string[] = [],
): string | undefined {
if (mapping.capability.module.name === "@hypit/bach") {
if ((request.ports.referenceVideo?.length ?? 0) > 0 || pendingPorts.includes("referenceVideo")) {
return "HypiHub Bach reference videos await verification of upstream input billing";
}
try { selectWireModelForRequest(mapping, request, pendingPorts); }
catch (error) { return error instanceof Error ? error.message : String(error); }
return undefined;
Expand Down Expand Up @@ -146,17 +143,26 @@ function normalizeHypiHubRequest(
delete input.last_frame;
if (typeof firstFrame === "string" && firstFrame.length > 0) input.first_frame = firstFrame;
if (typeof lastFrame === "string" && lastFrame.length > 0) input.last_frame = lastFrame;
if (Array.isArray(imageRefs) && imageRefs.length > 0) input.reference_image_urls = imageRefs;
if (Array.isArray(imageRefs) && imageRefs.length > 0) input.reference_image_urls = referenceItems(imageRefs);
if (Array.isArray(genericImageRefs) && genericImageRefs.length > 0) {
const urls = genericImageRefs.map((item) => item !== null && typeof item === "object"
? (item as Record<string, unknown>).url : item).filter((item): item is string => typeof item === "string" && item.length > 0);
if (urls.length > 0) input.reference_image_urls = urls;
}
if (Array.isArray(videoRefs) && videoRefs.length > 0) input.reference_videos = videoRefs;
if (Array.isArray(audioRefs) && audioRefs.length > 0) input.reference_audios = audioRefs;
if (Array.isArray(videoRefs) && videoRefs.length > 0) input.reference_videos = referenceItems(videoRefs);
if (Array.isArray(audioRefs) && audioRefs.length > 0) input.reference_audios = referenceItems(audioRefs);
return { model: request.model, input: canonicalize(input) };
}

/** A reference with an offset is sent as `{ url, start_time }`; one with only a URL is sent as that URL. */
function referenceItems(items: readonly unknown[]): readonly unknown[] {
return items.map((item) => {
if (item === null || typeof item !== "object") return item;
const object = item as Record<string, unknown>;
return Object.keys(object).length === 1 && typeof object.url === "string" ? object.url : object;
});
}

function capabilityKey(capability: { module: { name: string; version: string }; name: string }): string {
return `${capability.module.name}@${capability.module.version}#${capability.name}`;
}
Expand Down
Loading