gateway
gateway copied to clipboard
feat: adds image generation capability to Workers AI API
Author Description
Implements support for an image generation feature
Summary By MatterAI
๐ What Changed
This PR adds image generation capability to the Workers AI API by implementing a new endpoint. The implementation includes configuration for handling image generation requests with parameters like prompt, negative_prompt, steps, size, and seed. It also includes response transformation to properly format the image data returned from the Workers AI service.
๐ Impact of the Change
This change extends the API's capabilities to include image generation, allowing clients to generate images using the Workers AI models. The implementation follows the same pattern as other Workers AI features, reusing common error handling and response transformation patterns.
๐ Total Files Changed
7 files changed with 133 additions and 100 deletions. Key changes include:
- Added new
imageGenerate.tsfile with configuration and response transformation - Added common
utils.tsfile to centralize error handling - Updated API configuration to support the new endpoint
- Refactored existing files to use the centralized error handling
๐งช Test Added
N/A - No tests were included in this PR.
๐ Security Vulnerabilities
No security vulnerabilities detected.
Type of Change
- [x] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
- [x] Refactoring (no functional changes)
How Has This Been Tested?
- [ ] Unit Tests
- [ ] Integration Tests
- [x] Manual Testing
Screenshots (if applicable)
N/A
Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
Related Issues
N/A
Quality Recommendations
-
Add input validation for the image size parameter to ensure it's in the correct format before parsing
-
Consider adding error handling for the case when size parameter is malformed
-
Add unit tests for the new image generation functionality
-
Add documentation for the supported image models and their specific requirements
Sequence Diagram
sequenceDiagram
participant Client
participant API
participant WorkersAiAPI
participant ImageGenerate
Client->>API: POST /imageGenerate
Note over Client,API: prompt, negative_prompt, steps, size, seed
API->>WorkersAiAPI: Route to Workers AI API
Note over API,WorkersAiAPI: Configure endpoint using model
WorkersAiAPI->>ImageGenerate: Process request
Note over WorkersAiAPI,ImageGenerate: Transform parameters
ImageGenerate->>WorkersAiAPI: Generate image
Note over ImageGenerate,WorkersAiAPI: Process with model parameters
WorkersAiAPI-->>Client: Return response
Note over WorkersAiAPI,Client: b64_json image data