From 746a0bf9a15e73e2f8c3b083422033a039d0d3fb Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 13 Jul 2026 13:33:11 +0000 Subject: [PATCH] =?UTF-8?q?feat(ai-bot):=20=E5=A2=9E=E5=8A=A0=20AIBotModel?= =?UTF-8?q?s2Array=20=E6=96=B9=E6=B3=95=E7=9A=84=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=E6=80=A7=E8=BF=87=E6=BB=A4=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Setting.php | 9 +++++++-- app/Models/UserBot.php | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) 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( [ [