@@ -188,8 +188,10 @@ inline std::string chaton_tmpl_apply_single(const std::string &tmpl, const std::
188
188
// then 1st user message will have user-prefix only if systemuser-1st-user-has-prefix is true
189
189
// NOTE: This currently doesnt return about which parts of the tagged message contain tags and which parts the user message
190
190
inline std::string chaton_tmpl_apply (const std::string &tmpl, const std::vector<llama_chat_message> &msgs) {
191
+ ChatParts cp = {};
191
192
std::stringstream ss;
192
193
ss << conMeta[tmpl][K_GLOBAL][K_BEGIN];
194
+ cp.add_part (ChatParts::S, conMeta[tmpl][K_GLOBAL][K_BEGIN]);
193
195
int cntSystem = 0 ;
194
196
int cntUser = 0 ;
195
197
int cntOthers = 0 ;
@@ -199,33 +201,51 @@ inline std::string chaton_tmpl_apply(const std::string &tmpl, const std::vector<
199
201
std::string begin = " " ;
200
202
try {
201
203
begin = conMeta[tmpl][role][K_BEGIN];
204
+ cp.add_part (ChatParts::S, begin);
202
205
} catch (json::exception &err) {
203
206
204
207
}
205
208
auto prefix = conMeta[tmpl][role][K_PREFIX];
206
209
if (role == K_SYSTEM) {
207
210
cntSystem += 1 ;
208
211
ss << begin << prefix;
212
+ cp.add_part (ChatParts::S, begin);
213
+ cp.add_part (ChatParts::S, prefix);
209
214
} else if (role == K_USER) {
210
215
cntUser += 1 ;
211
216
if ((cntSystem == 1 ) && (cntUser == 1 )) {
212
217
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_BEGIN]) {
213
218
ss << begin;
219
+ cp.add_part (ChatParts::S, begin);
214
220
}
215
221
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_PREFIX]) {
216
222
ss << prefix;
223
+ cp.add_part (ChatParts::S, prefix);
217
224
}
218
225
} else {
219
226
ss << begin << prefix;
227
+ cp.add_part (ChatParts::S, begin);
228
+ cp.add_part (ChatParts::S, prefix);
220
229
}
221
230
} else {
222
231
cntOthers += 1 ;
223
232
ss << begin << prefix;
233
+ cp.add_part (ChatParts::S, begin);
234
+ cp.add_part (ChatParts::S, prefix);
224
235
}
225
236
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]);
226
239
}
227
240
ss << conMeta[tmpl][K_GLOBAL][K_END];
241
+ cp.add_part (ChatParts::S, conMeta[tmpl][K_GLOBAL][K_END]);
242
+ cp.dump ();
228
243
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
+ }
229
249
LOGLN (" DBUG:%s:%s:%s" , __func__, tmpl.c_str (), taggedMsgs.c_str ());
230
250
LOGLN (" DBUG:%s:%s:CntSys[%d]:CntUsr[%d]:CntOthers[%d]" , __func__, tmpl.c_str (), cntSystem, cntUser, cntOthers);
231
251
return taggedMsgs;
0 commit comments