feat(suite): confirm AI writing cost before request
This commit is contained in:
+42
-1
@@ -12,7 +12,15 @@ try:
|
||||
except ModuleNotFoundError: # pragma: no cover - GUI import guard
|
||||
Signal = None
|
||||
|
||||
from .. import ai, image_studio, image_studio_export, image_studio_generation, image_studio_images
|
||||
from .. import (
|
||||
ai,
|
||||
appconfig,
|
||||
cmhub_models,
|
||||
image_studio,
|
||||
image_studio_export,
|
||||
image_studio_generation,
|
||||
image_studio_images,
|
||||
)
|
||||
from ..collect_skip import ALIAS_UNMATCHED, LOGIN_REQUIRED, empty_skip_reason_counts
|
||||
from .widgets import *
|
||||
|
||||
@@ -484,6 +492,38 @@ class ProductSuiteAiWriteWorker(BaseWorker):
|
||||
}
|
||||
|
||||
|
||||
class CMHubModelCatalogWorker(BaseWorker):
|
||||
"""Fetch a transient cmhub model catalog without blocking a product workflow."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
base_url,
|
||||
api_key,
|
||||
*,
|
||||
connect_timeout=10,
|
||||
use_system_proxy=False,
|
||||
):
|
||||
super().__init__()
|
||||
self.base_url = appconfig.normalize_cmhub_base_url(base_url)
|
||||
self.api_key = str(api_key or "")
|
||||
self.connect_timeout = max(1, int(connect_timeout or 10))
|
||||
self.use_system_proxy = bool(use_system_proxy)
|
||||
|
||||
def execute(self):
|
||||
if self.should_cancel():
|
||||
return {"cancelled": True}
|
||||
models = ai.fetch_cmhub_models(
|
||||
self.base_url,
|
||||
self.api_key,
|
||||
connect_timeout=self.connect_timeout,
|
||||
use_system_proxy=self.use_system_proxy,
|
||||
)
|
||||
if self.should_cancel():
|
||||
return {"cancelled": True}
|
||||
cmhub_models.cache_model_catalog(self.base_url, models)
|
||||
return {"models": models}
|
||||
|
||||
|
||||
class ProductSuiteImportImagesWorker(BaseWorker):
|
||||
"""Validate and copy local product images outside the GUI thread."""
|
||||
|
||||
@@ -2869,6 +2909,7 @@ class CMHubSettingsWorker(BaseWorker):
|
||||
self.api_key,
|
||||
connect_timeout=self.connect_timeout,
|
||||
)
|
||||
cmhub_models.cache_model_catalog(self.base_url, models)
|
||||
balance = None
|
||||
if self.include_balance:
|
||||
balance = ai.fetch_cmhub_balance(
|
||||
|
||||
Reference in New Issue
Block a user