| 1 | export type ImageModelList = |
| 2 | | "openai/gpt-image-2" |
| 3 | | "fal-ai/nano-banana-2" |
| 4 | | "fal-ai/nano-banana-pro" |
| 5 | | "fal-ai/flux-2/turbo" |
| 6 | | "fal-ai/flux-2/flash" |
| 7 | | "fal-ai/flux-2-pro" |
| 8 | | "fal-ai/flux-2" |
| 9 | | "fal-ai/flux/dev"; |
| 10 | |
| 11 | export const DEFAULT_IMAGE_MODEL: ImageModelList = "fal-ai/flux-2/flash"; |
| 12 | |
| 13 | export type ImageModelOption = { |
| 14 | value: ImageModelList; |
| 15 | label: string; |
| 16 | adminOnly?: boolean; |
| 17 | }; |
| 18 | |
| 19 | const IMAGE_MODELS: ImageModelOption[] = [ |
| 20 | { |
| 21 | value: "fal-ai/flux-2/flash", |
| 22 | label: "Flux 2 Flash", |
| 23 | }, |
| 24 | { |
| 25 | value: "fal-ai/flux-2/turbo", |
| 26 | label: "Flux 2 Turbo", |
| 27 | adminOnly: true, |
| 28 | }, |
| 29 | { |
| 30 | value: "fal-ai/flux/dev", |
| 31 | label: "Flux Dev", |
| 32 | adminOnly: true, |
| 33 | }, |
| 34 | { |
| 35 | value: "fal-ai/flux-2", |
| 36 | label: "Flux 2", |
| 37 | adminOnly: true, |
| 38 | }, |
| 39 | { |
| 40 | value: "fal-ai/flux-2-pro", |
| 41 | label: "Flux 2 Pro", |
| 42 | adminOnly: true, |
| 43 | }, |
| 44 | { |
| 45 | value: "fal-ai/nano-banana-pro", |
| 46 | label: "Nano Banana Pro", |
| 47 | adminOnly: true, |
| 48 | }, |
| 49 | { |
| 50 | value: "fal-ai/nano-banana-2", |
| 51 | label: "Nano Banana 2", |
| 52 | adminOnly: true, |
| 53 | }, |
| 54 | { |
| 55 | value: "openai/gpt-image-2", |
| 56 | label: "GPT Image 2", |
| 57 | adminOnly: true, |
| 58 | }, |
| 59 | ]; |
| 60 | |
| 61 | export const getAvailableImageModels = (isAdmin: boolean): ImageModelOption[] => |
| 62 | IMAGE_MODELS.filter((model) => isAdmin || !model.adminOnly); |
| 63 | |
| 64 | type GptImageSize = "1024x1024" | "1536x1024" | "1024x1536" | "auto"; |
| 65 | |
| 66 | type FluxDevImageSize = |
| 67 | | "landscape_16_9" |
| 68 | | "landscape_4_3" |
| 69 | | "portrait_4_3" |
| 70 | | "portrait_9_16" |
| 71 | | "square"; |
| 72 | |
| 73 | export type FalImageGenerationInput = |
| 74 | | { |
| 75 | prompt: string; |
| 76 | aspect_ratio: "16:9" | "1:1" | "4:3" | "3:4" | "9:16"; |
| 77 | num_images: 1; |
| 78 | output_format?: "png"; |
| 79 | } |
| 80 | | { |
| 81 | prompt: string; |
| 82 | image_size: FluxDevImageSize; |
| 83 | num_images: 1; |
| 84 | } |
| 85 | | { |
| 86 | prompt: string; |
| 87 | image_size: GptImageSize; |
| 88 | num_images: 1; |
| 89 | output_format: "png"; |
| 90 | }; |
| 91 | |
| 92 | export type ImageAspectRatio = "16:9" | "1:1" | "4:3" | "3:4" | "9:16"; |
| 93 | |
| 94 | export function getFalImageGenerationInput({ |
| 95 | model, |
| 96 | prompt, |
| 97 | aspectRatio, |
| 98 | }: { |
| 99 | model: ImageModelList; |
| 100 | prompt: string; |
| 101 | aspectRatio: ImageAspectRatio; |
| 102 | }): FalImageGenerationInput { |
| 103 | if (model.includes("flux")) { |
| 104 | return { |
| 105 | prompt, |
| 106 | image_size: getFluxDevImageSize(aspectRatio), |
| 107 | num_images: 1, |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | if (model === "openai/gpt-image-2") { |
| 112 | return { |
| 113 | prompt, |
| 114 | image_size: getGptImageSize(aspectRatio), |
| 115 | num_images: 1, |
| 116 | output_format: "png", |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | return { |
| 121 | prompt, |
| 122 | aspect_ratio: aspectRatio, |
| 123 | num_images: 1, |
| 124 | output_format: "png", |
| 125 | }; |
| 126 | } |
| 127 | |
| 128 | function getFluxDevImageSize(aspectRatio: ImageAspectRatio): FluxDevImageSize { |
| 129 | if (aspectRatio === "1:1") return "square"; |
| 130 | if (aspectRatio === "9:16") return "portrait_9_16"; |
| 131 | if (aspectRatio === "3:4") return "portrait_4_3"; |
| 132 | if (aspectRatio === "4:3") return "landscape_4_3"; |
| 133 | return "landscape_16_9"; |
| 134 | } |
| 135 | |
| 136 | function getGptImageSize(aspectRatio: ImageAspectRatio): GptImageSize { |
| 137 | if (aspectRatio === "1:1") return "1024x1024"; |
| 138 | if (aspectRatio === "9:16" || aspectRatio === "3:4") return "1024x1536"; |
| 139 | return "1536x1024"; |
| 140 | } |
| 141 |