fix: add missing 'index' to Gemini streaming tool calls and improve tests
This commit is contained in:
parent
06327a408a
commit
ac47e04cf9
3 changed files with 72 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
export default {
|
export default {
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.js$': 'babel-jest',
|
'^.+\\.(js|mjs)$': 'babel-jest',
|
||||||
},
|
},
|
||||||
transformIgnorePatterns: [
|
transformIgnorePatterns: [
|
||||||
'/node_modules/(?!(uuid)/)', // uuid is an ESM module that needs to be transformed
|
'/node_modules/(?!(uuid)/)', // uuid is an ESM module that needs to be transformed
|
||||||
|
|
@ -15,8 +15,7 @@ export default {
|
||||||
'^(\\.{1,2}/.*)\\.js$': '$1'
|
'^(\\.{1,2}/.*)\\.js$': '$1'
|
||||||
},
|
},
|
||||||
testMatch: [
|
testMatch: [
|
||||||
'**/tests/api-server.test.js',
|
'**/tests/**/*.test.js'
|
||||||
'**/tests/api-integration.test.js'
|
|
||||||
],
|
],
|
||||||
collectCoverageFrom: [
|
collectCoverageFrom: [
|
||||||
'src/**/*.js',
|
'src/**/*.js',
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,7 @@ export class GeminiConverter extends BaseConverter {
|
||||||
}
|
}
|
||||||
if (part.functionCall) {
|
if (part.functionCall) {
|
||||||
toolCalls.push({
|
toolCalls.push({
|
||||||
|
index: toolCalls.length,
|
||||||
id: part.functionCall.id || `call_${uuidv4()}`,
|
id: part.functionCall.id || `call_${uuidv4()}`,
|
||||||
type: 'function',
|
type: 'function',
|
||||||
function: {
|
function: {
|
||||||
|
|
|
||||||
69
tests/gemini-converter.test.js
Normal file
69
tests/gemini-converter.test.js
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
|
||||||
|
import GeminiConverter from '../src/converters/strategies/GeminiConverter.js';
|
||||||
|
import { jest } from '@jest/globals';
|
||||||
|
|
||||||
|
describe('GeminiConverter', () => {
|
||||||
|
let converter;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
converter = new GeminiConverter();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toOpenAIStreamChunk adds index to tool_calls', () => {
|
||||||
|
const geminiChunk = {
|
||||||
|
candidates: [{
|
||||||
|
content: {
|
||||||
|
parts: [{
|
||||||
|
functionCall: {
|
||||||
|
name: 'test_tool',
|
||||||
|
args: { param: 'value' }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = converter.toOpenAIStreamChunk(geminiChunk, 'gemini-pro');
|
||||||
|
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result.choices[0].delta).toHaveProperty('tool_calls');
|
||||||
|
expect(result.choices[0].delta.tool_calls).toHaveLength(1);
|
||||||
|
expect(result.choices[0].delta.tool_calls[0]).toHaveProperty('index');
|
||||||
|
expect(result.choices[0].delta.tool_calls[0].index).toBe(0);
|
||||||
|
expect(result.choices[0].delta.tool_calls[0].function.name).toBe('test_tool');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toOpenAIStreamChunk handles multiple tool_calls with correct indices', () => {
|
||||||
|
const geminiChunk = {
|
||||||
|
candidates: [{
|
||||||
|
content: {
|
||||||
|
parts: [
|
||||||
|
{
|
||||||
|
functionCall: {
|
||||||
|
name: 'tool_one',
|
||||||
|
args: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
functionCall: {
|
||||||
|
name: 'tool_two',
|
||||||
|
args: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = converter.toOpenAIStreamChunk(geminiChunk, 'gemini-pro');
|
||||||
|
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result.choices[0].delta.tool_calls).toHaveLength(2);
|
||||||
|
|
||||||
|
expect(result.choices[0].delta.tool_calls[0].index).toBe(0);
|
||||||
|
expect(result.choices[0].delta.tool_calls[0].function.name).toBe('tool_one');
|
||||||
|
|
||||||
|
expect(result.choices[0].delta.tool_calls[1].index).toBe(1);
|
||||||
|
expect(result.choices[0].delta.tool_calls[1].function.name).toBe('tool_two');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue