Skip to content

Commit 85c6948

Browse files
committed
ChatOn: Add begin to the mix along with prefix
Dump shows user->begin. chat-template-apply[-single] updated to work with begin and prefix TODO: need to wrap begin in a try-catch, so that irrespective of role, begin+prefix will work, irrespoective of whether that role has a begin entry or not.
1 parent 0a3fccf commit 85c6948

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

common/chaton.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const auto K_SUFFIX = "suffix";
7272
const auto K_BEGIN = "begin";
7373
const auto K_END = "end";
7474
const auto K_GLOBAL = "global";
75+
const auto K_SYSTEMUSER_1ST_USER_HAS_BEGIN = "systemuser-1st-user-has-begin";
7576
const auto K_SYSTEMUSER_1ST_USER_HAS_PREFIX = "systemuser-1st-user-has-prefix";
7677
const auto K_REVERSE_PROMPT = "reverse-prompt";
7778

@@ -91,7 +92,10 @@ inline bool chaton_meta_load(std::string &fname) {
9192
// NOTE: This currently doesnt return about which parts of the tagged message contain tags and which parts the user message
9293
inline std::string chaton_tmpl_apply_single(const std::string &tmpl, const std::string &role, const std::string &content) {
9394
std::stringstream ss;
94-
ss << conMeta[tmpl][role][K_PREFIX] << content << conMeta[tmpl][role][K_SUFFIX];
95+
std::string begin = conMeta[tmpl][role][K_BEGIN];
96+
std::string prefix = conMeta[tmpl][role][K_PREFIX];
97+
std::string suffix = conMeta[tmpl][role][K_SUFFIX];
98+
ss << begin << prefix << content << suffix;
9599
std::string taggedStr = ss.str();
96100
LOGLN("DBUG:%s:%s:%s:%s", __func__, tmpl.c_str(), role.c_str(), taggedStr.c_str());
97101
return taggedStr;
@@ -110,22 +114,26 @@ inline std::string chaton_tmpl_apply(const std::string &tmpl, const std::vector<
110114
for(const auto msg: msgs) {
111115
auto role = msg.role;
112116
auto content = msg.content;
117+
auto begin = conMeta[tmpl][role][K_BEGIN];
113118
auto prefix = conMeta[tmpl][role][K_PREFIX];
114119
if (role == K_SYSTEM) {
115120
cntSystem += 1;
116-
ss << prefix;
121+
ss << begin << prefix;
117122
} else if (role == K_USER) {
118123
cntUser += 1;
119124
if ((cntSystem == 1) && (cntUser == 1)) {
125+
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_BEGIN]) {
126+
ss << begin;
127+
}
120128
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_PREFIX]) {
121129
ss << prefix;
122130
}
123131
} else {
124-
ss << prefix;
132+
ss << begin << prefix;
125133
}
126134
} else {
127135
cntOthers += 1;
128-
ss << prefix;
136+
ss << begin << prefix;
129137
}
130138
ss << content << conMeta[tmpl][role][K_SUFFIX];
131139
}
@@ -173,6 +181,7 @@ inline void _chaton_meta_dump(std::string &tmpl) {
173181
LOGXLN("INFO:%s:%s:%s", __func__, "global->end", chaton_tmpl_role_kv(tmpl, K_GLOBAL, K_END).c_str());
174182
LOGXLN("INFO:%s:%s:%s", __func__, "system->prefix", chaton_tmpl_role_kv(tmpl, K_SYSTEM, K_PREFIX).c_str());
175183
LOGXLN("INFO:%s:%s:%s", __func__, "system->suffix", chaton_tmpl_role_kv(tmpl, K_SYSTEM, K_SUFFIX).c_str());
184+
LOGXLN("INFO:%s:%s:%s", __func__, "user->begin", chaton_tmpl_role_kv(tmpl, K_USER, K_BEGIN).c_str());
176185
LOGXLN("INFO:%s:%s:%s", __func__, "user->prefix", chaton_tmpl_role_kv(tmpl, K_USER, K_PREFIX).c_str());
177186
LOGXLN("INFO:%s:%s:%s", __func__, "user->suffix", chaton_tmpl_role_kv(tmpl, K_USER, K_SUFFIX).c_str());
178187
LOGXLN("INFO:%s:%s:%s", __func__, "assistant->prefix", chaton_tmpl_role_kv(tmpl, K_ASSISTANT, K_PREFIX).c_str());

0 commit comments

Comments
 (0)