/* OpenAI 相容供應商預設。模型清單可在側邊欄按「抓取模型」從 /models 取得,或手動輸入。 */ export const PROVIDER_PRESETS = [ { name: 'OpenRouter', baseUrl: 'https://openrouter.ai/api/v1', models: ['nvidia/nemotron-3-ultra-550b-a55b:free'] }, { name: 'OpenAI', baseUrl: 'https://api.openai.com/v1', models: [] }, { name: 'Google Gemini', baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai', models: [] }, { name: 'Groq', baseUrl: 'https://api.groq.com/openai/v1', models: [] }, { name: 'DeepSeek', baseUrl: 'https://api.deepseek.com/v1', models: ['deepseek-chat', 'deepseek-reasoner'] }, { name: 'Mistral', baseUrl: 'https://api.mistral.ai/v1', models: [] }, { name: 'Together', baseUrl: 'https://api.together.xyz/v1', models: [] }, { name: 'SiliconFlow', baseUrl: 'https://api.siliconflow.cn/v1', models: [] }, { name: 'Cohere', baseUrl: 'https://api.cohere.ai/compatibility/v1', models: [] }, { name: 'Ollama(本機)', baseUrl: 'http://localhost:11434/v1', models: [], noKey: true }, { name: 'LM Studio(本機)', baseUrl: 'http://localhost:1234/v1', models: [], noKey: true }, { name: '自訂', baseUrl: '', models: [] }, ] export const uid = () => Math.random().toString(36).slice(2, 10) + Date.now().toString(36).slice(-4) export function makeProvider(preset) { return { id: uid(), name: preset.name, baseUrl: preset.baseUrl, apiKey: '', noKey: !!preset.noKey, models: [...(preset.models || [])], } } /** 從供應商的 /models 端點抓模型 id 清單 */ export async function fetchModels(provider) { const base = String(provider.baseUrl).replace(/\/+$/, '') const res = await fetch(`${base}/models`, { headers: provider.apiKey?.trim() ? { Authorization: `Bearer ${provider.apiKey.trim()}` } : {}, }) if (!res.ok) throw new Error(`HTTP ${res.status}`) const data = await res.json() const list = (data.data || data.models || []).map((m) => (typeof m === 'string' ? m : m.id || m.name)).filter(Boolean) return [...new Set(list.map((id) => String(id).replace(/^models\//, '')))].sort() }