fix: 处理 AI API 返回为空的情况,提示检查模型名

This commit is contained in:
2026-07-16 05:59:45 +08:00
parent 31c435c410
commit d346b5fc56
3 changed files with 9 additions and 2 deletions
+6 -1
View File
@@ -322,9 +322,14 @@ ${extras?.maxScore ?? 100}
timeout: ((getStore().get('timeout') as number) ?? 120) * 1000
})
const content = response.data.choices[0].message.content
const content = response.data?.choices?.[0]?.message?.content
if (!content) {
log.error('AI API 返回为空或格式异常:', JSON.stringify(response.data).slice(0, 1000))
throw new Error(`API 返回为空,请检查模型名是否正确 (当前: ${config.model})`)
}
const parsed = tryParseJson(content)
if (!parsed) {
log.error('AI 返回 JSON 解析失败:', content.slice(0, 500))
throw new Error(`AI 返回格式异常,无法解析为 JSON。原始返回:\n${content}`)
}
return {
+1 -1
View File
@@ -61,7 +61,7 @@ export function openDialogWindow(type: string): BrowserWindow | null {
settings: { width: 520, height: 560 },
history: { width: 800, height: 600 },
templates: { width: 640, height: 520 },
rubric: { width: 520, height: 480 },
rubric: { width: 640, height: 700 },
result: { width: 440, height: 560 }
}
const size = sizes[type] || { width: 500, height: 500 }
+2
View File
@@ -130,5 +130,7 @@ function handleClose() {
border: 1px solid #e4e7ed;
border-radius: 6px;
padding: 16px;
max-height: 480px;
overflow-y: auto;
}
</style>