Files

1 line
6.7 KiB
JSON

{"repo": "164149043/alphacouncil", "files": {"api/ai/deepseek.js": {"39961e25ce926f94a4a8d7881d2592198624e3db": {"t": 1785745524.7656765, "n": 1965, "h": "229fbacaae0a5fbe", "c": "import fetch from 'node-fetch';\n\nconst DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;\n\nif (!DEEPSEEK_API_KEY) {\n console.error('[DeepSeek] 未配置 DEEPSEEK_API_KEY 环境变量');\n}\n\nexport default async function handler(req, res) {\n // 设置 CORS 头\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n return res.status(200).end();\n }\n\n if (req.method !== 'POST') {\n return res.status(405).json({ success: false, error: 'Method not allowed' });\n }\n\n const { model, systemPrompt, prompt, temperature, apiKey } = req.body;\n\n // 优先使用 Vercel 环境变量,前端传递的 API Key 作为备用\n const effectiveApiKey = DEEPSEEK_API_KEY || apiKey;\n\n if (!effectiveApiKey) {\n return res.status(500).json({\n success: false,\n error: '未配置 DeepSeek API Key。请在 Vercel 项目设置中配置 DEEPSEEK_API_KEY 环境变量,或在前端临时输入 API Key'\n });\n }\n\n try {\n const response = await fetch('https://api.deepseek.com/chat/completions', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${effectiveApiKey}`\n },\n body: JSON.stringify({\n model: model || 'deepseek-chat',\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: prompt }\n ],\n temperature: temperature || 0.7,\n stream: false\n })\n });\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(`DeepSeek API 错误: ${error.error?.message || response.statusText}`);\n }\n\n const data = await response.json();\n return res.json({\n success: true,\n text: data.choices?.[0]?.message?.content || ''\n });\n } catch (error) {\n console.error('[DeepSeek] 请求失败:', error.message);\n return res.status(500).json({\n success: false,\n error: error.message\n });\n }\n}\n"}, "517424630b541d3fd0d51b1c9a67d71e60fedaf6": {"t": 1785753864.851085, "n": 1965, "h": "229fbacaae0a5fbe", "c": "import fetch from 'node-fetch';\n\nconst DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;\n\nif (!DEEPSEEK_API_KEY) {\n console.error('[DeepSeek] 未配置 DEEPSEEK_API_KEY 环境变量');\n}\n\nexport default async function handler(req, res) {\n // 设置 CORS 头\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n return res.status(200).end();\n }\n\n if (req.method !== 'POST') {\n return res.status(405).json({ success: false, error: 'Method not allowed' });\n }\n\n const { model, systemPrompt, prompt, temperature, apiKey } = req.body;\n\n // 优先使用 Vercel 环境变量,前端传递的 API Key 作为备用\n const effectiveApiKey = DEEPSEEK_API_KEY || apiKey;\n\n if (!effectiveApiKey) {\n return res.status(500).json({\n success: false,\n error: '未配置 DeepSeek API Key。请在 Vercel 项目设置中配置 DEEPSEEK_API_KEY 环境变量,或在前端临时输入 API Key'\n });\n }\n\n try {\n const response = await fetch('https://api.deepseek.com/chat/completions', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${effectiveApiKey}`\n },\n body: JSON.stringify({\n model: model || 'deepseek-chat',\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: prompt }\n ],\n temperature: temperature || 0.7,\n stream: false\n })\n });\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(`DeepSeek API 错误: ${error.error?.message || response.statusText}`);\n }\n\n const data = await response.json();\n return res.json({\n success: true,\n text: data.choices?.[0]?.message?.content || ''\n });\n } catch (error) {\n console.error('[DeepSeek] 请求失败:', error.message);\n return res.status(500).json({\n success: false,\n error: error.message\n });\n }\n}\n"}, "3c9a87af6143de4715f2068e70653e2ae453b386": {"t": 1785753866.2634125, "n": 1944, "h": "cc682d11c684a3b8", "c": "import fetch from 'node-fetch';\n\nconst DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;\n\nif (!DEEPSEEK_API_KEY) {\n console.error('[DeepSeek] 未配置 DEEPSEEK_API_KEY 环境变量');\n}\n\nexport default async function handler(req, res) {\n // 设置 CORS 头\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n return res.status(200).end();\n }\n\n if (req.method !== 'POST') {\n return res.status(405).json({ success: false, error: 'Method not allowed' });\n }\n\n const { model, systemPrompt, prompt, temperature, apiKey } = req.body;\n\n // 优先使用前端传递的 API Key,其次使用环境变量\n const effectiveApiKey = apiKey || DEEPSEEK_API_KEY;\n\n if (!effectiveApiKey) {\n return res.status(500).json({\n success: false,\n error: '未配置 DeepSeek API Key。请在前端输入 API Key 或联系管理员设置环境变量 DEEPSEEK_API_KEY'\n });\n }\n\n try {\n const response = await fetch('https://api.deepseek.com/chat/completions', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${effectiveApiKey}`\n },\n body: JSON.stringify({\n model: model || 'deepseek-chat',\n messages: [\n { role: 'system', content: systemPrompt },\n { role: 'user', content: prompt }\n ],\n temperature: temperature || 0.7,\n stream: false\n })\n });\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(`DeepSeek API 错误: ${error.error?.message || response.statusText}`);\n }\n\n const data = await response.json();\n return res.json({\n success: true,\n text: data.choices?.[0]?.message?.content || ''\n });\n } catch (error) {\n console.error('[DeepSeek] 请求失败:', error.message);\n return res.status(500).json({\n success: false,\n error: error.message\n });\n }\n}\n"}}}}