text stringlengths 0 59.1k |
|---|
description: |
"Generate a square Instagram ad image using Google Gemini with optional landing page reference", |
parameters: z.object({ |
productName: z.string().describe("The product or brand name"), |
tagline: z.string().describe("The main tagline or value proposition"), |
adConcept: z.string().describe("Creative concept for the ad"), |
style: z.string().optional().default("modern and professional").describe("Visual style"), |
targetAudience: z.string().optional().describe("Target audience description"), |
}), |
execute: async ({ productName, tagline, adConcept, style, targetAudience }, context) => { |
const outputDir = path.join(process.cwd(), "output", "ads", "instagram"); |
await fs.mkdir(outputDir, { recursive: true }); |
// First, generate creative brief |
const { text: adDescription } = await creativeBriefAgent.generateText( |
`Create a detailed visual description for a square Instagram advertisement: |
Product: ${productName} |
Tagline: "${tagline}" |
Concept: ${adConcept} |
Style: ${style} |
${targetAudience ? `Target audience: ${targetAudience}` : ""} |
Requirements: |
- Include the product name and tagline prominently |
- Eye-catching and scroll-stopping design |
- Modern design principles with clear visual hierarchy |
- Optimized for Instagram feed`, |
{ temperature: 0.5 } |
); |
// Prepare image generation with optional screenshot reference |
const userContent = [{ type: "text", text: imagePrompt }]; |
const screenshotPath = context?.context.get("screenshotPath"); |
if (screenshotPath) { |
const screenshotBuffer = await fs.readFile(screenshotPath); |
const processedScreenshot = await sharp(screenshotBuffer) |
.resize(1024, 1024, { fit: "cover" }) |
.png() |
.toBuffer(); |
userContent.push({ |
type: "image", |
image: processedScreenshot, |
mediaType: "image/png", |
}); |
} |
// Generate the Instagram ad |
const imageResult = await imageGenerationAgent.generateText( |
[{ role: "user", content: userContent }], |
{ |
providerOptions: { |
google: { responseModalities: ["IMAGE"] }, |
}, |
temperature: 0.3, |
} |
); |
// Save the generated image |
const buffer = Buffer.from(imageResult.files[0].base64, "base64"); |
const filename = `instagram_${productName}_${Date.now()}.png`; |
const filepath = path.join(outputDir, filename); |
await fs.writeFile(filepath, buffer); |
// Create public URL for immediate preview |
const baseUrl = process.env.PUBLIC_BASE_URL ?? `http://localhost:${process.env.PORT ?? "3141"}`; |
const publicUrl = new URL(path.relative(process.cwd(), filepath), baseUrl).toString(); |
return { success: true, publicUrl }; |
}, |
}); |
``` |
</details> |
 |
Implementation: |
- Two-stage generation: creative brief, then image |
- Incorporates landing page screenshots as references |
- Processes to Instagram square format (1024x1024) |
- Local asset storage with public URL generation |
- Context maintenance for traceability |
**Screenshot integration:** When available, screenshots from landing page analysis are included as references for visual consistency. |
### Application Structure |
 |
Application configuration and initialization: |
<details> |
<summary>Show index.ts</summary> |
```typescript |
import "dotenv/config"; |
import { VoltAgent, Memory, VoltAgentObservability } from "@voltagent/core"; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.