Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions test/integration/thinking_budget_grammar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,49 @@ thought-text ::= [^d]*
);
}
});

// A lazy grammar is dormant until its trigger, so a budget that leaves it
// applied through the thought would lock the reasoning onto its root.
test('a lazy grammar stays paused through a spent thinking budget even when '
'its root takes the thought', () async {
for (final root in ['think-body', 'seed-thought']) {
final grammar =
'root ::= $root "ok"\n'
'$root ::= [^<]* "</think>"\n';

for (final budget in [1, 3]) {
final chunks = await backend
.generate(
context,
prompt,
GenerationParams(
maxTokens: 48,
temp: 0,
seed: 1,
penalty: 1,
grammar: grammar,
grammarLazy: true,
grammarTriggers: const [
GenerationGrammarTrigger.typed(
type: GrammarTriggerType.word,
value: ' a',
),
],
thinkingBudget: ThinkingBudget(
maxTokens: budget,
startTag: '<think>',
endTag: '</think>',
),
),
)
.toList();

expect(
utf8.decode(chunks.expand((chunk) => chunk).toList()),
isNot(endsWith('</think>ok')),
reason: '$root, budget $budget',
);
}
}
});
}
4 changes: 3 additions & 1 deletion test/unit/core/template/handlers/seed_oss_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ void main() {
expect(
grammar.accepts(
'<seed:think>Plan ${budget.forcedMessage}${budget.endTag}'
'<seed:tool_call>\n<function=get_weather>\n</function>',
'<seed:tool_call>\n<function=get_time>\n'
'<parameter=location>\nParis\n</parameter>\n'
'</function>\n</seed:tool_call>',
),
isFalse,
);
Expand Down
Loading