@@ -72,6 +72,7 @@ const auto K_SUFFIX = "suffix";
72
72
const auto K_BEGIN = " begin" ;
73
73
const auto K_END = " end" ;
74
74
const auto K_GLOBAL = " global" ;
75
+ const auto K_SYSTEMUSER_1ST_USER_HAS_BEGIN = " systemuser-1st-user-has-begin" ;
75
76
const auto K_SYSTEMUSER_1ST_USER_HAS_PREFIX = " systemuser-1st-user-has-prefix" ;
76
77
const auto K_REVERSE_PROMPT = " reverse-prompt" ;
77
78
@@ -91,7 +92,10 @@ inline bool chaton_meta_load(std::string &fname) {
91
92
// NOTE: This currently doesnt return about which parts of the tagged message contain tags and which parts the user message
92
93
inline std::string chaton_tmpl_apply_single (const std::string &tmpl, const std::string &role, const std::string &content) {
93
94
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;
95
99
std::string taggedStr = ss.str ();
96
100
LOGLN (" DBUG:%s:%s:%s:%s" , __func__, tmpl.c_str (), role.c_str (), taggedStr.c_str ());
97
101
return taggedStr;
@@ -110,22 +114,26 @@ inline std::string chaton_tmpl_apply(const std::string &tmpl, const std::vector<
110
114
for (const auto msg: msgs) {
111
115
auto role = msg.role ;
112
116
auto content = msg.content ;
117
+ auto begin = conMeta[tmpl][role][K_BEGIN];
113
118
auto prefix = conMeta[tmpl][role][K_PREFIX];
114
119
if (role == K_SYSTEM) {
115
120
cntSystem += 1 ;
116
- ss << prefix;
121
+ ss << begin << prefix;
117
122
} else if (role == K_USER) {
118
123
cntUser += 1 ;
119
124
if ((cntSystem == 1 ) && (cntUser == 1 )) {
125
+ if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_BEGIN]) {
126
+ ss << begin;
127
+ }
120
128
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_PREFIX]) {
121
129
ss << prefix;
122
130
}
123
131
} else {
124
- ss << prefix;
132
+ ss << begin << prefix;
125
133
}
126
134
} else {
127
135
cntOthers += 1 ;
128
- ss << prefix;
136
+ ss << begin << prefix;
129
137
}
130
138
ss << content << conMeta[tmpl][role][K_SUFFIX];
131
139
}
@@ -173,6 +181,7 @@ inline void _chaton_meta_dump(std::string &tmpl) {
173
181
LOGXLN (" INFO:%s:%s:%s" , __func__, " global->end" , chaton_tmpl_role_kv (tmpl, K_GLOBAL, K_END).c_str ());
174
182
LOGXLN (" INFO:%s:%s:%s" , __func__, " system->prefix" , chaton_tmpl_role_kv (tmpl, K_SYSTEM, K_PREFIX).c_str ());
175
183
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 ());
176
185
LOGXLN (" INFO:%s:%s:%s" , __func__, " user->prefix" , chaton_tmpl_role_kv (tmpl, K_USER, K_PREFIX).c_str ());
177
186
LOGXLN (" INFO:%s:%s:%s" , __func__, " user->suffix" , chaton_tmpl_role_kv (tmpl, K_USER, K_SUFFIX).c_str ());
178
187
LOGXLN (" INFO:%s:%s:%s" , __func__, " assistant->prefix" , chaton_tmpl_role_kv (tmpl, K_ASSISTANT, K_PREFIX).c_str ());
0 commit comments