feat(ai-bot): 增加 AIBotModels2Array 方法的可见性过滤选项

This commit is contained in:
kuaifan 2026-07-13 13:33:11 +00:00
parent 18163e1e82
commit 746a0bf9a1
2 changed files with 11 additions and 3 deletions

View File

@ -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)) {

View File

@ -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(
[
[