T-576 增加生成和更新内容模式
This commit is contained in:
@@ -40,6 +40,8 @@ CMHUB_CONFIG_PATH = os.path.join(default_data_dir(), "config", "cmhub.json")
|
||||
CATEGORIES = {"text", "image"}
|
||||
API_TYPES = {"chat", "images_edits", "auto"}
|
||||
AI_BACKENDS = {"direct", "cmhub"}
|
||||
AI_GENERATE_MODES = {"title", "cover", "title_cover"}
|
||||
SHOPEE_UPDATE_MODES = {"title", "cover", "title_cover"}
|
||||
AI_CONCURRENCY_MIN = 1
|
||||
AI_CONCURRENCY_MAX = 5
|
||||
AI_RETRY_MIN = 0
|
||||
@@ -78,6 +80,7 @@ DEFAULT_CONFIG = {
|
||||
"default_text_model": "GPT-5.5 文本",
|
||||
"default_image_model": "Nano Banana 2",
|
||||
"generate_cover": False,
|
||||
"generate_mode": "",
|
||||
"backend": "cmhub",
|
||||
"cmhub": {
|
||||
"base_url": "",
|
||||
@@ -104,6 +107,7 @@ DEFAULT_CONFIG = {
|
||||
"test_item_id": "51100639510",
|
||||
"allow_real_submit": False,
|
||||
"allow_cover_update": False,
|
||||
"update_mode": "",
|
||||
"max_items_per_run": 1,
|
||||
"close_success_tab": False,
|
||||
"dry_run": False,
|
||||
@@ -357,6 +361,11 @@ def _normalize_config_values(config, migrate_old_cmhub_connect_timeout=False):
|
||||
return config
|
||||
ai = config.get("ai")
|
||||
if isinstance(ai, dict):
|
||||
ai["generate_mode"] = normalize_generate_mode(
|
||||
ai.get("generate_mode"),
|
||||
generate_cover=ai.get("generate_cover", False),
|
||||
)
|
||||
ai["generate_cover"] = generate_mode_includes_cover(ai["generate_mode"])
|
||||
ai["title_concurrency"] = _clamp_int(
|
||||
ai.get("title_concurrency"),
|
||||
AI_CONCURRENCY_MIN,
|
||||
@@ -385,6 +394,13 @@ def _normalize_config_values(config, migrate_old_cmhub_connect_timeout=False):
|
||||
cmhub["download_with_curl"] = _normalize_cmhub_download_with_curl(
|
||||
cmhub.get("download_with_curl", "auto")
|
||||
)
|
||||
update = config.get("shopee_update")
|
||||
if isinstance(update, dict):
|
||||
update["update_mode"] = normalize_update_mode(
|
||||
update.get("update_mode"),
|
||||
allow_cover_update=update.get("allow_cover_update", False),
|
||||
)
|
||||
update["allow_cover_update"] = update_mode_includes_cover(update["update_mode"])
|
||||
return config
|
||||
|
||||
|
||||
@@ -632,6 +648,55 @@ def ai_config(config=None) -> dict:
|
||||
return copy.deepcopy(_config_or_load(config).get("ai", DEFAULT_CONFIG["ai"]))
|
||||
|
||||
|
||||
def normalize_generate_mode(value=None, generate_cover=None) -> str:
|
||||
text = str(value or "").strip().lower()
|
||||
if text in AI_GENERATE_MODES:
|
||||
return text
|
||||
return "title_cover" if bool(generate_cover) else "title"
|
||||
|
||||
|
||||
def generate_mode_includes_title(mode) -> bool:
|
||||
return normalize_generate_mode(mode) in {"title", "title_cover"}
|
||||
|
||||
|
||||
def generate_mode_includes_cover(mode) -> bool:
|
||||
return normalize_generate_mode(mode) in {"cover", "title_cover"}
|
||||
|
||||
|
||||
def ai_generate_mode(config=None) -> str:
|
||||
ai = ai_config(config)
|
||||
return normalize_generate_mode(ai.get("generate_mode"), generate_cover=ai.get("generate_cover", False))
|
||||
|
||||
|
||||
def normalize_update_mode(value=None, allow_cover_update=None) -> str:
|
||||
text = str(value or "").strip().lower()
|
||||
if text in SHOPEE_UPDATE_MODES:
|
||||
return text
|
||||
return "title_cover" if bool(allow_cover_update) else "title"
|
||||
|
||||
|
||||
def update_mode_includes_title(mode) -> bool:
|
||||
return normalize_update_mode(mode) in {"title", "title_cover"}
|
||||
|
||||
|
||||
def update_mode_includes_cover(mode) -> bool:
|
||||
return normalize_update_mode(mode) in {"cover", "title_cover"}
|
||||
|
||||
|
||||
def shopee_update_config(config=None) -> dict:
|
||||
cfg = _config_or_load(config)
|
||||
loaded = cfg.get("shopee_update", {})
|
||||
if not isinstance(loaded, dict):
|
||||
loaded = {}
|
||||
merged = _deep_merge(DEFAULT_CONFIG["shopee_update"], loaded)
|
||||
merged["update_mode"] = normalize_update_mode(
|
||||
merged.get("update_mode"),
|
||||
allow_cover_update=merged.get("allow_cover_update", False),
|
||||
)
|
||||
merged["allow_cover_update"] = update_mode_includes_cover(merged["update_mode"])
|
||||
return merged
|
||||
|
||||
|
||||
|
||||
def ai_backend(config=None) -> str:
|
||||
ai = ai_config(config)
|
||||
|
||||
Reference in New Issue
Block a user