Skip to content

Commit 6f6f697

Browse files
committed
ChatOn: Wrap getting begin in try-catch,
so that even if a role doesnt contain begin, the logic will work fine.
1 parent 85c6948 commit 6f6f697

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

common/chaton.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ inline bool chaton_meta_load(std::string &fname) {
9292
// NOTE: This currently doesnt return about which parts of the tagged message contain tags and which parts the user message
9393
inline std::string chaton_tmpl_apply_single(const std::string &tmpl, const std::string &role, const std::string &content) {
9494
std::stringstream ss;
95-
std::string begin = conMeta[tmpl][role][K_BEGIN];
95+
std::string begin = "";
96+
try {
97+
begin = conMeta[tmpl][role][K_BEGIN];
98+
} catch (json::exception &err) {
99+
100+
}
96101
std::string prefix = conMeta[tmpl][role][K_PREFIX];
97102
std::string suffix = conMeta[tmpl][role][K_SUFFIX];
98103
ss << begin << prefix << content << suffix;
@@ -114,7 +119,12 @@ inline std::string chaton_tmpl_apply(const std::string &tmpl, const std::vector<
114119
for(const auto msg: msgs) {
115120
auto role = msg.role;
116121
auto content = msg.content;
117-
auto begin = conMeta[tmpl][role][K_BEGIN];
122+
std::string begin = "";
123+
try {
124+
begin = conMeta[tmpl][role][K_BEGIN];
125+
} catch (json::exception &err) {
126+
127+
}
118128
auto prefix = conMeta[tmpl][role][K_PREFIX];
119129
if (role == K_SYSTEM) {
120130
cntSystem += 1;

0 commit comments

Comments
 (0)