mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 05:11:24 +08:00
chore(OpenAIApiClient): handle empty delta objects in non-streaming esponses (#7658)
chore(OpenAIApiClient): handle empty delta objects in non-streaming responses
This commit is contained in:
parent
b0053b94a9
commit
7b7819217f
@ -639,9 +639,15 @@ export class OpenAIAPIClient extends OpenAIBaseClient<
|
||||
|
||||
if (!choice) return
|
||||
|
||||
// 对于流式响应,使用delta;对于非流式响应,使用message
|
||||
const contentSource: OpenAISdkRawContentSource | null =
|
||||
'delta' in choice ? choice.delta : 'message' in choice ? choice.message : null
|
||||
// 对于流式响应,使用 delta;对于非流式响应,使用 message。
|
||||
// 然而某些 OpenAI 兼容平台在非流式请求时会错误地返回一个空对象的 delta 字段。
|
||||
// 如果 delta 为空对象,应当忽略它并回退到 message,避免造成内容缺失。
|
||||
let contentSource: OpenAISdkRawContentSource | null = null
|
||||
if ('delta' in choice && choice.delta && Object.keys(choice.delta).length > 0) {
|
||||
contentSource = choice.delta
|
||||
} else if ('message' in choice) {
|
||||
contentSource = choice.message
|
||||
}
|
||||
|
||||
if (!contentSource) return
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user