Files
openclaw-ollama-toolcall-proxy/test/vllm-rewriter.test.ts

54 lines
1.6 KiB
TypeScript
Executable File

import { describe, it, expect } from 'vitest';
import { rewriteVllmResponse } from '../src/proxy/vllm-response-rewriter';
describe('vLLM Response Rewriter', () => {
it('rewrites XML tool call in OpenAI choices content into structured tool_calls', () => {
const inputResponse = {
id: "chatcmpl-123",
choices: [{
index: 0,
message: {
role: "assistant",
content: "<function=read>\n<parameter=path>\n/tmp/test.txt\n</parameter>\n</function>"
}
}]
};
const result = rewriteVllmResponse(inputResponse);
expect(result.choices[0].message.content).toBe("");
expect(result.choices[0].message.tool_calls).toBeDefined();
expect(result.choices[0].message.tool_calls).toHaveLength(1);
const toolCall = result.choices[0].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 = {
choices: [{
message: {
role: "assistant",
content: "Here are the calls",
tool_calls: [
{
id: "123",
type: "function",
function: { name: "read", arguments: "{}" }
}
]
}
}]
};
const result = rewriteVllmResponse(inputResponse);
expect(result.choices[0].message.content).toBe("Here are the calls");
expect(result.choices[0].message.tool_calls).toHaveLength(1);
});
});