Skip to content

Commit 01db429

Browse files
author
ochafik
committed
fix test-chat (update delta to latest r1 template change)
1 parent 8409bf1 commit 01db429

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/test-chat.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,24 @@ static delta_data init_delta(const common_chat_template & tmpl, const std::vecto
198198
std::string prefix = params_prefix.prompt;
199199
std::string full = params_full.prompt;
200200

201-
// Check full starts with prefix
202-
if (full.find(prefix) != 0) {
203-
fprintf(stderr, "Full:\n%s\n\nPrefix:\n%s\n\n", full.c_str(), prefix.c_str());
204-
throw std::runtime_error("Full message does not start with prefix");
205-
}
206-
207201
if (full == prefix) {
208202
throw std::runtime_error("Full message is the same as the prefix");
209203
}
210204

211-
auto delta = full.substr(prefix.size());
205+
size_t common_prefix_length = 0;
206+
for (size_t i = 0; i < prefix.size() && i < full.size(); ++i) {
207+
if (prefix[i] != full[i]) {
208+
break;
209+
}
210+
if (prefix[i] == '<') {
211+
// DeepSeek R1's template (as of 20250209) adds a trailing <think> if add_generation_prompt,
212+
// but it removes thinking tags for past messages.
213+
// The prefix and full strings diverge at <think> vs. <|tool▁calls▁begin|>, we avoid consuming the leading <.
214+
continue;
215+
}
216+
common_prefix_length = i + 1;
217+
}
218+
auto delta = full.substr(common_prefix_length);
212219

213220
// Strip end tokens
214221
for (const auto & end_token : end_tokens) {

0 commit comments

Comments
 (0)