Models

DALL-E 3

Configuration

const response = await openai.images.generate({
  model: 'dall-e-3',
  prompt: combinedPrompt,
  n: 1,
  size: '1024x1024',
  quality: 'standard',
  response_format: 'url'
});

Features

  • High-quality image generation

  • 1024x1024 resolution

  • Standard quality setting

  • URL response format

  • Single image per request

Style Enhancement

  • Template-based prompt enhancement

  • Style consistency

  • Quality optimization

  • Content guidelines

Error Handling

function getDalleErrorMessage(error: any): string {
  if (error?.type === 'invalid_request_error') {
    if (error.code === 'content_policy_violation') {
      return '❌ Your prompt was rejected due to content policy violation...';
    }
    if (error.message?.toLowerCase().includes('rate limit')) {
      return '⏳ Rate limit exceeded...';
    }
    if (error.message?.toLowerCase().includes('capacity')) {
      return '🔄 The service is currently at capacity...';
    }
  }
  // ... other error types
}

GPT-4o-mini (Caption Generation)

Configuration

const completion = await openai.chat.completions.create({
  messages: [{ 
    role: "system", 
    content: await getCombinedPrompt('img', prompt, agent)
  }],
  model: "gpt-4o-mini",
  temperature: 0.7,
  max_tokens: 150
});

Features

  • Intelligent caption generation

  • Context-aware responses

  • HTML formatting support

  • Temperature control

  • Token limit optimization

Prompt Enhancement

  • System prompt integration

  • Agent personality adaptation

  • Style consistency

  • Content guidelines

Error Handling

  • Fallback to original prompt

  • Error logging

  • Response validation

  • Format verification

Integration

Parallel Processing

const [imageUrl, caption] = await Promise.all([
  generateImage(imagePrompt),
  generateImageCaption(imagePrompt, agent)
]);

Response Handling

// Format caption with HTML
const caption = completion.choices[0].message.content || prompt;
return caption
  .replace(/\*([^*]+)\*/g, '<i>$1</i>')
  .trim();

Buffer Management

// Download and buffer image
const imageResponse = await fetch(imageUrl);
const imageBuffer = Buffer.from(await imageResponse.arrayBuffer());

Performance Considerations

Rate Limiting

  • DALL-E API limits

  • GPT-4o-mini throughput

  • Function cooldowns

  • User quotas

Optimization

  • Parallel requests

  • Response caching

  • Buffer management

  • Error recovery

Monitoring

  • Request tracking

  • Error logging

  • Performance metrics

  • Usage analytics

Last updated