chat : implement inkling parser (#32381)
This commit is contained in:
1 parent
4303cd94ae
commit
4ddf2b9470
9 files changed
+532
-54
No files matched your search
@@ -5516,6 +5516,102 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
|
||||
.run();
|
||||
}
|
||||
|
||||
// Inkling 1 and 2
|
||||
for (const int version : { 1, 2 }) {
|
||||
auto tst = peg_tester(version == 1 ? "models/templates/thinkingmachines-Inkling.jinja" :
|
||||
"models/templates/thinkingmachines-Inkling-2-Small.jinja", detailed_debug);
|
||||
|
||||
// Inkling 1 has the first header in the generation prompt, Inkling 2 writes it
|
||||
const std::string H = "<|message_model|>";
|
||||
const std::string P = version == 1 ? "" : H;
|
||||
const std::string E = "<|end_message|>";
|
||||
const std::string CALL = "special_function<|content_invoke_tool_json|>{\"name\":\"special_function\",\"args\":{\"arg1\":1}}" + E;
|
||||
|
||||
// Content only
|
||||
tst.test(P + "<|content_text|>Hello, world!\nWhat's up?" + E)
|
||||
.expect(message_assist)
|
||||
.run();
|
||||
|
||||
// Thinking block, then content block
|
||||
tst.test(P + "<|content_thinking|>I'm thinking" + E + H + "<|content_text|>Hello, world!\nWhat's up?" + E)
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.expect(simple_assist_msg("Hello, world!\nWhat's up?", "I'm thinking"))
|
||||
.run();
|
||||
|
||||
// Without reasoning extraction, the thinking block stays in the content
|
||||
tst.test(P + "<|content_thinking|>I'm thinking" + E + H + "<|content_text|>Hello, world!\nWhat's up?" + E)
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_NONE)
|
||||
.expect_content("<|content_thinking|>I'm thinking" + E + "Hello, world!\nWhat's up?")
|
||||
.run();
|
||||
|
||||
// Cut by the token limit, in thinking and in content
|
||||
tst.test(P + "<|content_thinking|>I was still thinking")
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.expect_reasoning("I was still thinking")
|
||||
.run();
|
||||
tst.test(P + "<|content_thinking|>I'm thinking" + E + H + "<|content_text|>Hello, wor")
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.expect(simple_assist_msg("Hello, wor", "I'm thinking"))
|
||||
.run();
|
||||
|
||||
// Single tool call
|
||||
tst.test(P + CALL)
|
||||
.tools({ special_function_tool })
|
||||
.expect_tool_calls({
|
||||
{ "special_function", R"({"arg1":1})", "" },
|
||||
})
|
||||
.expect_rules({ "tool-0" })
|
||||
.run();
|
||||
|
||||
// Thinking, content, then a tool call
|
||||
tst.test(P + "<|content_thinking|>I should call it" + E + H + "<|content_text|>On it." + E + H + CALL)
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.tools({ special_function_tool })
|
||||
.expect(simple_assist_msg("On it.", "I should call it", "special_function", R"({"arg1":1})", ""))
|
||||
.run();
|
||||
|
||||
// Tools given, but the model answers with content
|
||||
tst.test(P + "<|content_thinking|>No tool needed" + E + H + "<|content_text|>Hello, world!\nWhat's up?" + E)
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.tools({ special_function_tool })
|
||||
.expect(simple_assist_msg("Hello, world!\nWhat's up?", "No tool needed"))
|
||||
.run();
|
||||
|
||||
// Parallel tool calls, one block each
|
||||
tst.test(P + CALL + H +
|
||||
"special_function_with_opt<|content_invoke_tool_json|>{\"name\":\"special_function_with_opt\",\"args\":{\"arg1\":1,\"arg2\":2}}" + E)
|
||||
.parallel_tool_calls(true)
|
||||
.tools({ special_function_tool, special_function_tool_with_optional_param })
|
||||
.expect_tool_calls({
|
||||
{ "special_function", R"({"arg1":1})", "" },
|
||||
{ "special_function_with_opt", R"({"arg1":1,"arg2":2})", "" },
|
||||
})
|
||||
.run();
|
||||
|
||||
// The block closer inside a string argument does not end the block
|
||||
tst.test(P + "python<|content_invoke_tool_json|>{\"name\":\"python\",\"args\":{\"code\":\"print('<|end_message|>')\"}}" + E)
|
||||
.tools({ python_tool })
|
||||
.expect_tool_calls({
|
||||
{ "python", R"JSON({"code":"print('<|end_message|>')"})JSON", "" },
|
||||
})
|
||||
.run();
|
||||
|
||||
// Forced tool call
|
||||
tst.test(P + "<|content_thinking|>I should call it" + E + H + CALL)
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.tool_choice(COMMON_CHAT_TOOL_CHOICE_REQUIRED)
|
||||
.tools({ special_function_tool })
|
||||
.expect(simple_assist_msg("", "I should call it", "special_function", R"({"arg1":1})", ""))
|
||||
.run();
|
||||
|
||||
// Response format
|
||||
tst.test(P + "<|content_thinking|>I'm thinking" + E + H + "<|content_text|>{\"amount\": 123.45}" + E)
|
||||
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
|
||||
.json_schema(invoice_schema)
|
||||
.expect(simple_assist_msg("{\"amount\": 123.45}", "I'm thinking"))
|
||||
.run();
|
||||
}
|
||||
|
||||
// Kimi-K2-Thinking tests - custom parser
|
||||
// Unique feature: tool call ID embeds function name as functions.<name>:<counter>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user