From e90100e1a5f2e11bbd0b4afbf9b298b04555cfc9 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Tue, 22 Apr 2025 02:45:41 -0700 Subject: [PATCH] Add. --- comfy_api_nodes/apis/PixverseController.py | 4 ++-- comfy_api_nodes/apis/PixverseDto.py | 4 ++-- comfy_api_nodes/apis/__init__.py | 17 +++++++++++++---- comfy_api_nodes/apis/client.py | 3 ++- comfy_api_nodes/nodes_api.py | 17 ++++++++++------- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/comfy_api_nodes/apis/PixverseController.py b/comfy_api_nodes/apis/PixverseController.py index 583fd26da..db49134fe 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:58:11+00:00 +# filename: http://localhost:8080/openapi +# timestamp: 2025-04-22T09:45:21+00:00 from __future__ import annotations diff --git a/comfy_api_nodes/apis/PixverseDto.py b/comfy_api_nodes/apis/PixverseDto.py index 32da4ab05..36e7b090e 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:58:11+00:00 +# filename: http://localhost:8080/openapi +# timestamp: 2025-04-22T09:45:21+00:00 from __future__ import annotations diff --git a/comfy_api_nodes/apis/__init__.py b/comfy_api_nodes/apis/__init__.py index e34b68f8d..fbf557bbf 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:58:11+00:00 +# filename: http://localhost:8080/openapi +# timestamp: 2025-04-22T09:45:21+00:00 from __future__ import annotations @@ -1139,6 +1139,15 @@ class OpenAIImageGenerationRequest(BaseModel): ) +class Datum1(BaseModel): + b64_json: Optional[str] = Field(None, description='Base64 encoded image data') + url: Optional[str] = Field(None, description='URL of the image') + + +class OpenAIImageGenerationResponse(BaseModel): + data: Optional[List[Datum1]] = None + + class PersonalAccessToken(BaseModel): createdAt: Optional[datetime] = Field( None, description='[Output Only]The date and time the token was created.' @@ -1186,7 +1195,7 @@ class RecraftImageGenerationRequest(BaseModel): ) -class Datum1(BaseModel): +class Datum2(BaseModel): image_id: Optional[str] = Field( None, description='Unique identifier for the generated image' ) @@ -1198,7 +1207,7 @@ class RecraftImageGenerationResponse(BaseModel): ..., description='Unix timestamp when the generation was created' ) credits: int = Field(..., description='Number of credits used for the generation') - data: List[Datum1] = Field(..., description='Array of generated image information') + data: List[Datum2] = Field(..., description='Array of generated image information') class StorageFile(BaseModel): diff --git a/comfy_api_nodes/apis/client.py b/comfy_api_nodes/apis/client.py index 9603221b2..0512d9e39 100644 --- a/comfy_api_nodes/apis/client.py +++ b/comfy_api_nodes/apis/client.py @@ -138,6 +138,7 @@ class ApiClient: request_headers = self.get_headers() if headers: request_headers.update(headers) + logging.debug(f"[DEBUG] Request Headers: {request_headers}") try: response = requests.request( method=method, @@ -220,7 +221,7 @@ class SynchronousOperation(Generic[T, R]): self, endpoint: ApiEndpoint[T, R], request: T, - api_base: str = "https://api.comfy.org", + api_base: str = "https://stagingapi.comfy.org", auth_token: Optional[str] = None, timeout: float = 30.0, verify_ssl: bool = True, diff --git a/comfy_api_nodes/nodes_api.py b/comfy_api_nodes/nodes_api.py index 600c1bc5f..386b9c670 100644 --- a/comfy_api_nodes/nodes_api.py +++ b/comfy_api_nodes/nodes_api.py @@ -7,6 +7,7 @@ from comfy_api_nodes.apis import ( IdeogramGenerateResponse, ImageRequest, OpenAIImageGenerationRequest, + OpenAIImageGenerationResponse ) from comfy_api_nodes.apis.client import ApiEndpoint, HttpMethod, SynchronousOperation @@ -214,6 +215,9 @@ class OpenAITextToImage(ComfyNodeABC): "tooltip": "Optional random seed", }), }, + "hidden": { + "auth_token": "AUTH_TOKEN_COMFY_ORG" + } } RETURN_TYPES = (IO.IMAGE,) @@ -222,7 +226,7 @@ class OpenAITextToImage(ComfyNodeABC): DESCRIPTION = cleandoc(__doc__ or "") API_NODE = True - def api_call(self, prompt, model, n=1, size="1024x1024", seed=0): + def api_call(self, prompt, model, n=1, size="1024x1024", seed=0, auth_token=None): # Validate size based on model if model == "dall-e-2": if size == "auto": @@ -251,7 +255,7 @@ class OpenAITextToImage(ComfyNodeABC): path="/proxy/openai/images/generations", method=HttpMethod.POST, request_model=OpenAIImageGenerationRequest, - response_model=None + response_model=OpenAIImageGenerationResponse ), request=OpenAIImageGenerationRequest( model=model, @@ -260,20 +264,19 @@ class OpenAITextToImage(ComfyNodeABC): size=size, seed=seed if seed != 0 else None ), + auth_token=auth_token ) response = operation.execute() # validate raw JSON response - if not isinstance(response, dict) or 'data' not in response: - raise Exception("Invalid response format from OpenAI endpoint") - data = response['data'] + data = response.data if not data or len(data) == 0: raise Exception("No images returned from OpenAI endpoint") # Get base64 image data - b64_data = data[0].get('b64_json') + b64_data = data[0].b64_json if not b64_data: raise Exception("No image data in OpenAI response") @@ -292,7 +295,7 @@ class OpenAITextToImage(ComfyNodeABC): # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "IdeogramTextToImage": IdeogramTextToImage, - "OpenAIDalleTextToImage": OpenAIDalleTextToImage, + "OpenAIDalleTextToImage": OpenAITextToImage, } # A dictionary that contains the friendly/humanly readable titles for the nodes