fix(OpenAIProvider): ensure tool_calls are only yielded when present (#6861)

This update modifies the OpenAIProvider to yield tool_calls only if they exist and have a length greater than zero, improving the handling of delta content. Additionally, a minor cleanup was performed by removing an unnecessary blank line in the code.
This commit is contained in:
SuYao 2025-06-05 22:49:29 +08:00 committed by GitHub
parent b44b397cdd
commit dd15b391c5

View File

@ -635,7 +635,7 @@ export default class OpenAIProvider extends BaseOpenAIProvider {
if (delta?.content) {
yield { type: 'text-delta', textDelta: delta.content }
}
if (delta?.tool_calls) {
if (delta?.tool_calls && delta?.tool_calls.length > 0) {
yield { type: 'tool-calls', delta: delta }
}
@ -664,7 +664,6 @@ export default class OpenAIProvider extends BaseOpenAIProvider {
for await (const chunk of readableStreamAsyncIterable(processedStream)) {
const delta = chunk.type === 'finish' ? chunk.delta : chunk
const rawChunk = chunk.type === 'finish' ? chunk.chunk : chunk
switch (chunk.type) {
case 'reasoning': {
if (time_first_token_millsec === 0) {