diff --git a/common/parsers/muse-glimmer.cpp b/common/parsers/muse-glimmer.cpp index add95697eb..d03bf2d58f 100644 --- a/common/parsers/muse-glimmer.cpp +++ b/common/parsers/muse-glimmer.cpp @@ -130,7 +130,7 @@ common_chat_params common_chat_params_init_muse_glimmer(const common_chat_templa }); data.grammar_triggers = { { COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN, - "<\\|start\\|>assistant( to=(?!self<\\|message\\|>)(?!user<\\|message\\|>)[^<]*?<\\|message\\|>)" }, + "(?:^|<\\|start\\|>assistant)( to=(?!self<\\|message\\|>)(?!user<\\|message\\|>)[^<]*?<\\|message\\|>)" }, }; } diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp index 13733c1d9c..f2728f7cca 100644 --- a/tests/test-chat.cpp +++ b/tests/test-chat.cpp @@ -6357,6 +6357,14 @@ static void test_template_output_peg_parsers(bool detailed_debug) { .expect(message_assist) .run(); + // A tool call as the first message of the turn: "<|start|>assistant" is the + // generation prompt, so the output starts at " to=". + tst.test(" to=special_function<|message|>" + call_markup) + .tools({ special_function_tool }) + .reasoning_format(COMMON_REASONING_FORMAT_AUTO) + .expect(message_assist_call) + .run(); + // "Inform then act": the model answers the user and calls a tool in ONE generation, // closing the answer with <|eom|>. The answer must stop there rather than swallow it. tst.test(" to=user<|message|>Hello, world!\nWhat's up?<|eom|>"