fix: 处理 AI API 返回为空的情况,提示检查模型名
This commit is contained in:
@@ -322,9 +322,14 @@ ${extras?.maxScore ?? 100}
|
|||||||
timeout: ((getStore().get('timeout') as number) ?? 120) * 1000
|
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)
|
const parsed = tryParseJson(content)
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
|
log.error('AI 返回 JSON 解析失败:', content.slice(0, 500))
|
||||||
throw new Error(`AI 返回格式异常,无法解析为 JSON。原始返回:\n${content}`)
|
throw new Error(`AI 返回格式异常,无法解析为 JSON。原始返回:\n${content}`)
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export function openDialogWindow(type: string): BrowserWindow | null {
|
|||||||
settings: { width: 520, height: 560 },
|
settings: { width: 520, height: 560 },
|
||||||
history: { width: 800, height: 600 },
|
history: { width: 800, height: 600 },
|
||||||
templates: { width: 640, height: 520 },
|
templates: { width: 640, height: 520 },
|
||||||
rubric: { width: 520, height: 480 },
|
rubric: { width: 640, height: 700 },
|
||||||
result: { width: 440, height: 560 }
|
result: { width: 440, height: 560 }
|
||||||
}
|
}
|
||||||
const size = sizes[type] || { width: 500, height: 500 }
|
const size = sizes[type] || { width: 500, height: 500 }
|
||||||
|
|||||||
@@ -130,5 +130,7 @@ function handleClose() {
|
|||||||
border: 1px solid #e4e7ed;
|
border: 1px solid #e4e7ed;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
max-height: 480px;
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user