/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ // 体验中心:判断当前模型是否具备分析上传文件的能力。 // // 采用"反向黑名单"策略而不是正向白名单: // - 主流多模态模型(gpt-4o / claude-3 / gemini-* / qwen-vl / o1 / o3 等)数量大且持续增长, // 维护正向列表必然漏判 → 默认放行; // - 只把已知**文本-only**的传统模型列入黑名单,避免它们被选中时用户却看到上传按钮, // 传上去再被上游 400 退回的尴尬体验。 // // 黑名单基于模型名前缀匹配,admin 后端可以通过自定义模型映射绕过;这里只是 UI 的预判, // 真要发请求时后端的 inlining / 上游错误仍是最终防线。 const LEGACY_TEXT_ONLY_PATTERNS = [ /^gpt-3\.5/i, // GPT-3.5 系列:纯文本 /^text-(davinci|curie|babbage|ada)/i, // OpenAI legacy completion 模型 /^(davinci|curie|babbage|ada)(-|$)/i, // 同上的简称 /^o1-mini/i, // OpenAI o1-mini:纯文本(无视觉/文件) /^o3-mini/i, // OpenAI o3-mini:纯文本 /^deepseek-(chat|coder)(-|$)/i, // DeepSeek 非视觉系列(V2.5 起部分支持,但 chat/coder 不支持) /^qwen(-?max|-?plus|-?turbo)(?!-vl)/i, // 通义千问非视觉系列(qwen-vl-* 才有视觉) /^moonshot-v1-(?!.*vision)/i, // Moonshot 非视觉系列 /embed/i, // embedding 模型不应出现在聊天里,但兜底 ]; /** * 当前模型是否支持文件/图片输入。 * @param {string} modelName 模型 ID(如 'gpt-4o-mini') * @returns {boolean} true = 支持(默认),false = 已知不支持 */ export const isModelFilesCapable = (modelName) => { if (!modelName || typeof modelName !== 'string') return true; const trimmed = modelName.trim(); if (trimmed === '') return true; return !LEGACY_TEXT_ONLY_PATTERNS.some((p) => p.test(trimmed)); }; /** * 当前模型是否被管理员允许图片输入。 * * 与后端 controller/playground.go 的视觉模型白名单逻辑保持一致: * - visionModelsConfig 为空(管理员未配置)→ 放行所有模型; * - 非空 → 仅白名单内模型放行。 * 配置来源:status.experience_center_vision_models(逗号分隔)。 * * @param {string} modelName 模型 ID * @param {string} visionModelsConfig 逗号分隔的白名单字符串 * @returns {boolean} */ export const isModelVisionAllowed = (modelName, visionModelsConfig) => { const config = typeof visionModelsConfig === 'string' ? visionModelsConfig.trim() : ''; if (config === '') return true; if (!modelName || typeof modelName !== 'string') return true; const allowed = config .split(',') .map((m) => m.trim()) .filter((m) => m !== ''); return allowed.includes(modelName.trim()); };