feat: adapt new fal response (#7042)

This commit is contained in:
darkskygit
2024-05-23 10:43:12 +00:00
parent f511b02bf9
commit 535254fdf6

View File

@@ -13,9 +13,16 @@ export type FalConfig = {
apiKey: string;
};
export type FalImage = {
url: string;
seed: number;
file_name: string;
};
export type FalResponse = {
detail: Array<{ msg: string }> | string;
images: Array<{ url: string }>;
images?: Array<FalImage>;
image?: FalImage;
};
type FalPrompt = {
@@ -122,12 +129,17 @@ export class FalProvider
signal: options.signal,
}).then(res => res.json())) as FalResponse;
if (!data.images?.length) {
if (!data.images?.length && !data.image?.url) {
const error = this.extractError(data);
throw new Error(
error ? `Failed to generate image: ${error}` : 'No images generated'
);
}
if (data.image?.url) {
return [data.image.url];
}
return data.images?.map(image => image.url) || [];
}