Skip to content

Commit c7d58a0

Browse files
committed
ChatON:ChatTmplApply:Update the function notes
1 parent fab249c commit c7d58a0

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

common/chaton.hpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ inline bool chaton_tmpl_kv_bool(const std::string &tmpl, const std::string &key)
325325
// a tagged message, types string and lens vector wrt the parts that make up the returned string
326326
//
327327
// * a string containing the tagged message
328-
// * user-(begin+prefix) + msg + user-(suffix+end)
328+
// * role-(begin+prefix) + msg + role-(suffix+end)
329329
// * a string where the chars contain info about
330330
// type of sub-strings/parts that make up the tagged message.
331331
// * a vector of ints, which give the length of each part in the tagged message.
@@ -357,7 +357,7 @@ inline bool chaton_tmpl_apply_single_ex(
357357
// Given the template standard, role and a message, this returns the tagged message.
358358
//
359359
// * a string containing the tagged message
360-
// * user-(begin+prefix) + msg + user-(suffix+end)
360+
// * role-(begin+prefix) + msg + role-(suffix+end)
361361
inline size_t chaton_tmpl_apply_single(
362362
const std::string &tmpl,
363363
const std::string &role,
@@ -403,10 +403,19 @@ inline size_t chat_tmpl_apply_single_capi(
403403
return taggedLength;
404404
}
405405

406-
// global-begin + [[role-begin] + [role-prefix] + msg + role-suffix] + global-end
407-
// if there is a combination of system-user messages,
408-
// then 1st user message will have user-prefix only if systemuser-1st-user-has-prefix is true
409-
// NOTE: returns types and lens to help identify the parts of the tagged msg, which relate to passed and added tags
406+
407+
// Given the template standard and a bunch of messages including their roles, this returns
408+
// tagged messages, types string and lens vector. Returned types string and lens vector help
409+
// identify the parts of the tagged msgs string, which relate to passed msgs and added tags.
410+
//
411+
// * a string containing the tagged messages
412+
// * global-begin + 1 or more [[role-begin] + [role-prefix] + msg + [role-suffix] +[role-end]] + global-end
413+
// * a string where the chars contain info about
414+
// type of sub-strings/parts that make up the tagged messages string.
415+
// * a vector of ints, which give the length of each part in the tagged messages string.
416+
//
417+
// if a combination of system-user messages is passed, then tags between the system
418+
// and the 1st user message, is based on the flags set wrt the corresponding template standard.
410419
inline bool chaton_tmpl_apply_ex(
411420
const std::string &tmpl,
412421
const std::vector<const llama_chat_message *> &msgs,
@@ -499,9 +508,9 @@ inline bool chaton_tmpl_apply_ex(
499508
return true;
500509
}
501510

502-
// global-begin + [[role-begin] + [role-prefix] + msg + role-suffix] + global-end
503-
// if there is a combination of system-user messages,
504-
// then 1st user message will have user-prefix only if systemuser-1st-user-has-prefix is true
511+
// Given the template standard and a bunch of messages including their roles, this returns
512+
// the tagged messages as a string.
513+
// global-begin + 1 or more [[role-begin] + [role-prefix] + msg + [role-suffix] +[role-end]] + global-end
505514
inline int32_t chaton_tmpl_apply(
506515
const std::string &tmpl,
507516
const std::vector<const llama_chat_message *> &msgs,
@@ -516,6 +525,18 @@ inline int32_t chaton_tmpl_apply(
516525
return tagged.size();
517526
}
518527

528+
// Given the template standard and a bunch of messages including their roles, this returns
529+
// the tagged messages as a string.
530+
// global-begin + 1 or more [[role-begin] + [role-prefix] + msg + [role-suffix] +[role-end]] + global-end
531+
//
532+
// If the passed char array is smaller than that required for the tagged messages string,
533+
// * part of the tagged messages string which fits within dest buffer is copied
534+
// * the returned value, indicates the size of the actual tagged message
535+
// NOTE:
536+
// * ideally the passed char array should be able to fit the tagged messages string + 0|null char.
537+
// * if the return value from this function is larger than or equal to destLength,
538+
// then you will have to increase the size of the dest buffer, and call this
539+
// function a second time, to ensure that one gets the full tagged messages string.
519540
inline int32_t chaton_tmpl_apply_capi(
520541
const char *tmpl,
521542
const struct llama_chat_message *msgs,

0 commit comments

Comments
 (0)