feat(settings): support gateway source switching

This commit is contained in:
chengma
2026-07-20 16:29:28 +08:00
parent ed1d8ee764
commit 6a0cd1c763
18 changed files with 746 additions and 77 deletions
+30 -5
View File
@@ -1089,7 +1089,7 @@ class GenerateTab(QWidget):
self.failed_progress_label = QLabel("失败 0")
self.failed_progress_label.setObjectName("generateFailedProgressLabel")
self.failed_progress_label.setVisible(False)
self.cmhub_balance_label = QLabel("cmhub余额:未获取")
self.cmhub_balance_label = QLabel("默认网关余额:未获取")
self.cmhub_balance_label.setObjectName("generateCmhubBalanceLabel")
self.cmhub_balance_label.setVisible(False)
self.title_elapsed_label = QLabel("生标题用时 0 秒")
@@ -1760,6 +1760,21 @@ class GenerateTab(QWidget):
if not self._save_generate_mode_setting(show_status=False):
return
generate_mode = self._current_generate_mode()
if not self._is_cmhub_backend():
try:
ai.validate_direct_generation_config(
self.config,
generate_mode,
models_path=(
self.config.get("ai_models_path")
or appconfig.ai_models_config_path(self.config)
),
)
except Exception as exc:
message = "自定义网关配置不完整:%s。请到⑤设置补齐本轮所需模型的地址、模型ID、API Key、接口类型和启用状态。" % str(exc)
QMessageBox.warning(self, "无法开始生成", message)
self._set_status("自定义网关配置不完整,请到⑤设置补齐", "warning")
return
generate_cover = appconfig.generate_mode_includes_cover(generate_mode)
base_candidates = self._generation_candidates(generate_mode)
if not base_candidates:
@@ -1837,7 +1852,12 @@ class GenerateTab(QWidget):
"generate_mode": generate_mode,
}
)
self._set_status(f"开始 AI 生成:{len(tasks)} 条")
if self._is_cmhub_backend():
self._set_status(f"开始 AI 生成:{len(tasks)} 条")
else:
self._set_status(
"开始 AI 生成:%d 条;自定义网关(不计点数,费用由服务商收取)" % len(tasks)
)
thread.start()
def _generation_candidates(self, generate_mode):
@@ -2282,7 +2302,7 @@ class GenerateTab(QWidget):
def _reset_cmhub_balance_label(self):
self.cmhub_balance_label.setVisible(False)
if self._is_cmhub_backend():
self.cmhub_balance_label.setText("cmhub余额:生成后刷新")
self.cmhub_balance_label.setText("默认网关余额:生成后刷新")
else:
self.cmhub_balance_label.setText("")
@@ -2293,9 +2313,14 @@ class GenerateTab(QWidget):
balance = payload.get("points_balance") if isinstance(payload, dict) else None
if balance is None:
if not self.cmhub_balance_label.text():
self.cmhub_balance_label.setText("cmhub余额:未获取")
self.cmhub_balance_label.setText("默认网关余额:未获取")
return
self.cmhub_balance_label.setText(f"cmhub余额:{balance}")
self.cmhub_balance_label.setText(f"默认网关余额:{balance}")
def refresh_gateway_state(self):
"""Clear source-specific feedback after ⑤ saves a new gateway source."""
self._reset_cmhub_balance_label()
def _is_cmhub_backend(self):
try: