From a630564c481d8a80950aa5234fd75e6fb050a20c Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Fri, 26 Apr 2024 09:09:41 +0530 Subject: [PATCH] ChatON:ChatTemplateApplyCAPI remaining base logic As c doesnt have the concept of pass by reference, and inturn the existing c api uses pointers wrt llama chat message structure, so switching to same wrt chat_tmpl_apply logics. Also fix a oversight in previous commit and add the remaining logic. --- common/chaton.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/common/chaton.hpp b/common/chaton.hpp index 7c31ad4dc..e072289f8 100644 --- a/common/chaton.hpp +++ b/common/chaton.hpp @@ -300,7 +300,7 @@ inline size_t chat_tmpl_apply_single_capi( // NOTE: returns types and lens to help identify the parts of the tagged msg, which relate to passed and added tags inline bool chaton_tmpl_apply_ex( const std::string &tmpl, - const std::vector &msgs, + const std::vector &msgs, std::string &tagged, std::string &types, std::vector &lens, @@ -318,8 +318,8 @@ inline bool chaton_tmpl_apply_ex( int cntUser = 0; int cntOthers = 0; for(const auto msg: msgs) { - auto role = msg.role; - auto content = msg.content; + auto role = msg->role; + auto content = msg->content; std::string begin = chaton_tmpl_role_kv(tmpl, role, {K_BEGIN}); auto prefix = chaton_tmpl_role_kv(tmpl, role, {K_PREFIX}); auto suffix = chaton_tmpl_role_kv(tmpl, role, {K_SUFFIX}); @@ -395,7 +395,7 @@ inline bool chaton_tmpl_apply_ex( // then 1st user message will have user-prefix only if systemuser-1st-user-has-prefix is true inline int32_t chaton_tmpl_apply( const std::string &tmpl, - const std::vector &msgs, + const std::vector &msgs, bool alertAssistantAtEnd, std::string &tagged ) { @@ -420,10 +420,17 @@ inline int32_t chaton_tmpl_apply_capi( } std::vector vMsgs; for(size_t i=0; i 0) { + strlcpy(dest, taggedMsgs.c_str(), destLength); + } + return taggedLength; }