From d010dd9d8042481b4f11fee131d29e5b4bc15474 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 5 May 2025 01:22:49 -0700 Subject: [PATCH] Show errors and API output URLs to the user (change log levels) (#131) --- comfy_api_nodes/apis/client.py | 36 ++++++++++++---------------------- comfy_api_nodes/nodes_kling.py | 15 ++++++-------- comfy_api_nodes/nodes_pika.py | 2 +- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/comfy_api_nodes/apis/client.py b/comfy_api_nodes/apis/client.py index 2a7a3adab..496831ac4 100644 --- a/comfy_api_nodes/apis/client.py +++ b/comfy_api_nodes/apis/client.py @@ -1,11 +1,3 @@ -import logging -import time -from typing import Callable -import io - -from comfy.cli_args import args -from comfy import utils - """ API Client Framework for api.comfy.org. @@ -97,21 +89,18 @@ operation = PollingOperation( result = operation.execute(client=api_client) # Returns the final ImageGenerationResult when done """ -from typing import ( - Dict, - Type, - Optional, - Any, - TypeVar, - Generic, -) -from pydantic import BaseModel, Field +import logging +import time +import io +from typing import Dict, Type, Optional, Any, TypeVar, Generic, Callable from enum import Enum import json import requests from urllib.parse import urljoin +from pydantic import BaseModel, Field -# Import models from your generated stubs +from comfy.cli_args import args +from comfy import utils T = TypeVar("T", bound=BaseModel) R = TypeVar("R", bound=BaseModel) @@ -475,7 +464,7 @@ class SynchronousOperation(Generic[T, R]): return self._parse_response(resp) except Exception as e: - logging.debug(f"[DEBUG] API Exception: {str(e)}") + logging.error(f"[DEBUG] API Exception: {str(e)}") raise Exception(str(e)) def _parse_response(self, resp): @@ -554,7 +543,7 @@ class PollingOperation(Generic[T, R]): return TaskStatus.FAILED return TaskStatus.PENDING except Exception as e: - logging.debug(f"Error extracting status: {e}") + logging.error(f"Error extracting status: {e}") return TaskStatus.PENDING def _poll_until_complete(self, client: ApiClient) -> R: @@ -609,8 +598,9 @@ class PollingOperation(Generic[T, R]): progress.update(100) return self.final_response elif status == TaskStatus.FAILED: - logging.debug(f"[DEBUG] Task failed: {json.dumps(resp)}") - raise Exception(f"Task failed: {json.dumps(resp)}") + message = f"Task failed: {json.dumps(resp)}" + logging.error(f"[DEBUG] {message}") + raise Exception(message) else: logging.debug("[DEBUG] Task still pending, continuing to poll...") @@ -621,5 +611,5 @@ class PollingOperation(Generic[T, R]): time.sleep(self.poll_interval) except Exception as e: - logging.debug(f"[DEBUG] Polling error: {str(e)}") + logging.error(f"[DEBUG] Polling error: {str(e)}") raise Exception(f"Error while polling: {str(e)}") diff --git a/comfy_api_nodes/nodes_kling.py b/comfy_api_nodes/nodes_kling.py index 208a3730a..b36c1c544 100644 --- a/comfy_api_nodes/nodes_kling.py +++ b/comfy_api_nodes/nodes_kling.py @@ -179,7 +179,7 @@ def validate_prompts(prompt: str, negative_prompt: str, max_length: int) -> bool return True -def validate_task_creation_response(response): +def validate_task_creation_response(response) -> None: """Validates that the Kling task creation request was successful.""" if not is_valid_task_creation_response(response): error_msg = f"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}" @@ -187,7 +187,7 @@ def validate_task_creation_response(response): raise KlingApiError(error_msg) -def validate_video_result_response(response): +def validate_video_result_response(response) -> None: """Validates that the Kling task result contains a video.""" if not is_valid_video_response(response): error_msg = f"Kling task {response.data.task_id} succeeded but no video data found in response." @@ -195,7 +195,7 @@ def validate_video_result_response(response): raise KlingApiError(error_msg) -def validate_image_result_response(response): +def validate_image_result_response(response) -> None: """Validates that the Kling task result contains an image.""" if not is_valid_image_response(response): error_msg = f"Kling task {response.data.task_id} succeeded but no image data found in response." @@ -221,7 +221,7 @@ def get_camera_control_input_config( def get_video_from_response(response) -> KlingVideoResult: """Returns the first video object from the Kling video generation task result.""" video = response.data.task_result.videos[0] - logging.debug( + logging.info( "Kling task %s succeeded. Video URL: %s", response.data.task_id, video.url ) return video @@ -229,7 +229,7 @@ def get_video_from_response(response) -> KlingVideoResult: def get_images_from_response(response) -> list[KlingImageResult]: images = response.data.task_result.images - logging.debug("Kling task %s succeeded. Images: %s", response.data.task_id, images) + logging.info("Kling task %s succeeded. Images: %s", response.data.task_id, images) return images @@ -255,10 +255,7 @@ def image_result_to_node_output( class KlingNodeBase(ComfyNodeABC): - """ - Base class for Kling nodes. - - """ + """Base class for Kling nodes.""" FUNCTION = "api_call" CATEGORY = "api node/video/Kling" diff --git a/comfy_api_nodes/nodes_pika.py b/comfy_api_nodes/nodes_pika.py index 64f9645da..ba4e8457d 100644 --- a/comfy_api_nodes/nodes_pika.py +++ b/comfy_api_nodes/nodes_pika.py @@ -173,7 +173,7 @@ class PikaNodeBase(ComfyNodeABC): raise PikaApiError(error_msg) video_url = str(final_response.url) - logging.debug("Pika task %s succeeded. Video URL: %s", task_id, video_url) + logging.info("Pika task %s succeeded. Video URL: %s", task_id, video_url) return (download_url_to_video_output(video_url),)