mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 05:29:08 +08:00
feat: adapt new fal response (#7042)
This commit is contained in:
@@ -13,9 +13,16 @@ export type FalConfig = {
|
|||||||
apiKey: string;
|
apiKey: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type FalImage = {
|
||||||
|
url: string;
|
||||||
|
seed: number;
|
||||||
|
file_name: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type FalResponse = {
|
export type FalResponse = {
|
||||||
detail: Array<{ msg: string }> | string;
|
detail: Array<{ msg: string }> | string;
|
||||||
images: Array<{ url: string }>;
|
images?: Array<FalImage>;
|
||||||
|
image?: FalImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FalPrompt = {
|
type FalPrompt = {
|
||||||
@@ -122,12 +129,17 @@ export class FalProvider
|
|||||||
signal: options.signal,
|
signal: options.signal,
|
||||||
}).then(res => res.json())) as FalResponse;
|
}).then(res => res.json())) as FalResponse;
|
||||||
|
|
||||||
if (!data.images?.length) {
|
if (!data.images?.length && !data.image?.url) {
|
||||||
const error = this.extractError(data);
|
const error = this.extractError(data);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
error ? `Failed to generate image: ${error}` : 'No images generated'
|
error ? `Failed to generate image: ${error}` : 'No images generated'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.image?.url) {
|
||||||
|
return [data.image.url];
|
||||||
|
}
|
||||||
|
|
||||||
return data.images?.map(image => image.url) || [];
|
return data.images?.map(image => image.url) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user