mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-09-06 17:47:07 +08:00
Show errors and API output URLs to the user (change log levels) (#131)
This commit is contained in:
parent
337e707103
commit
d010dd9d80
@ -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.
|
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
|
result = operation.execute(client=api_client) # Returns the final ImageGenerationResult when done
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import (
|
import logging
|
||||||
Dict,
|
import time
|
||||||
Type,
|
import io
|
||||||
Optional,
|
from typing import Dict, Type, Optional, Any, TypeVar, Generic, Callable
|
||||||
Any,
|
|
||||||
TypeVar,
|
|
||||||
Generic,
|
|
||||||
)
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from urllib.parse import urljoin
|
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)
|
T = TypeVar("T", bound=BaseModel)
|
||||||
R = TypeVar("R", bound=BaseModel)
|
R = TypeVar("R", bound=BaseModel)
|
||||||
@ -475,7 +464,7 @@ class SynchronousOperation(Generic[T, R]):
|
|||||||
return self._parse_response(resp)
|
return self._parse_response(resp)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.debug(f"[DEBUG] API Exception: {str(e)}")
|
logging.error(f"[DEBUG] API Exception: {str(e)}")
|
||||||
raise Exception(str(e))
|
raise Exception(str(e))
|
||||||
|
|
||||||
def _parse_response(self, resp):
|
def _parse_response(self, resp):
|
||||||
@ -554,7 +543,7 @@ class PollingOperation(Generic[T, R]):
|
|||||||
return TaskStatus.FAILED
|
return TaskStatus.FAILED
|
||||||
return TaskStatus.PENDING
|
return TaskStatus.PENDING
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.debug(f"Error extracting status: {e}")
|
logging.error(f"Error extracting status: {e}")
|
||||||
return TaskStatus.PENDING
|
return TaskStatus.PENDING
|
||||||
|
|
||||||
def _poll_until_complete(self, client: ApiClient) -> R:
|
def _poll_until_complete(self, client: ApiClient) -> R:
|
||||||
@ -609,8 +598,9 @@ class PollingOperation(Generic[T, R]):
|
|||||||
progress.update(100)
|
progress.update(100)
|
||||||
return self.final_response
|
return self.final_response
|
||||||
elif status == TaskStatus.FAILED:
|
elif status == TaskStatus.FAILED:
|
||||||
logging.debug(f"[DEBUG] Task failed: {json.dumps(resp)}")
|
message = f"Task failed: {json.dumps(resp)}"
|
||||||
raise Exception(f"Task failed: {json.dumps(resp)}")
|
logging.error(f"[DEBUG] {message}")
|
||||||
|
raise Exception(message)
|
||||||
else:
|
else:
|
||||||
logging.debug("[DEBUG] Task still pending, continuing to poll...")
|
logging.debug("[DEBUG] Task still pending, continuing to poll...")
|
||||||
|
|
||||||
@ -621,5 +611,5 @@ class PollingOperation(Generic[T, R]):
|
|||||||
time.sleep(self.poll_interval)
|
time.sleep(self.poll_interval)
|
||||||
|
|
||||||
except Exception as e:
|
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)}")
|
raise Exception(f"Error while polling: {str(e)}")
|
||||||
|
|||||||
@ -179,7 +179,7 @@ def validate_prompts(prompt: str, negative_prompt: str, max_length: int) -> bool
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def validate_task_creation_response(response):
|
def validate_task_creation_response(response) -> None:
|
||||||
"""Validates that the Kling task creation request was successful."""
|
"""Validates that the Kling task creation request was successful."""
|
||||||
if not is_valid_task_creation_response(response):
|
if not is_valid_task_creation_response(response):
|
||||||
error_msg = f"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}"
|
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)
|
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."""
|
"""Validates that the Kling task result contains a video."""
|
||||||
if not is_valid_video_response(response):
|
if not is_valid_video_response(response):
|
||||||
error_msg = f"Kling task {response.data.task_id} succeeded but no video data found in 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)
|
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."""
|
"""Validates that the Kling task result contains an image."""
|
||||||
if not is_valid_image_response(response):
|
if not is_valid_image_response(response):
|
||||||
error_msg = f"Kling task {response.data.task_id} succeeded but no image data found in 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:
|
def get_video_from_response(response) -> KlingVideoResult:
|
||||||
"""Returns the first video object from the Kling video generation task result."""
|
"""Returns the first video object from the Kling video generation task result."""
|
||||||
video = response.data.task_result.videos[0]
|
video = response.data.task_result.videos[0]
|
||||||
logging.debug(
|
logging.info(
|
||||||
"Kling task %s succeeded. Video URL: %s", response.data.task_id, video.url
|
"Kling task %s succeeded. Video URL: %s", response.data.task_id, video.url
|
||||||
)
|
)
|
||||||
return video
|
return video
|
||||||
@ -229,7 +229,7 @@ def get_video_from_response(response) -> KlingVideoResult:
|
|||||||
|
|
||||||
def get_images_from_response(response) -> list[KlingImageResult]:
|
def get_images_from_response(response) -> list[KlingImageResult]:
|
||||||
images = response.data.task_result.images
|
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
|
return images
|
||||||
|
|
||||||
|
|
||||||
@ -255,10 +255,7 @@ def image_result_to_node_output(
|
|||||||
|
|
||||||
|
|
||||||
class KlingNodeBase(ComfyNodeABC):
|
class KlingNodeBase(ComfyNodeABC):
|
||||||
"""
|
"""Base class for Kling nodes."""
|
||||||
Base class for Kling nodes.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
FUNCTION = "api_call"
|
FUNCTION = "api_call"
|
||||||
CATEGORY = "api node/video/Kling"
|
CATEGORY = "api node/video/Kling"
|
||||||
|
|||||||
@ -173,7 +173,7 @@ class PikaNodeBase(ComfyNodeABC):
|
|||||||
raise PikaApiError(error_msg)
|
raise PikaApiError(error_msg)
|
||||||
|
|
||||||
video_url = str(final_response.url)
|
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),)
|
return (download_url_to_video_output(video_url),)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user