File size: 2,571 Bytes
3b9f744
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from pydantic import BaseModel, Field
from typing import List, Optional, Literal
from enum import Enum


class ImageSize(str, Enum):
    """Supported image sizes (OpenAI compatible)"""
    SMALL = "256x256"
    MEDIUM = "512x512" 
    LARGE = "1024x1024"
    WIDE = "1792x1024"
    TALL = "1024x1792"


class ImageQuality(str, Enum):
    """Image quality options"""
    STANDARD = "standard"
    HD = "hd"


class ImageStyle(str, Enum):
    """Image style options"""
    VIVID = "vivid"
    NATURAL = "natural"


class ResponseFormat(str, Enum):
    """Response format options"""
    URL = "url"
    B64_JSON = "b64_json"


class ImageGenerationRequest(BaseModel):
    """OpenAI compatible image generation request"""
    prompt: str = Field(..., description="A text description of the desired image(s)")
    model: str = Field(default="dall-e-3", description="The model to use for image generation")
    n: int = Field(default=1, ge=1, le=10, description="Number of images to generate")
    quality: ImageQuality = Field(default=ImageQuality.STANDARD, description="Quality of the image")
    response_format: ResponseFormat = Field(default=ResponseFormat.URL, description="Response format")
    size: ImageSize = Field(default=ImageSize.LARGE, description="Size of the generated images")
    style: ImageStyle = Field(default=ImageStyle.VIVID, description="Style of the generated images")
    user: Optional[str] = Field(default=None, description="A unique identifier representing your end-user")


class ImageData(BaseModel):
    """Individual image data in response"""
    url: Optional[str] = Field(default=None, description="URL of the generated image")
    b64_json: Optional[str] = Field(default=None, description="Base64 encoded image data")
    revised_prompt: Optional[str] = Field(default=None, description="The revised prompt used for generation")


class ImageGenerationResponse(BaseModel):
    """OpenAI compatible image generation response"""
    created: int = Field(..., description="Unix timestamp of when the image was created")
    data: List[ImageData] = Field(..., description="List of generated images")


class ErrorResponse(BaseModel):
    """Error response format"""
    error: dict = Field(..., description="Error details")


class ModelInfo(BaseModel):
    """Model information"""
    id: str
    object: str = "model"
    created: int
    owned_by: str


class ModelsResponse(BaseModel):
    """Models list response"""
    object: str = "list"
    data: List[ModelInfo]