fix: map finish_reason to 'tool_calls' in Gemini stream when tool calls are present
This commit is contained in:
parent
d9fca2eaea
commit
902bee1aa5
2 changed files with 26 additions and 0 deletions
|
|
@ -232,6 +232,11 @@ export class GeminiConverter extends BaseConverter {
|
||||||
candidate.finishReason.toLowerCase();
|
candidate.finishReason.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果包含工具调用,且完成原因为 stop,则将完成原因修改为 tool_calls
|
||||||
|
if (toolCalls.length > 0 && finishReason === 'stop') {
|
||||||
|
finishReason = 'tool_calls';
|
||||||
|
}
|
||||||
|
|
||||||
// 构建delta对象
|
// 构建delta对象
|
||||||
const delta = {};
|
const delta = {};
|
||||||
if (content) delta.content = content;
|
if (content) delta.content = content;
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,25 @@ describe('GeminiConverter', () => {
|
||||||
expect(result.choices[0].delta.tool_calls[1].index).toBe(1);
|
expect(result.choices[0].delta.tool_calls[1].index).toBe(1);
|
||||||
expect(result.choices[0].delta.tool_calls[1].function.name).toBe('tool_two');
|
expect(result.choices[0].delta.tool_calls[1].function.name).toBe('tool_two');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('toOpenAIStreamChunk sets finish_reason to tool_calls when tool calls are present and finishReason is STOP', () => {
|
||||||
|
const geminiChunk = {
|
||||||
|
candidates: [{
|
||||||
|
finishReason: 'STOP',
|
||||||
|
content: {
|
||||||
|
parts: [{
|
||||||
|
functionCall: {
|
||||||
|
name: 'test_tool',
|
||||||
|
args: {}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = converter.toOpenAIStreamChunk(geminiChunk, 'gemini-pro');
|
||||||
|
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result.choices[0].finish_reason).toBe('tool_calls');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue