diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 0c585c16a..b529e5fc2 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -216,10 +216,11 @@ class Setting extends AbstractModel /** * AI 机器人模型转数组 * @param $models - * @param bool $retValue + * @param bool $retValue 仅返回模型 value 列表 + * @param bool $visibleOnly 仅返回可见模型(跳过标记 hidden 的项,供展示给终端用户的场景) * @return array */ - public static function AIBotModels2Array($models, $retValue = false) + public static function AIBotModels2Array($models, $retValue = false, $visibleOnly = false) { $list = null; if (is_array($models)) { @@ -244,6 +245,10 @@ class Setting extends AbstractModel if ($value === '') { continue; } + // 隐藏模型:仍保存在设置中,但展示给终端用户时跳过($visibleOnly) + if ($visibleOnly && !empty($item['hidden'])) { + continue; + } $label = trim((string)($item['name'] ?? $item['label'] ?? '')); $thinking = strtolower(trim((string)($item['thinking'] ?? 'off'))); if (!in_array($thinking, ['off', 'low', 'medium', 'high'], true)) { diff --git a/app/Models/UserBot.php b/app/Models/UserBot.php index 11a09a719..84d08dfcf 100644 --- a/app/Models/UserBot.php +++ b/app/Models/UserBot.php @@ -273,8 +273,11 @@ class UserBot extends AbstractModel if ($match[1] === "ai-") { $aibotSetting = Base::setting('aibotSetting'); $aibotModel = $aibotSetting[$match[2] . '_model']; - $aibotModels = Setting::AIBotModels2Array($aibotSetting[$match[2] . '_models']); + $aibotModels = Setting::AIBotModels2Array($aibotSetting[$match[2] . '_models'], false, true); if ($aibotModels) { + if (!in_array($aibotModel, array_column($aibotModels, 'value'), true)) { + $aibotModel = $aibotModels[0]['value']; + } $menus = array_merge( [ [