fix: normalize ollama tool calls from content and thinking
This commit is contained in:
@@ -49,4 +49,25 @@ describe('Response Rewriter', () => {
|
||||
expect(result.message.content).toBe("Here are the calls"); // not cleared
|
||||
expect(result.message.tool_calls).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('rewrites tool call found in thinking into structured tool_calls', () => {
|
||||
const inputResponse: OllamaChatResponse = {
|
||||
model: "test-model",
|
||||
done: true,
|
||||
message: {
|
||||
role: "assistant",
|
||||
content: "",
|
||||
thinking: "<tool_call>\n{\"name\":\"read\",\"arguments\":{\"path\":\"/tmp/test.txt\"}}\n</tool_call>"
|
||||
}
|
||||
};
|
||||
|
||||
const result = rewriteResponse(inputResponse);
|
||||
|
||||
expect(result.message.content).toBe("");
|
||||
expect(result.message.tool_calls).toBeDefined();
|
||||
expect(result.message.tool_calls).toHaveLength(1);
|
||||
expect(result.message.tool_calls![0].function.name).toBe("read");
|
||||
expect(result.message.tool_calls![0].function.arguments).toEqual({ path: "/tmp/test.txt" });
|
||||
expect(result.message.thinking).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -45,4 +45,17 @@ hello
|
||||
const result = parseXmlToolCalls(content);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('parses JSON tool calls wrapped in tool_call tags', () => {
|
||||
const content = `
|
||||
<tool_call>
|
||||
{"name":"read","arguments":{"path":"/tmp/test.txt"}}
|
||||
</tool_call>
|
||||
`;
|
||||
|
||||
const result = parseXmlToolCalls(content);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].name).toBe('read');
|
||||
expect(result[0].args).toEqual({ path: '/tmp/test.txt' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user