fix: normalize ollama tool calls from content and thinking

This commit is contained in:
lingyuzeng
2026-03-22 19:54:47 +08:00
parent 3f51c4a6b4
commit 8eb7b25ec9
6 changed files with 121 additions and 43 deletions

View File

@@ -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("");
});
});