first commit
This commit is contained in:
52
test/response-rewriter.test.ts
Executable file
52
test/response-rewriter.test.ts
Executable file
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { rewriteResponse } from '../src/proxy/response-rewriter';
|
||||
import { OllamaChatResponse } from '../src/types/ollama';
|
||||
|
||||
describe('Response Rewriter', () => {
|
||||
it('rewrites XML tool call in content into structured tool_calls', () => {
|
||||
const inputResponse: OllamaChatResponse = {
|
||||
model: "test-model",
|
||||
done: true,
|
||||
message: {
|
||||
role: "assistant",
|
||||
content: "<function=read>\n<parameter=path>\n/tmp/test.txt\n</parameter>\n</function>"
|
||||
}
|
||||
};
|
||||
|
||||
const result = rewriteResponse(inputResponse);
|
||||
|
||||
expect(result.message.content).toBe("");
|
||||
expect(result.message.tool_calls).toBeDefined();
|
||||
expect(result.message.tool_calls).toHaveLength(1);
|
||||
|
||||
const toolCall = result.message.tool_calls![0];
|
||||
expect(toolCall.type).toBe('function');
|
||||
expect(toolCall.function.name).toBe('read');
|
||||
|
||||
const argsObject = JSON.parse(toolCall.function.arguments);
|
||||
expect(argsObject).toEqual({ path: '/tmp/test.txt' });
|
||||
});
|
||||
|
||||
it('does not touch response that already has tool_calls', () => {
|
||||
const inputResponse: OllamaChatResponse = {
|
||||
model: "test-model",
|
||||
done: true,
|
||||
message: {
|
||||
role: "assistant",
|
||||
content: "Here are the calls",
|
||||
tool_calls: [
|
||||
{
|
||||
id: "123",
|
||||
type: "function",
|
||||
function: { name: "read", arguments: "{}" }
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const result = rewriteResponse(inputResponse);
|
||||
|
||||
expect(result.message.content).toBe("Here are the calls"); // not cleared
|
||||
expect(result.message.tool_calls).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user