mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-06 05:00:29 -06:00
test: unit test tool calls
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { expect } = require('chai');
|
||||
const Messages = require('./Messages.js');
|
||||
const OpenAIUtil = require('./OpenAIUtil.js');
|
||||
|
||||
describe('Messages', () => {
|
||||
describe('normalize_single_message', () => {
|
||||
@@ -70,4 +71,114 @@ describe('Messages', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
describe('normalize OpenAI tool calls', () => {
|
||||
const cases = [
|
||||
{
|
||||
name: 'string message',
|
||||
input: {
|
||||
role: 'assistant',
|
||||
tool_calls: [
|
||||
{
|
||||
id: 'tool-1',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'tool-1-function',
|
||||
arguments: {},
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
output: {
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'tool-1',
|
||||
name: 'tool-1-function',
|
||||
input: {},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
for ( const tc of cases ) {
|
||||
it(`should normalize ${tc.name}`, () => {
|
||||
const output = Messages.normalize_single_message(tc.input);
|
||||
expect(output).to.deep.equal(tc.output);
|
||||
});
|
||||
}
|
||||
});
|
||||
describe('normalize Claude tool calls', () => {
|
||||
const cases = [
|
||||
{
|
||||
name: 'string message',
|
||||
input: {
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'tool-1',
|
||||
name: 'tool-1-function',
|
||||
input: "{}",
|
||||
}
|
||||
]
|
||||
},
|
||||
output: {
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'tool-1',
|
||||
name: 'tool-1-function',
|
||||
input: "{}",
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
for ( const tc of cases ) {
|
||||
it(`should normalize ${tc.name}`, () => {
|
||||
const output = Messages.normalize_single_message(tc.input);
|
||||
expect(output).to.deep.equal(tc.output);
|
||||
});
|
||||
}
|
||||
});
|
||||
describe('OpenAI-ify normalized tool calls', () => {
|
||||
const cases = [
|
||||
{
|
||||
name: 'string message',
|
||||
input: [{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'tool-1',
|
||||
name: 'tool-1-function',
|
||||
input: {},
|
||||
}
|
||||
]
|
||||
}],
|
||||
output: [{
|
||||
role: 'assistant',
|
||||
content: null,
|
||||
tool_calls: [
|
||||
{
|
||||
id: 'tool-1',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'tool-1-function',
|
||||
arguments: '{}',
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
}
|
||||
];
|
||||
for ( const tc of cases ) {
|
||||
it(`should normalize ${tc.name}`, async () => {
|
||||
const output = await OpenAIUtil.process_input_messages(tc.input);
|
||||
expect(output).to.deep.equal(tc.output);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user