mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 12:11:09 +00:00
Merge pull request #1448 from QwenLM/fix/openai-compatible
fix(core): handle missing delta in OpenAI stream chunks
This commit is contained in:
commit
bde31d1261
2 changed files with 22 additions and 1 deletions
|
|
@ -207,6 +207,27 @@ describe('OpenAIContentConverter', () => {
|
||||||
expect.objectContaining({ text: 'visible text' }),
|
expect.objectContaining({ text: 'visible text' }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not throw when streaming chunk has no delta', () => {
|
||||||
|
const chunk = converter.convertOpenAIChunkToGemini({
|
||||||
|
object: 'chat.completion.chunk',
|
||||||
|
id: 'chunk-2',
|
||||||
|
created: 456,
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
index: 0,
|
||||||
|
// Some OpenAI-compatible providers may omit delta entirely.
|
||||||
|
delta: undefined,
|
||||||
|
finish_reason: null,
|
||||||
|
logprobs: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
model: 'gpt-test',
|
||||||
|
} as unknown as OpenAI.Chat.ChatCompletionChunk);
|
||||||
|
|
||||||
|
const parts = chunk.candidates?.[0]?.content?.parts;
|
||||||
|
expect(parts).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('convertGeminiToolsToOpenAI', () => {
|
describe('convertGeminiToolsToOpenAI', () => {
|
||||||
|
|
|
||||||
|
|
@ -799,7 +799,7 @@ export class OpenAIContentConverter {
|
||||||
const parts: Part[] = [];
|
const parts: Part[] = [];
|
||||||
|
|
||||||
const reasoningText = (choice.delta as ExtendedCompletionChunkDelta)
|
const reasoningText = (choice.delta as ExtendedCompletionChunkDelta)
|
||||||
.reasoning_content;
|
?.reasoning_content;
|
||||||
if (reasoningText) {
|
if (reasoningText) {
|
||||||
parts.push({ text: reasoningText, thought: true });
|
parts.push({ text: reasoningText, thought: true });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue