fix: AI Chat LLM 从已失效 api.qnaigc.com 切换到 OpenCode Zen 免费 API
- 数据库 AIModel 记录从 meituan/longcat-flash-lite → deepseek-v4-flash-free - API 端点 https://api.qnaigc.com → https://opencode.ai/zen/v1/chat/completions - aiChat.js 支持免 Authorization 的免费 API(apiKey 为 sk-dummy 时跳过) - .env 同步更新
This commit is contained in:
@@ -91,22 +91,24 @@ router.post('/ask', userAuthMiddleware, async (req, res) => {
|
|||||||
modelConfig = { temperature: 0.7, maxTokens: 800, topP: 1 }
|
modelConfig = { temperature: 0.7, maxTokens: 800, topP: 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查API配置
|
// 检查API配置(opencode.ai免费API无需key)
|
||||||
if (!apiKey) {
|
const needsAuth = apiKey && apiKey !== 'sk-dummy' && apiKey !== '***'
|
||||||
logger.error('AI API Key未配置')
|
|
||||||
return ApiResponse.error(res, 'AI服务暂时不可用', 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建系统提示词
|
// 构建系统提示词
|
||||||
const systemPrompt = getSystemPromptByDimension(dimension)
|
const systemPrompt = getSystemPromptByDimension(dimension)
|
||||||
|
|
||||||
|
// 构建请求头
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
if (needsAuth) {
|
||||||
|
headers['Authorization'] = `Bearer ${apiKey}`
|
||||||
|
}
|
||||||
|
|
||||||
// 调用AI API
|
// 调用AI API
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${apiKey}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: modelId,
|
model: modelId,
|
||||||
messages: [
|
messages: [
|
||||||
|
|||||||
Reference in New Issue
Block a user