T-529 default to cmhub gateway
This commit is contained in:
+13
-35
@@ -68,6 +68,7 @@ class SettingsTab(QWidget):
|
||||
self.backend_combo.setObjectName("aiBackendCombo")
|
||||
for label, value in self.BACKEND_ITEMS:
|
||||
self.backend_combo.addItem(label, value)
|
||||
self.backend_combo.setVisible(False)
|
||||
self.cmhub_base_url_edit = QLineEdit()
|
||||
self.cmhub_base_url_edit.setObjectName("cmhubBaseUrlEdit")
|
||||
self.cmhub_base_url_edit.setPlaceholderText("https://<cmhub>")
|
||||
@@ -266,8 +267,6 @@ class SettingsTab(QWidget):
|
||||
]
|
||||
)
|
||||
|
||||
backend_form = self._three_column_form([("AI 后端", self.backend_combo)])
|
||||
|
||||
self.model_picker_panel = QWidget()
|
||||
self.model_picker_panel.setLayout(model_picker_layout)
|
||||
|
||||
@@ -313,7 +312,7 @@ class SettingsTab(QWidget):
|
||||
self.settings_panel_layout = panel_layout
|
||||
panel_layout.setContentsMargins(13, 18, 13, 18)
|
||||
self.ai_model_section_title = self._section_title(
|
||||
"AI 模型",
|
||||
"cmhub 网关",
|
||||
"settingsAiModelSectionTitle",
|
||||
)
|
||||
self.model_detail_section_title = self._section_title(
|
||||
@@ -333,7 +332,6 @@ class SettingsTab(QWidget):
|
||||
"settingsInfrastructureSectionTitle",
|
||||
)
|
||||
panel_layout.addWidget(self.ai_model_section_title)
|
||||
panel_layout.addLayout(backend_form)
|
||||
panel_layout.addWidget(self.model_picker_panel)
|
||||
panel_layout.addSpacing(14)
|
||||
panel_layout.addWidget(self.model_detail_section_title)
|
||||
@@ -437,8 +435,6 @@ class SettingsTab(QWidget):
|
||||
def _maybe_auto_refresh_cmhub_models(self):
|
||||
if self._cmhub_auto_refresh_done:
|
||||
return
|
||||
if (self.backend_combo.currentData() or "direct") != "cmhub":
|
||||
return
|
||||
if not self.cmhub_base_url_edit.text().strip() or not self.cmhub_api_key_edit.text():
|
||||
return
|
||||
self._cmhub_auto_refresh_done = True
|
||||
@@ -454,12 +450,12 @@ class SettingsTab(QWidget):
|
||||
return appconfig.CMHUB_CONFIG_PATH
|
||||
|
||||
def _on_backend_changed(self, index=None):
|
||||
is_cmhub = (self.backend_combo.currentData() or "direct") == "cmhub"
|
||||
self.model_picker_panel.setVisible(not is_cmhub)
|
||||
self.model_detail_section_title.setVisible(not is_cmhub)
|
||||
self.model_detail_panel.setVisible(not is_cmhub)
|
||||
self.direct_role_panel.setVisible(not is_cmhub)
|
||||
self.cmhub_panel.setVisible(is_cmhub)
|
||||
self.backend_combo.setVisible(False)
|
||||
self.model_picker_panel.setVisible(False)
|
||||
self.model_detail_section_title.setVisible(False)
|
||||
self.model_detail_panel.setVisible(False)
|
||||
self.direct_role_panel.setVisible(False)
|
||||
self.cmhub_panel.setVisible(True)
|
||||
self._set_cmhub_running(self.cmhub_thread is not None)
|
||||
self._update_button_state()
|
||||
|
||||
@@ -623,12 +619,9 @@ class SettingsTab(QWidget):
|
||||
self._show_error("默认调试端口必须在调试端口范围内")
|
||||
return None
|
||||
ai_cfg = appconfig.ai_config(self.config)
|
||||
backend = self.backend_combo.currentData() or "direct"
|
||||
backend = "cmhub"
|
||||
text_model = self.default_text_model_combo.currentData() or ai_cfg.get("default_text_model")
|
||||
image_model = self.default_image_model_combo.currentData() or ai_cfg.get("default_image_model")
|
||||
if backend == "direct" and (not text_model or not image_model):
|
||||
self._show_error("标题大模型和图片大模型不能为空")
|
||||
return None
|
||||
cmhub_cfg = self._cmhub_settings_values(backend)
|
||||
if cmhub_cfg is None:
|
||||
return None
|
||||
@@ -686,23 +679,9 @@ class SettingsTab(QWidget):
|
||||
"connect_timeout": self.cmhub_connect_timeout_spin.value(),
|
||||
"check_balance_before_batch": self.cmhub_check_balance_checkbox.isChecked(),
|
||||
}
|
||||
if backend != "cmhub":
|
||||
merged = dict(current)
|
||||
merged.update(values)
|
||||
return merged
|
||||
missing = []
|
||||
if not values["base_url"]:
|
||||
missing.append("Base URL")
|
||||
if not self.cmhub_api_key_edit.text():
|
||||
missing.append("API Key")
|
||||
if not values["title_alias"]:
|
||||
missing.append("生文别名")
|
||||
if not values["image_alias"]:
|
||||
missing.append("生图别名")
|
||||
if missing:
|
||||
self._show_error("cmhub 配置不完整:缺少 " + "、".join(missing))
|
||||
return None
|
||||
return values
|
||||
merged = dict(current)
|
||||
merged.update(values)
|
||||
return merged
|
||||
|
||||
def _replace_config(self, saved):
|
||||
internal = {}
|
||||
@@ -719,8 +698,7 @@ class SettingsTab(QWidget):
|
||||
def _populate_app_settings(self):
|
||||
self._populate_role_model_combos()
|
||||
ai_cfg = appconfig.ai_config(self.config)
|
||||
backend = ai_cfg.get("backend", "direct")
|
||||
self._set_combo_by_data(self.backend_combo, backend)
|
||||
self._set_combo_by_data(self.backend_combo, "cmhub")
|
||||
cmhub_cfg = appconfig.cmhub_config(self.config)
|
||||
self.cmhub_base_url_edit.setText(cmhub_cfg.get("base_url", ""))
|
||||
self._loaded_cmhub_api_key = appconfig.get_cmhub_api_key(path=self.cmhub_config_path)
|
||||
|
||||
Reference in New Issue
Block a user