mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 21:42:27 +08:00
chore(OpenAIApiClient): fallback to message when delta.content is empty (#8101)
* chore(OpenAIApiClient): fallback to message when delta.content is empty, fix missing content issue Signed-off-by: luoxu1314 <xiaoluoxu@163.com> * Update OpenAIApiClient.ts * Update OpenAIApiClient.ts --------- Signed-off-by: luoxu1314 <xiaoluoxu@163.com> Co-authored-by: one <wangan.cs@gmail.com>
This commit is contained in:
parent
c2d438fba3
commit
1b129636ed
@ -703,9 +703,15 @@ export class OpenAIAPIClient extends OpenAIBaseClient<
|
||||
|
||||
// 对于流式响应,使用 delta;对于非流式响应,使用 message。
|
||||
// 然而某些 OpenAI 兼容平台在非流式请求时会错误地返回一个空对象的 delta 字段。
|
||||
// 如果 delta 为空对象,应当忽略它并回退到 message,避免造成内容缺失。
|
||||
// 如果 delta 为空对象或content为空,应当忽略它并回退到 message,避免造成内容缺失。
|
||||
let contentSource: OpenAISdkRawContentSource | null = null
|
||||
if ('delta' in choice && choice.delta && Object.keys(choice.delta).length > 0) {
|
||||
if (
|
||||
'delta' in choice &&
|
||||
choice.delta &&
|
||||
Object.keys(choice.delta).length > 0 &&
|
||||
(!('content' in choice.delta) ||
|
||||
(typeof choice.delta.content === 'string' && choice.delta.content !== ''))
|
||||
) {
|
||||
contentSource = choice.delta
|
||||
} else if ('message' in choice) {
|
||||
contentSource = choice.message
|
||||
|
||||
Loading…
Reference in New Issue
Block a user