Use pydantic v2.

This commit is contained in:
Robin Huang 2025-04-22 01:58:55 -07:00
parent 08b797fe80
commit 824c87a106
4 changed files with 105 additions and 20 deletions

View File

@ -25,7 +25,7 @@ jobs:
- name: Generate API models
run: |
datamodel-codegen --use-subclass-enum --url https://stagingapi.comfy.org/openapi --output comfy_api_nodes/apis
datamodel-codegen --use-subclass-enum --url https://stagingapi.comfy.org/openapi --output comfy_api_nodes/apis --output-model-type pydantic_v2.BaseModel
- name: Check for changes
id: git-check

View File

@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: https://stagingapi.comfy.org/openapi
# timestamp: 2025-04-22T08:06:44+00:00
# timestamp: 2025-04-22T08:58:11+00:00
from __future__ import annotations

View File

@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: https://stagingapi.comfy.org/openapi
# timestamp: 2025-04-22T08:06:44+00:00
# timestamp: 2025-04-22T08:58:11+00:00
from __future__ import annotations
@ -15,20 +15,20 @@ class V2OpenAPII2VResp(BaseModel):
class V2OpenAPIT2VReq(BaseModel):
aspect_ratio: str = Field(
..., description='Aspect ratio (16:9, 4:3, 1:1, 3:4, 9:16)', example='16:9'
..., description='Aspect ratio (16:9, 4:3, 1:1, 3:4, 9:16)', examples=['16:9']
)
duration: int = Field(
...,
description='Video duration (5, 8 seconds, --model=v3.5 only allows 5,8; --quality=1080p does not support 8s)',
example=5,
examples=[5],
)
model: str = Field(
..., description='Model version (only supports v3.5)', example='v3.5'
..., description='Model version (only supports v3.5)', examples=['v3.5']
)
motion_mode: Optional[str] = Field(
'normal',
description='Motion mode (normal, fast, --fast only available when duration=5; --quality=1080p does not support fast)',
example='normal',
examples=['normal'],
)
negative_prompt: Optional[constr(max_length=2048)] = Field(
None, description='Negative prompt\n'
@ -37,21 +37,21 @@ class V2OpenAPIT2VReq(BaseModel):
quality: str = Field(
...,
description='Video quality ("360p"(Turbo model), "540p", "720p", "1080p")',
example='540p',
examples=['540p'],
)
seed: Optional[int] = Field(None, description='Random seed, range: 0 - 2147483647')
style: Optional[str] = Field(
None,
description='Style (effective when model=v3.5, "anime", "3d_animation", "clay", "comic", "cyberpunk") Do not include style parameter unless needed',
example='anime',
examples=['anime'],
)
template_id: Optional[int] = Field(
None,
description='Template ID (template_id must be activated before use)',
example=302325299692608,
examples=[302325299692608],
)
water_mark: Optional[bool] = Field(
False,
description='Watermark (true: add watermark, false: no watermark)',
example=False,
examples=[False],
)

View File

@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: https://stagingapi.comfy.org/openapi
# timestamp: 2025-04-22T08:06:44+00:00
# timestamp: 2025-04-22T08:58:11+00:00
from __future__ import annotations
@ -9,7 +9,7 @@ from enum import Enum
from typing import Any, Dict, List, Literal, Optional, Union
from uuid import UUID
from pydantic import AnyUrl, BaseModel, Field, confloat, conint, constr
from pydantic import AnyUrl, BaseModel, Field, RootModel, confloat, conint, constr
class BFLFluxProGenerateRequest(BaseModel):
@ -829,8 +829,8 @@ class LumaImageReference(BaseModel):
url: AnyUrl = Field(..., description='The URL of the image')
class LumaKeyframe(BaseModel):
__root__: Union[LumaGenerationReference, LumaImageReference] = Field(
class LumaKeyframe(RootModel[Union[LumaGenerationReference, LumaImageReference]]):
root: Union[LumaGenerationReference, LumaImageReference] = Field(
...,
description='A keyframe can be either a Generation reference, an Image, or a Video',
discriminator='type',
@ -884,8 +884,10 @@ class LumaVideoModelOutputDuration1(str, Enum):
field_9s = '9s'
class LumaVideoModelOutputDuration(BaseModel):
__root__: Union[LumaVideoModelOutputDuration1, str]
class LumaVideoModelOutputDuration(
RootModel[Union[LumaVideoModelOutputDuration1, str]]
):
root: Union[LumaVideoModelOutputDuration1, str]
class LumaVideoModelOutputResolution1(str, Enum):
@ -895,8 +897,10 @@ class LumaVideoModelOutputResolution1(str, Enum):
field_4k = '4k'
class LumaVideoModelOutputResolution(BaseModel):
__root__: Union[LumaVideoModelOutputResolution1, str]
class LumaVideoModelOutputResolution(
RootModel[Union[LumaVideoModelOutputResolution1, str]]
):
root: Union[LumaVideoModelOutputResolution1, str]
class MachineStats(BaseModel):
@ -1054,6 +1058,87 @@ class NodeVersionUpdateRequest(BaseModel):
)
class Background(str, Enum):
transparent = 'transparent'
opaque = 'opaque'
class Moderation(str, Enum):
low = 'low'
auto = 'auto'
class OutputFormat(str, Enum):
png = 'png'
webp = 'webp'
jpeg = 'jpeg'
class Quality(str, Enum):
low = 'low'
medium = 'medium'
high = 'high'
class ResponseFormat(str, Enum):
url = 'url'
b64_json = 'b64_json'
class Style(str, Enum):
vivid = 'vivid'
natural = 'natural'
class OpenAIImageGenerationRequest(BaseModel):
background: Optional[Background] = Field(
None, description='Background transparency', examples=['opaque']
)
model: Optional[str] = Field(
None,
description='The model to use for image generation',
examples=['gpt-image-1'],
)
moderation: Optional[Moderation] = Field(
None, description='Content moderation setting', examples=['auto']
)
n: Optional[int] = Field(
None,
description='The number of images to generate (110). Only 1 supported for dall-e-3.',
examples=[1],
)
output_compression: Optional[int] = Field(
None, description='Compression level for JPEG or WebP (0100)', examples=[100]
)
output_format: Optional[OutputFormat] = Field(
None, description='Format of the output image', examples=['png']
)
prompt: str = Field(
...,
description='A text description of the desired image',
examples=['Draw a rocket in front of a blackhole in deep space'],
)
quality: Optional[Quality] = Field(
None, description='The quality of the generated image', examples=['high']
)
response_format: Optional[ResponseFormat] = Field(
None, description='Response format of image data', examples=['b64_json']
)
size: Optional[str] = Field(
None,
description='Size of the image (e.g., 1024x1024, 1536x1024, auto)',
examples=['1024x1536'],
)
style: Optional[Style] = Field(
None, description='Style of the image (only for dall-e-3)', examples=['vivid']
)
user: Optional[str] = Field(
None,
description='A unique identifier for end-user monitoring',
examples=['user-1234'],
)
class PersonalAccessToken(BaseModel):
createdAt: Optional[datetime] = Field(
None, description='[Output Only]The date and time the token was created.'
@ -1299,7 +1384,7 @@ class PersonGeneration(str, Enum):
class Parameters(BaseModel):
aspectRatio: Optional[str] = Field(None, example='16:9')
aspectRatio: Optional[str] = Field(None, examples=['16:9'])
durationSeconds: Optional[int] = None
enhancePrompt: Optional[bool] = None
negativePrompt: Optional[str] = None