From 824c87a106b0b0d98bce0fb3e4f5c6868db9d86e Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Tue, 22 Apr 2025 01:58:55 -0700 Subject: [PATCH] Use pydantic v2. --- .github/workflows/update-api-stubs.yml | 2 +- comfy_api_nodes/apis/PixverseController.py | 2 +- comfy_api_nodes/apis/PixverseDto.py | 18 ++-- comfy_api_nodes/apis/__init__.py | 103 +++++++++++++++++++-- 4 files changed, 105 insertions(+), 20 deletions(-) diff --git a/.github/workflows/update-api-stubs.yml b/.github/workflows/update-api-stubs.yml index 4eda03956..b27f2c580 100644 --- a/.github/workflows/update-api-stubs.yml +++ b/.github/workflows/update-api-stubs.yml @@ -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 diff --git a/comfy_api_nodes/apis/PixverseController.py b/comfy_api_nodes/apis/PixverseController.py index 2899706f6..583fd26da 100644 --- a/comfy_api_nodes/apis/PixverseController.py +++ b/comfy_api_nodes/apis/PixverseController.py @@ -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 diff --git a/comfy_api_nodes/apis/PixverseDto.py b/comfy_api_nodes/apis/PixverseDto.py index 50d813c05..32da4ab05 100644 --- a/comfy_api_nodes/apis/PixverseDto.py +++ b/comfy_api_nodes/apis/PixverseDto.py @@ -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], ) diff --git a/comfy_api_nodes/apis/__init__.py b/comfy_api_nodes/apis/__init__.py index 304668168..e34b68f8d 100644 --- a/comfy_api_nodes/apis/__init__.py +++ b/comfy_api_nodes/apis/__init__.py @@ -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 (1–10). Only 1 supported for dall-e-3.', + examples=[1], + ) + output_compression: Optional[int] = Field( + None, description='Compression level for JPEG or WebP (0–100)', 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