fix: rewrite vllm tool calls from reasoning content

This commit is contained in:
lingyuzeng
2026-03-22 19:56:45 +08:00
parent 8eb7b25ec9
commit 7a718d8983
3 changed files with 92 additions and 38 deletions

View File

@@ -50,4 +50,29 @@ describe('vLLM Response Rewriter', () => {
expect(result.choices[0].message.content).toBe("Here are the calls");
expect(result.choices[0].message.tool_calls).toHaveLength(1);
});
it('rewrites tool call found in reasoning_content into structured tool_calls', () => {
const inputResponse = {
id: "chatcmpl-123",
choices: [{
index: 0,
message: {
role: "assistant",
content: "",
reasoning_content: "<tool_call>\n{\"name\":\"read\",\"arguments\":{\"path\":\"/tmp/test.txt\"}}\n</tool_call>"
}
}]
};
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);
expect(result.choices[0].message.tool_calls[0].function.name).toBe("read");
expect(JSON.parse(result.choices[0].message.tool_calls[0].function.arguments)).toEqual({
path: "/tmp/test.txt"
});
expect(result.choices[0].message.reasoning_content).toBe("");
});
});