ChatOn:ChatOnTemplateApply: suffix,end flag based control
Also fix a oversight wrt begin, when flag based begin adding control was introduced. NOTE: Currently system role suffix/end conditional adding always triggered, if 1st system prompt seen or additional system prompt is seen.
This commit is contained in:
parent
f8ae21cec7
commit
344857b6cb
1 changed files with 25 additions and 14 deletions
|
@ -223,22 +223,19 @@ inline bool chaton_tmpl_apply_ex(
|
||||||
) {
|
) {
|
||||||
ChatParts cp = {};
|
ChatParts cp = {};
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << conMeta[tmpl][K_GLOBAL][K_BEGIN];
|
std::string globalBegin = chaton_tmpl_role_kv(tmpl, K_GLOBAL, {K_BEGIN});
|
||||||
cp.add_part(ChatParts::S, conMeta[tmpl][K_GLOBAL][K_BEGIN]);
|
ss << globalBegin;
|
||||||
|
cp.add_part(ChatParts::S, globalBegin);
|
||||||
int cntSystem = 0;
|
int cntSystem = 0;
|
||||||
int cntUser = 0;
|
int cntUser = 0;
|
||||||
int cntOthers = 0;
|
int cntOthers = 0;
|
||||||
for(const auto msg: msgs) {
|
for(const auto msg: msgs) {
|
||||||
auto role = msg.role;
|
auto role = msg.role;
|
||||||
auto content = msg.content;
|
auto content = msg.content;
|
||||||
std::string begin = "";
|
std::string begin = chaton_tmpl_role_kv(tmpl, role, {K_BEGIN});
|
||||||
try {
|
auto prefix = chaton_tmpl_role_kv(tmpl, role, {K_PREFIX});
|
||||||
begin = conMeta[tmpl][role][K_BEGIN];
|
auto suffix = chaton_tmpl_role_kv(tmpl, role, {K_SUFFIX});
|
||||||
cp.add_part(ChatParts::S, begin);
|
auto end = chaton_tmpl_role_kv(tmpl, role, {K_END});
|
||||||
} catch (json::exception &err) {
|
|
||||||
|
|
||||||
}
|
|
||||||
auto prefix = conMeta[tmpl][role][K_PREFIX];
|
|
||||||
if (role == K_SYSTEM) {
|
if (role == K_SYSTEM) {
|
||||||
cntSystem += 1;
|
cntSystem += 1;
|
||||||
ss << begin << prefix;
|
ss << begin << prefix;
|
||||||
|
@ -266,12 +263,26 @@ inline bool chaton_tmpl_apply_ex(
|
||||||
cp.add_part(ChatParts::S, begin);
|
cp.add_part(ChatParts::S, begin);
|
||||||
cp.add_part(ChatParts::S, prefix);
|
cp.add_part(ChatParts::S, prefix);
|
||||||
}
|
}
|
||||||
ss << content << conMeta[tmpl][role][K_SUFFIX];
|
ss << content;
|
||||||
cp.add_part(ChatParts::N, content);
|
cp.add_part(ChatParts::N, content);
|
||||||
cp.add_part(ChatParts::S, conMeta[tmpl][role][K_SUFFIX]);
|
if (role == K_SYSTEM) {
|
||||||
|
if (chaton_tmpl_kv_bool(tmpl, K_SYSTEMUSER_SYSTEM_HAS_SUFFIX)) {
|
||||||
|
ss << suffix;
|
||||||
|
cp.add_part(ChatParts::S, suffix);
|
||||||
}
|
}
|
||||||
ss << conMeta[tmpl][K_GLOBAL][K_END];
|
if (chaton_tmpl_kv_bool(tmpl, K_SYSTEMUSER_SYSTEM_HAS_END)) {
|
||||||
cp.add_part(ChatParts::S, conMeta[tmpl][K_GLOBAL][K_END]);
|
ss << end;
|
||||||
|
cp.add_part(ChatParts::S, end);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ss << suffix << end;
|
||||||
|
cp.add_part(ChatParts::S, suffix);
|
||||||
|
cp.add_part(ChatParts::S, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto globalEnd = chaton_tmpl_role_kv(tmpl, K_GLOBAL, {K_END});
|
||||||
|
ss << globalEnd;
|
||||||
|
cp.add_part(ChatParts::S, globalEnd);
|
||||||
cp.dump();
|
cp.dump();
|
||||||
tagged = ss.str();
|
tagged = ss.str();
|
||||||
std::string cpStr = cp.str();
|
std::string cpStr = cp.str();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue