mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-10 06:10:50 +08:00
- Run comfyui workflows directly inside other python applications using EmbeddedComfyClient. - Optional telemetry in prompts and models using anonymity preserving Plausible self-hosted or hosted. - Better OpenAPI schema - Basic support for distributed ComfyUI backends. Limitations: no progress reporting, no easy way to start your own distributed backend, requires RabbitMQ as a message broker.
133 lines
4.3 KiB
Python
133 lines
4.3 KiB
Python
# coding: utf-8
|
|
|
|
"""
|
|
comfyui
|
|
No description provided (generated by Openapi JSON Schema Generator https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) # noqa: E501
|
|
The version of the OpenAPI document: 0.0.1
|
|
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
|
|
"""
|
|
|
|
import dataclasses
|
|
import typing
|
|
|
|
from comfy.api import api_response
|
|
|
|
|
|
class OpenApiException(Exception):
|
|
"""The base exception class for all OpenAPIExceptions"""
|
|
|
|
def render_path(path_to_item):
|
|
"""Returns a string representation of a path"""
|
|
result = ""
|
|
for pth in path_to_item:
|
|
if isinstance(pth, int):
|
|
result += "[{0}]".format(pth)
|
|
else:
|
|
result += "['{0}']".format(pth)
|
|
return result
|
|
|
|
|
|
class ApiTypeError(OpenApiException, TypeError):
|
|
def __init__(self, msg, path_to_item=None, valid_classes=None,
|
|
key_type=None):
|
|
""" Raises an exception for TypeErrors
|
|
|
|
Args:
|
|
msg (str): the exception message
|
|
|
|
Keyword Args:
|
|
path_to_item (list): a list of keys an indices to get to the
|
|
current_item
|
|
None if unset
|
|
valid_classes (tuple): the primitive classes that current item
|
|
should be an instance of
|
|
None if unset
|
|
key_type (bool): False if our value is a value in a dict
|
|
True if it is a key in a dict
|
|
False if our item is an item in a list
|
|
None if unset
|
|
"""
|
|
self.path_to_item = path_to_item
|
|
self.valid_classes = valid_classes
|
|
self.key_type = key_type
|
|
full_msg = msg
|
|
if path_to_item:
|
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
super(ApiTypeError, self).__init__(full_msg)
|
|
|
|
|
|
class ApiValueError(OpenApiException, ValueError):
|
|
def __init__(self, msg, path_to_item=None):
|
|
"""
|
|
Args:
|
|
msg (str): the exception message
|
|
|
|
Keyword Args:
|
|
path_to_item (list) the path to the exception in the
|
|
received_data dict. None if unset
|
|
"""
|
|
|
|
self.path_to_item = path_to_item
|
|
full_msg = msg
|
|
if path_to_item:
|
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
super(ApiValueError, self).__init__(full_msg)
|
|
|
|
|
|
class ApiAttributeError(OpenApiException, AttributeError):
|
|
def __init__(self, msg, path_to_item=None):
|
|
"""
|
|
Raised when an attribute reference or assignment fails.
|
|
|
|
Args:
|
|
msg (str): the exception message
|
|
|
|
Keyword Args:
|
|
path_to_item (None/list) the path to the exception in the
|
|
received_data dict
|
|
"""
|
|
self.path_to_item = path_to_item
|
|
full_msg = msg
|
|
if path_to_item:
|
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
super(ApiAttributeError, self).__init__(full_msg)
|
|
|
|
|
|
class ApiKeyError(OpenApiException, KeyError):
|
|
def __init__(self, msg, path_to_item=None):
|
|
"""
|
|
Args:
|
|
msg (str): the exception message
|
|
|
|
Keyword Args:
|
|
path_to_item (None/list) the path to the exception in the
|
|
received_data dict
|
|
"""
|
|
self.path_to_item = path_to_item
|
|
full_msg = msg
|
|
if path_to_item:
|
|
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
super(ApiKeyError, self).__init__(full_msg)
|
|
|
|
T = typing.TypeVar('T', bound=api_response.ApiResponse)
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class ApiException(OpenApiException, typing.Generic[T]):
|
|
status: int
|
|
reason: typing.Optional[str] = None
|
|
api_response: typing.Optional[T] = None
|
|
|
|
def __str__(self):
|
|
"""Custom error messages for exception"""
|
|
error_message = "({0})\n"\
|
|
"Reason: {1}\n".format(self.status, self.reason)
|
|
if self.api_response:
|
|
if self.api_response.response.headers:
|
|
error_message += "HTTP response headers: {0}\n".format(
|
|
self.api_response.response.headers)
|
|
if self.api_response.response.data:
|
|
error_message += "HTTP response body: {0}\n".format(self.api_response.response.data)
|
|
|
|
return error_message
|