mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-06-28 04:30:15 -05:00
Merge pull request #1958 from ikawrakow/ik/handle_think_no_space
This commit is contained in:
commit
5f917a64b3
@ -785,7 +785,22 @@ common_peg_parser common_chat_peg_builder::prefix(const std::string & s, const s
|
|||||||
if (delimiter.empty()) {
|
if (delimiter.empty()) {
|
||||||
return literal(s);
|
return literal(s);
|
||||||
}
|
}
|
||||||
return literal(s.substr(0, s.rfind(delimiter)));
|
auto pos = s.rfind(delimiter);
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
// The generation prompt may force-open the reasoning block without the
|
||||||
|
// whitespace that surrounds the detected tag (e.g. a prompt ending in
|
||||||
|
// '<think>' while history renders '<think>\n'). Only strip when the
|
||||||
|
// prompt ends exactly with the trimmed tag, so prompts with trailing
|
||||||
|
// whitespace after the tag (e.g. '<think>\n') keep their behavior.
|
||||||
|
if (auto b = delimiter.find_first_not_of(" \t\n\r"); b != std::string::npos) {
|
||||||
|
auto e = delimiter.find_last_not_of (" \t\n\r");
|
||||||
|
auto trimmed = delimiter.substr(b, e - b + 1);
|
||||||
|
if (s.size() >= trimmed.size() && s.compare(s.size() - trimmed.size(), trimmed.size(), trimmed) == 0) {
|
||||||
|
pos = s.size() - trimmed.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return literal(s.substr(0, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
common_peg_parser common_chat_peg_builder::optspace(const std::string & tag) {
|
common_peg_parser common_chat_peg_builder::optspace(const std::string & tag) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user