forked from mito-systems/sol-mem-gen
75 lines
1.6 KiB
TypeScript
75 lines
1.6 KiB
TypeScript
export interface FluxGenerationResult {
|
|
imageUrl?: string
|
|
error?: string
|
|
}
|
|
|
|
export interface FluxModelConfig {
|
|
modelId: string
|
|
name: string
|
|
description: string
|
|
cost: number
|
|
}
|
|
|
|
// Available Flux/fal-ai models
|
|
export const FLUX_MODELS: FluxModelConfig[] = [
|
|
{
|
|
modelId: "fal-ai/flux/schnell",
|
|
name: "Schnell",
|
|
description: "Fast meme generator",
|
|
cost: 0.05
|
|
},
|
|
{
|
|
modelId: "fal-ai/recraft-v3",
|
|
name: "Recraft",
|
|
description: "Advanced meme generator",
|
|
cost: 0.10
|
|
},
|
|
{
|
|
modelId: "fal-ai/stable-diffusion-v35-large",
|
|
name: "Marquee",
|
|
description: "Best meme generator",
|
|
cost: 0.15
|
|
}
|
|
]
|
|
|
|
export async function generateWithFlux(
|
|
prompt: string,
|
|
modelId: string,
|
|
transactionSignature: string,
|
|
): Promise<FluxGenerationResult> {
|
|
try {
|
|
const response = await fetch('/api/flux', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
prompt,
|
|
modelId,
|
|
transactionSignature,
|
|
}),
|
|
})
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to generate image')
|
|
}
|
|
|
|
const data = await response.json()
|
|
console.log('Raw Flux response:', data)
|
|
|
|
if (data.imageUrl) {
|
|
return { imageUrl: data.imageUrl }
|
|
} else {
|
|
console.error('Unexpected response structure:', data)
|
|
throw new Error('Invalid response format from Flux API')
|
|
}
|
|
} catch (error) {
|
|
console.error('Flux generation error:', error)
|
|
// Reload the page to get latest prices
|
|
window.location.reload();
|
|
return {
|
|
error: error instanceof Error ? error.message : 'Generation failed'
|
|
}
|
|
}
|
|
}
|