|
| 1 | +# ai-proxy-core v0.4.0 |
| 2 | +## Abstract GPT-4o Image Generation Provider |
| 3 | + |
| 4 | +### Overview |
| 5 | +This release adds abstract wrapper support for OpenAI's GPT-4o native image generation capabilities (March 2025), maintaining consistency with ai-proxy-core's design philosophy of providing abstract, extensible AI provider interfaces. |
| 6 | + |
| 7 | +### Installation |
| 8 | +```bash |
| 9 | +pip install ai-proxy-core==0.4.0 |
| 10 | +``` |
| 11 | + |
| 12 | +### Quick Start |
| 13 | + |
| 14 | +```python |
| 15 | +from ai_proxy_core import GPT4oImageProvider, ImageSize, ImageQuality |
| 16 | + |
| 17 | +# Initialize provider |
| 18 | +provider = GPT4oImageProvider(api_key="your-api-key") |
| 19 | + |
| 20 | +# Generate image |
| 21 | +response = provider.generate( |
| 22 | + prompt="A modern minimalist app icon", |
| 23 | + size=ImageSize.SQUARE, |
| 24 | + quality=ImageQuality.HD |
| 25 | +) |
| 26 | + |
| 27 | +# Access image data |
| 28 | +image_bytes = response.image_data |
| 29 | +c2pa_metadata = response.c2pa_metadata |
| 30 | +``` |
| 31 | + |
| 32 | +### Abstract Models |
| 33 | + |
| 34 | +The library provides abstract models that work across providers: |
| 35 | + |
| 36 | +```python |
| 37 | +from ai_proxy_core import ImageGenerationRequest, ImageGenerationResponse |
| 38 | + |
| 39 | +# Create abstract request |
| 40 | +request = ImageGenerationRequest( |
| 41 | + prompt="Generate an image", |
| 42 | + provider="openai", |
| 43 | + model="gpt-4o", |
| 44 | + size="1024x1024", |
| 45 | + context={"previous_messages": [...]} |
| 46 | +) |
| 47 | + |
| 48 | +# Convert to provider format |
| 49 | +provider_request = request.to_provider_format("openai") |
| 50 | +``` |
| 51 | + |
| 52 | +### Provider Implementations |
| 53 | + |
| 54 | +#### OpenAI GPT-4o |
| 55 | +```python |
| 56 | +from ai_proxy_core import GPT4oImageProvider |
| 57 | + |
| 58 | +provider = GPT4oImageProvider(api_key="sk-...") |
| 59 | +``` |
| 60 | + |
| 61 | +#### Azure OpenAI |
| 62 | +```python |
| 63 | +from ai_proxy_core import AzureGPT4oImageProvider |
| 64 | + |
| 65 | +provider = AzureGPT4oImageProvider( |
| 66 | + api_key="...", |
| 67 | + resource_name="myresource", |
| 68 | + deployment_name="gpt-image-1", |
| 69 | + api_version="2025-04-15" |
| 70 | +) |
| 71 | +``` |
| 72 | + |
| 73 | +### Image Editing |
| 74 | + |
| 75 | +```python |
| 76 | +# Edit existing image |
| 77 | +edited = provider.edit( |
| 78 | + image=original_bytes, |
| 79 | + prompt="Change the background to turquoise", |
| 80 | + mask=mask_bytes # Optional |
| 81 | +) |
| 82 | +``` |
| 83 | + |
| 84 | +### Context-Aware Generation |
| 85 | + |
| 86 | +```python |
| 87 | +# Generate with context |
| 88 | +response = provider.generate( |
| 89 | + prompt="Create a similar style icon", |
| 90 | + context={ |
| 91 | + "images": [reference_image_bytes], |
| 92 | + "messages": previous_chat_history |
| 93 | + } |
| 94 | +) |
| 95 | +``` |
| 96 | + |
| 97 | +### C2PA Metadata |
| 98 | + |
| 99 | +All generated images include C2PA (Content Authenticity) metadata: |
| 100 | + |
| 101 | +```python |
| 102 | +metadata = provider.extract_c2pa_metadata(response) |
| 103 | +print(metadata["generator"]) # "OpenAI GPT-4o" |
| 104 | +print(metadata["is_ai_generated"]) # True |
| 105 | +``` |
| 106 | + |
| 107 | +### Extending the Abstract Provider |
| 108 | + |
| 109 | +Create your own implementation: |
| 110 | + |
| 111 | +```python |
| 112 | +from ai_proxy_core import GPT4oImageProvider |
| 113 | + |
| 114 | +class CustomImageProvider(GPT4oImageProvider): |
| 115 | + def generate(self, prompt, **kwargs): |
| 116 | + # Add custom preprocessing |
| 117 | + prompt = self.preprocess_prompt(prompt) |
| 118 | + |
| 119 | + # Call parent implementation |
| 120 | + response = super().generate(prompt, **kwargs) |
| 121 | + |
| 122 | + # Add custom postprocessing |
| 123 | + return self.postprocess_response(response) |
| 124 | +``` |
| 125 | + |
| 126 | +### What's New in v0.4.0 |
| 127 | + |
| 128 | +- **GPT-4o Native Generation**: Not DALL-E, uses autoregressive method |
| 129 | +- **Image Editing**: Modify existing images with natural language |
| 130 | +- **Context Awareness**: Use chat history and reference images |
| 131 | +- **C2PA Metadata**: Built-in content authenticity |
| 132 | +- **Azure Support**: Full Azure OpenAI integration |
| 133 | +- **Abstract Models**: Provider-agnostic request/response models |
| 134 | + |
| 135 | +### Migration from v0.3.x |
| 136 | + |
| 137 | +```python |
| 138 | +# Old (v0.3.x) |
| 139 | +from ai_proxy_core import DallEProvider |
| 140 | +provider = DallEProvider(api_key="key") |
| 141 | + |
| 142 | +# New (v0.4.0) |
| 143 | +from ai_proxy_core import GPT4oImageProvider |
| 144 | +provider = GPT4oImageProvider(api_key="key") |
| 145 | +``` |
| 146 | + |
| 147 | +### License |
| 148 | +MIT |
| 149 | + |
| 150 | +### Contributing |
| 151 | +See [CONTRIBUTING.md](CONTRIBUTING.md) |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +**Branch**: `feature/app-store-internationalization-v0.4.0` |
| 156 | +**Release**: v0.4.0 |
| 157 | +**Issue**: #30 |
0 commit comments