|
| 1 | +from typing import Literal |
| 2 | + |
| 3 | +from pydantic import BaseModel, Field |
| 4 | + |
| 5 | + |
| 6 | +class Text2ImageTaskCreationRequest(BaseModel): |
| 7 | + model: str = Field(...) |
| 8 | + prompt: str = Field(...) |
| 9 | + response_format: str | None = Field("url") |
| 10 | + size: str | None = Field(None) |
| 11 | + seed: int | None = Field(0, ge=0, le=2147483647) |
| 12 | + guidance_scale: float | None = Field(..., ge=1.0, le=10.0) |
| 13 | + watermark: bool | None = Field(True) |
| 14 | + |
| 15 | + |
| 16 | +class Image2ImageTaskCreationRequest(BaseModel): |
| 17 | + model: str = Field(...) |
| 18 | + prompt: str = Field(...) |
| 19 | + response_format: str | None = Field("url") |
| 20 | + image: str = Field(..., description="Base64 encoded string or image URL") |
| 21 | + size: str | None = Field("adaptive") |
| 22 | + seed: int | None = Field(..., ge=0, le=2147483647) |
| 23 | + guidance_scale: float | None = Field(..., ge=1.0, le=10.0) |
| 24 | + watermark: bool | None = Field(True) |
| 25 | + |
| 26 | + |
| 27 | +class Seedream4Options(BaseModel): |
| 28 | + max_images: int = Field(15) |
| 29 | + |
| 30 | + |
| 31 | +class Seedream4TaskCreationRequest(BaseModel): |
| 32 | + model: str = Field(...) |
| 33 | + prompt: str = Field(...) |
| 34 | + response_format: str = Field("url") |
| 35 | + image: list[str] | None = Field(None, description="Image URLs") |
| 36 | + size: str = Field(...) |
| 37 | + seed: int = Field(..., ge=0, le=2147483647) |
| 38 | + sequential_image_generation: str = Field("disabled") |
| 39 | + sequential_image_generation_options: Seedream4Options = Field(Seedream4Options(max_images=15)) |
| 40 | + watermark: bool = Field(True) |
| 41 | + |
| 42 | + |
| 43 | +class ImageTaskCreationResponse(BaseModel): |
| 44 | + model: str = Field(...) |
| 45 | + created: int = Field(..., description="Unix timestamp (in seconds) indicating time when the request was created.") |
| 46 | + data: list = Field([], description="Contains information about the generated image(s).") |
| 47 | + error: dict = Field({}, description="Contains `code` and `message` fields in case of error.") |
| 48 | + |
| 49 | + |
| 50 | +class TaskTextContent(BaseModel): |
| 51 | + type: str = Field("text") |
| 52 | + text: str = Field(...) |
| 53 | + |
| 54 | + |
| 55 | +class TaskImageContentUrl(BaseModel): |
| 56 | + url: str = Field(...) |
| 57 | + |
| 58 | + |
| 59 | +class TaskImageContent(BaseModel): |
| 60 | + type: str = Field("image_url") |
| 61 | + image_url: TaskImageContentUrl = Field(...) |
| 62 | + role: Literal["first_frame", "last_frame", "reference_image"] | None = Field(None) |
| 63 | + |
| 64 | + |
| 65 | +class Text2VideoTaskCreationRequest(BaseModel): |
| 66 | + model: str = Field(...) |
| 67 | + content: list[TaskTextContent] = Field(..., min_length=1) |
| 68 | + |
| 69 | + |
| 70 | +class Image2VideoTaskCreationRequest(BaseModel): |
| 71 | + model: str = Field(...) |
| 72 | + content: list[TaskTextContent | TaskImageContent] = Field(..., min_length=2) |
| 73 | + |
| 74 | + |
| 75 | +class TaskCreationResponse(BaseModel): |
| 76 | + id: str = Field(...) |
| 77 | + |
| 78 | + |
| 79 | +class TaskStatusError(BaseModel): |
| 80 | + code: str = Field(...) |
| 81 | + message: str = Field(...) |
| 82 | + |
| 83 | + |
| 84 | +class TaskStatusResult(BaseModel): |
| 85 | + video_url: str = Field(...) |
| 86 | + |
| 87 | + |
| 88 | +class TaskStatusResponse(BaseModel): |
| 89 | + id: str = Field(...) |
| 90 | + model: str = Field(...) |
| 91 | + status: Literal["queued", "running", "cancelled", "succeeded", "failed"] = Field(...) |
| 92 | + error: TaskStatusError | None = Field(None) |
| 93 | + content: TaskStatusResult | None = Field(None) |
| 94 | + |
| 95 | + |
| 96 | +RECOMMENDED_PRESETS = [ |
| 97 | + ("1024x1024 (1:1)", 1024, 1024), |
| 98 | + ("864x1152 (3:4)", 864, 1152), |
| 99 | + ("1152x864 (4:3)", 1152, 864), |
| 100 | + ("1280x720 (16:9)", 1280, 720), |
| 101 | + ("720x1280 (9:16)", 720, 1280), |
| 102 | + ("832x1248 (2:3)", 832, 1248), |
| 103 | + ("1248x832 (3:2)", 1248, 832), |
| 104 | + ("1512x648 (21:9)", 1512, 648), |
| 105 | + ("2048x2048 (1:1)", 2048, 2048), |
| 106 | + ("Custom", None, None), |
| 107 | +] |
| 108 | + |
| 109 | +RECOMMENDED_PRESETS_SEEDREAM_4 = [ |
| 110 | + ("2048x2048 (1:1)", 2048, 2048), |
| 111 | + ("2304x1728 (4:3)", 2304, 1728), |
| 112 | + ("1728x2304 (3:4)", 1728, 2304), |
| 113 | + ("2560x1440 (16:9)", 2560, 1440), |
| 114 | + ("1440x2560 (9:16)", 1440, 2560), |
| 115 | + ("2496x1664 (3:2)", 2496, 1664), |
| 116 | + ("1664x2496 (2:3)", 1664, 2496), |
| 117 | + ("3024x1296 (21:9)", 3024, 1296), |
| 118 | + ("4096x4096 (1:1)", 4096, 4096), |
| 119 | + ("Custom", None, None), |
| 120 | +] |
| 121 | + |
| 122 | +# The time in this dictionary are given for 10 seconds duration. |
| 123 | +VIDEO_TASKS_EXECUTION_TIME = { |
| 124 | + "seedance-1-0-lite-t2v-250428": { |
| 125 | + "480p": 40, |
| 126 | + "720p": 60, |
| 127 | + "1080p": 90, |
| 128 | + }, |
| 129 | + "seedance-1-0-lite-i2v-250428": { |
| 130 | + "480p": 40, |
| 131 | + "720p": 60, |
| 132 | + "1080p": 90, |
| 133 | + }, |
| 134 | + "seedance-1-0-pro-250528": { |
| 135 | + "480p": 70, |
| 136 | + "720p": 85, |
| 137 | + "1080p": 115, |
| 138 | + }, |
| 139 | + "seedance-1-0-pro-fast-251015": { |
| 140 | + "480p": 50, |
| 141 | + "720p": 65, |
| 142 | + "1080p": 100, |
| 143 | + }, |
| 144 | +} |
0 commit comments