Skip to content

Commit c07c1ba

Browse files
committed
Strip leftover opening <think> tag
1 parent 1a4968b commit c07c1ba

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

libraries/YarpPlugins/LlamaGPT/ILLMImpl.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ namespace
3636
}).base(), s.end());
3737
}
3838

39+
std::string trim(const std::string & s)
40+
{
41+
std::string out = s;
42+
ltrim(out);
43+
rtrim(out);
44+
return out;
45+
}
46+
3947
std::regex re("\\\\boxed\\{([^}]+)\\}");
4048
}
4149

@@ -57,14 +65,12 @@ bool LlamaGPT::setPrompt(const std::string & prompt)
5765
#endif
5866
}
5967

60-
auto temp = prompt;
61-
ltrim(temp);
62-
rtrim(temp);
68+
const auto trimmed = trim(prompt);
6369

64-
if (!temp.empty())
70+
if (!trimmed.empty())
6571
{
66-
yCInfo(LLAMA) << "Setting prompt:" << temp;
67-
messages.push_back({"system", ::strdup(temp.c_str())});
72+
yCInfo(LLAMA) << "Setting prompt:" << trimmed;
73+
messages.push_back({"system", ::strdup(trimmed.c_str())});
6874
}
6975
else
7076
{
@@ -246,9 +252,12 @@ bool LlamaGPT::ask(const std::string & question, yarp::dev::LLM_Message & answer
246252

247253
if (auto index = out.find("</think>"); index != std::string::npos)
248254
{
249-
out = out.substr(index + 8);
250-
ltrim(out);
251-
rtrim(out);
255+
out = trim(out.substr(index + 8));
256+
}
257+
258+
if (auto index = out.find("<think>"); index != std::string::npos)
259+
{
260+
out = trim(out.substr(index + 7));
252261
}
253262

254263
if (std::smatch sm; std::regex_search(out, sm, re) && !sm.empty())

0 commit comments

Comments
 (0)