mirror of
https://github.com/vegu-ai/talemate.git
synced 2025-12-16 11:47:48 +01:00
linting
This commit is contained in:
@@ -85,12 +85,15 @@ class Backend(BackendBase):
|
||||
@property
|
||||
def status_cache_key(self) -> str:
|
||||
return f"{self.name}-{self.instance_label}"
|
||||
|
||||
|
||||
async def on_status_change(self):
|
||||
visual_agent = get_agent("visual")
|
||||
log.debug("Backend.on_status_change", backend=self.name, instance_label=self.instance_label)
|
||||
log.debug(
|
||||
"Backend.on_status_change",
|
||||
backend=self.name,
|
||||
instance_label=self.instance_label,
|
||||
)
|
||||
await visual_agent.emit_status()
|
||||
|
||||
|
||||
def _update_status_from_future(self, fut: asyncio.Future):
|
||||
current_status = self.status
|
||||
@@ -104,7 +107,7 @@ class Backend(BackendBase):
|
||||
else:
|
||||
self.status = result
|
||||
self._test_conn_cache[self.status_cache_key] = self.status
|
||||
|
||||
|
||||
if current_status and current_status != self.status:
|
||||
asyncio.create_task(self.on_status_change())
|
||||
|
||||
@@ -125,7 +128,7 @@ class Backend(BackendBase):
|
||||
|
||||
def _get_cache_data(self) -> dict:
|
||||
"""Override this method to return data that should be cached after successful test_connection.
|
||||
|
||||
|
||||
Returns a dict of data to cache. The dict will be stored and can be retrieved
|
||||
by other backend instances sharing the same cache key.
|
||||
"""
|
||||
@@ -133,7 +136,7 @@ class Backend(BackendBase):
|
||||
|
||||
def _apply_cache_data(self, data: dict):
|
||||
"""Override this method to apply cached data to this backend instance.
|
||||
|
||||
|
||||
Called when using cached status to restore any additional data that was
|
||||
cached from a previous test_connection call.
|
||||
"""
|
||||
@@ -154,13 +157,13 @@ class Backend(BackendBase):
|
||||
|
||||
# log.debug("Testing connection to backend", backend=self.name, instance_label=self.instance_label)
|
||||
status = await self.test_connection()
|
||||
|
||||
|
||||
# Store cache data if test_connection was successful
|
||||
if status.type == BackendStatusType.OK:
|
||||
cache_data = self._get_cache_data()
|
||||
if cache_data:
|
||||
self._test_conn_cache_data[self.status_cache_key] = cache_data
|
||||
|
||||
|
||||
return status
|
||||
|
||||
async def test_connection(self, timeout: int = 2) -> BackendStatus:
|
||||
|
||||
@@ -98,7 +98,8 @@ class Backend(backends.Backend):
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
url=f"{normalize_api_url(self.api_url)}/sdapi/v1/samplers", timeout=timeout
|
||||
url=f"{normalize_api_url(self.api_url)}/sdapi/v1/samplers",
|
||||
timeout=timeout,
|
||||
)
|
||||
ready = response.status_code == 200
|
||||
return backends.BackendStatus(
|
||||
@@ -172,7 +173,9 @@ class Backend(backends.Backend):
|
||||
log.info("automatic1111.Backend.cancel_request", api_url=self.api_url)
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(url=f"{normalize_api_url(self.api_url)}/sdapi/v1/interrupt")
|
||||
response = await client.post(
|
||||
url=f"{normalize_api_url(self.api_url)}/sdapi/v1/interrupt"
|
||||
)
|
||||
response.raise_for_status()
|
||||
log.info("automatic1111.Backend.cancel_request", response=response.text)
|
||||
except Exception as e:
|
||||
|
||||
@@ -323,7 +323,9 @@ class Backend(backends.Backend):
|
||||
|
||||
log.debug("ComfyUI - Getting object info", api_url=self.api_url)
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(url=f"{normalize_api_url(self.api_url)}/object_info")
|
||||
response = await client.get(
|
||||
url=f"{normalize_api_url(self.api_url)}/object_info"
|
||||
)
|
||||
self._object_info = response.json()
|
||||
|
||||
return self._object_info
|
||||
@@ -423,7 +425,8 @@ class Backend(backends.Backend):
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
url=f"{normalize_api_url(self.api_url)}/system_stats", timeout=timeout
|
||||
url=f"{normalize_api_url(self.api_url)}/system_stats",
|
||||
timeout=timeout,
|
||||
)
|
||||
ready = response.status_code == 200
|
||||
return backends.BackendStatus(
|
||||
@@ -444,7 +447,9 @@ class Backend(backends.Backend):
|
||||
|
||||
async def get_history(self, prompt_id: str):
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(url=f"{normalize_api_url(self.api_url)}/history/{prompt_id}")
|
||||
response = await client.get(
|
||||
url=f"{normalize_api_url(self.api_url)}/history/{prompt_id}"
|
||||
)
|
||||
return response.json()
|
||||
|
||||
async def get_image(self, filename: str, subfolder: str, folder_type: str):
|
||||
@@ -452,7 +457,9 @@ class Backend(backends.Backend):
|
||||
url_values = urllib.parse.urlencode(data)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(url=f"{normalize_api_url(self.api_url)}/view?{url_values}")
|
||||
response = await client.get(
|
||||
url=f"{normalize_api_url(self.api_url)}/view?{url_values}"
|
||||
)
|
||||
return response.content
|
||||
|
||||
async def get_images(self, prompt_id: str, max_wait: int | None = None):
|
||||
@@ -512,7 +519,9 @@ class Backend(backends.Backend):
|
||||
}
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(
|
||||
f"{normalize_api_url(self.api_url)}/upload/image", files=files, data=data
|
||||
f"{normalize_api_url(self.api_url)}/upload/image",
|
||||
files=files,
|
||||
data=data,
|
||||
)
|
||||
r.raise_for_status()
|
||||
out = r.json()
|
||||
@@ -606,7 +615,9 @@ class Backend(backends.Backend):
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
_response = await client.post(url=f"{normalize_api_url(self.api_url)}/prompt", json=payload)
|
||||
_response = await client.post(
|
||||
url=f"{normalize_api_url(self.api_url)}/prompt", json=payload
|
||||
)
|
||||
_response.raise_for_status()
|
||||
|
||||
log.info("comfyui.Backend.generate", response=_response.text)
|
||||
@@ -634,7 +645,9 @@ class Backend(backends.Backend):
|
||||
log.info("comfyui.Backend.cancel_request", api_url=self.api_url)
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(url=f"{normalize_api_url(self.api_url)}/interrupt")
|
||||
response = await client.post(
|
||||
url=f"{normalize_api_url(self.api_url)}/interrupt"
|
||||
)
|
||||
response.raise_for_status()
|
||||
log.info("comfyui.Backend.cancel_request", response=response.text)
|
||||
except Exception as e:
|
||||
|
||||
@@ -78,17 +78,21 @@ class Backend(backends.Backend):
|
||||
type=backends.BackendStatusType.ERROR, message=str(e)
|
||||
)
|
||||
return self.status
|
||||
|
||||
|
||||
async def on_status_change(self):
|
||||
visual_agent = get_agent("visual")
|
||||
choices_changed_create = False
|
||||
choices_changed_edit = False
|
||||
if self.status.type == backends.BackendStatusType.OK:
|
||||
choices_changed_create = await visual_agent.sdnext_update_model_choices("sdnext_image_create", backend=self)
|
||||
choices_changed_edit = await visual_agent.sdnext_update_model_choices("sdnext_image_edit", backend=self)
|
||||
choices_changed_create = await visual_agent.sdnext_update_model_choices(
|
||||
"sdnext_image_create", backend=self
|
||||
)
|
||||
choices_changed_edit = await visual_agent.sdnext_update_model_choices(
|
||||
"sdnext_image_edit", backend=self
|
||||
)
|
||||
if choices_changed_create or choices_changed_edit:
|
||||
await super().on_status_change()
|
||||
|
||||
|
||||
def _get_cache_data(self) -> dict:
|
||||
"""Return models list to cache for sharing with other backends."""
|
||||
return {"models": self.models}
|
||||
@@ -528,9 +532,13 @@ class SDNextMixin:
|
||||
if choices
|
||||
else [{"label": "- Default Model -", "value": ""}]
|
||||
)
|
||||
|
||||
log.debug("sdnext_update_model_choices", old_choices=old_choices, new_choices=action.config["model"].choices)
|
||||
|
||||
|
||||
log.debug(
|
||||
"sdnext_update_model_choices",
|
||||
old_choices=old_choices,
|
||||
new_choices=action.config["model"].choices,
|
||||
)
|
||||
|
||||
choices_changed = old_choices != action.config["model"].choices
|
||||
return choices_changed
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
def normalize_api_url(url: str | None) -> str:
|
||||
"""Strip trailing slash from API URL for request construction.
|
||||
|
||||
|
||||
Args:
|
||||
url: The API URL to normalize. Can be a string or None.
|
||||
|
||||
|
||||
Returns:
|
||||
Normalized URL string. Returns empty string if url is None.
|
||||
"""
|
||||
@@ -15,4 +15,3 @@ def normalize_api_url(url: str | None) -> str:
|
||||
if not isinstance(url, str):
|
||||
url = str(url)
|
||||
return url.rstrip("/")
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ def list_scenes_directory(path: str = ".", list_images: bool = True) -> list:
|
||||
"""
|
||||
current_dir = os.getcwd()
|
||||
|
||||
scenes = _list_files_and_directories(os.path.join(current_dir, "scenes"), path, list_images=list_images)
|
||||
scenes = _list_files_and_directories(
|
||||
os.path.join(current_dir, "scenes"), path, list_images=list_images
|
||||
)
|
||||
|
||||
return scenes
|
||||
|
||||
@@ -23,7 +25,11 @@ def _list_files_and_directories(root: str, path: str, list_images: bool = True)
|
||||
:return: List of files and directories in the given root directory.
|
||||
"""
|
||||
# Define the file patterns to match
|
||||
patterns = ["characters/*.png", "characters/*.webp", "*/*.json"] if list_images else ["*/*.json"]
|
||||
patterns = (
|
||||
["characters/*.png", "characters/*.webp", "*/*.json"]
|
||||
if list_images
|
||||
else ["*/*.json"]
|
||||
)
|
||||
|
||||
items = []
|
||||
|
||||
@@ -38,7 +44,7 @@ def _list_files_and_directories(root: str, path: str, list_images: bool = True)
|
||||
# skip changelog files
|
||||
if "changelog" in dirpath.split(os.sep):
|
||||
continue
|
||||
|
||||
|
||||
# skp assets directory
|
||||
if "assets" in dirpath.split(os.sep):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user