Skip to content

Commit 9626779

Browse files
committed
ChatON: Test ChatParts in chat-template-apply
1 parent 2824815 commit 9626779

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

common/chaton.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ inline std::string chaton_tmpl_apply_single(const std::string &tmpl, const std::
188188
// then 1st user message will have user-prefix only if systemuser-1st-user-has-prefix is true
189189
// NOTE: This currently doesnt return about which parts of the tagged message contain tags and which parts the user message
190190
inline std::string chaton_tmpl_apply(const std::string &tmpl, const std::vector<llama_chat_message> &msgs) {
191+
ChatParts cp = {};
191192
std::stringstream ss;
192193
ss << conMeta[tmpl][K_GLOBAL][K_BEGIN];
194+
cp.add_part(ChatParts::S, conMeta[tmpl][K_GLOBAL][K_BEGIN]);
193195
int cntSystem = 0;
194196
int cntUser = 0;
195197
int cntOthers = 0;
@@ -199,33 +201,51 @@ inline std::string chaton_tmpl_apply(const std::string &tmpl, const std::vector<
199201
std::string begin = "";
200202
try {
201203
begin = conMeta[tmpl][role][K_BEGIN];
204+
cp.add_part(ChatParts::S, begin);
202205
} catch (json::exception &err) {
203206

204207
}
205208
auto prefix = conMeta[tmpl][role][K_PREFIX];
206209
if (role == K_SYSTEM) {
207210
cntSystem += 1;
208211
ss << begin << prefix;
212+
cp.add_part(ChatParts::S, begin);
213+
cp.add_part(ChatParts::S, prefix);
209214
} else if (role == K_USER) {
210215
cntUser += 1;
211216
if ((cntSystem == 1) && (cntUser == 1)) {
212217
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_BEGIN]) {
213218
ss << begin;
219+
cp.add_part(ChatParts::S, begin);
214220
}
215221
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_PREFIX]) {
216222
ss << prefix;
223+
cp.add_part(ChatParts::S, prefix);
217224
}
218225
} else {
219226
ss << begin << prefix;
227+
cp.add_part(ChatParts::S, begin);
228+
cp.add_part(ChatParts::S, prefix);
220229
}
221230
} else {
222231
cntOthers += 1;
223232
ss << begin << prefix;
233+
cp.add_part(ChatParts::S, begin);
234+
cp.add_part(ChatParts::S, prefix);
224235
}
225236
ss << content << conMeta[tmpl][role][K_SUFFIX];
237+
cp.add_part(ChatParts::N, content);
238+
cp.add_part(ChatParts::S, conMeta[tmpl][role][K_SUFFIX]);
226239
}
227240
ss << conMeta[tmpl][K_GLOBAL][K_END];
241+
cp.add_part(ChatParts::S, conMeta[tmpl][K_GLOBAL][K_END]);
242+
cp.dump();
228243
std::string taggedMsgs = ss.str();
244+
std::string cpStr = cp.str();
245+
if (taggedMsgs != cpStr) {
246+
LOG_TEELN("DBUG:%s:Mismatch between CP[%s] and SS[%s]", __func__, cpStr.c_str(), taggedMsgs.c_str());
247+
exit(2);
248+
}
229249
LOGLN("DBUG:%s:%s:%s", __func__, tmpl.c_str(), taggedMsgs.c_str());
230250
LOGLN("DBUG:%s:%s:CntSys[%d]:CntUsr[%d]:CntOthers[%d]", __func__, tmpl.c_str(), cntSystem, cntUser, cntOthers);
231251
return taggedMsgs;

0 commit comments

Comments
 (0)