Commit Graph

73 Commits

Author SHA1 Message Date
HanishKVC eb7554ca3b ChatON: Avoid -> to match simpcfg as well as corresponding keys 2024-05-13 10:37:14 +05:30
HanishKVC db2ffabb18 ChatON: use templated json_get when loading bool key-value fields
With this now even loading chaton_meta.json file will generate
more informative exception, so that user can know which field
is missing, if any.
2024-05-12 18:26:58 +05:30
HanishKVC 470b8885f3 ChatON: Switch to templated json_get for str/bool/etal 2024-05-12 18:19:18 +05:30
HanishKVC 0249c07e6b ChatON:Switch to json_get_str to help identify missing keys better
The json library generates less informative exception message,
which doesnt help one identify which key is missing, so switch to
the new json_get_str helper added in the last commit. It generates
more informative exception message.
2024-05-12 17:44:13 +05:30
HanishKVC 4eae05a6b7 ChatON: json access helper which raises exception if key missing 2024-05-12 17:34:04 +05:30
HanishKVC f94fed92d3 ChatON+MetaHpp: Had forgotten to conv reverse-prompt
Also has dump was using get_value calls with fallback to default,
so it wasnt identifying the missed field.

Have fixed both of those. Also reconverted meta json file.

Misc: interesting avesham and aattam
2024-05-12 16:20:28 +05:30
HanishKVC a3285e8e25 ChatON:Include auto converted ChatONMeta.hpp chat template data
This should allow for using this generic chat templating code flow
along with the included chat template data, without needing to
load any json file at runtime.

However If user wants to change the already included chat template
data, or add new chat template standard/model related data, one can
explicitly load json file.

TODO: Need to cross check this flow once, but logically should work
2024-05-12 14:08:09 +05:30
HanishKVC 1574201f71 ChatON:LoadJSon:ChatTemplates: revPrompt, system-user flags
WIP:NOTE:

Initial go converting from json driven flow to ChatTemplatesGroupKV
related flow done. Needs to be tested.

A optional helper added to load ChatTemplates from a specified
json file.

Need to add a compile time initialized MapOfMapOfVariants wrt
the chat template details of models/standards already known
to the program. So that one can use the llama.cpp and this new
chat template logic, even without json dependency, if one doesnt
want to.
2024-05-12 01:45:19 +05:30
HanishKVC 444d2ccf9c ChatON:LoadJSON: ChatTemplates - global/system/user/assistant
Manually iterate the json object items using begin-end explicitly,
because the implicit iteration for loop related helpers for the
used json lib gives only the values and not a key-value pair.
2024-05-12 01:35:31 +05:30
HanishKVC 2efc09f2d0 ChatON: Unnecessarily indirect nlohmann json
code used for exploring/testing commited just for future reference
2024-05-12 00:42:17 +05:30
HanishKVC b944d04d08 ChatON: Add constructor for ChatTemplates which chains into GKV 2024-05-11 23:42:08 +05:30
HanishKVC 4a9a6ce256 ChatON: ChatONMetaDump switch to GKV/ChatTemplates based flow 2024-05-11 22:53:45 +05:30
HanishKVC e999934e91 ChatON:WIP: initial go at GroupKV based flow, instead of json 2024-05-11 19:41:58 +05:30
HanishKVC 1f9a0eb8ce ChatON: Remove unneeded iostream 2024-05-10 21:10:44 +05:30
HanishKVC 8fe8231313 ChatON:SubPartsAwareTokenizePath: Allow extract subparts testing 2024-05-08 19:51:57 +05:30
HanishKVC a49697b488 ChatON: Keep compiler happy simbly 2024-05-08 19:22:46 +05:30
HanishKVC 868ab608f0 ChatON: Add forceParseSpecial flag to subparts aware tokenizing 2024-05-08 18:42:22 +05:30
HanishKVC b6da7d9c9d ChatON: tokenize keeping in mind the taggedMessage subparts
Initial go
2024-05-08 18:38:07 +05:30
HanishKVC 8dfa31bb91 ChatON: Make c-api wrappers a bit robust incl some cross checks
If the tagged message will be of 0 length, ensure that the passed
dest char* array, has null inserted appropriately.

Check that user has passed a non-null pNumParts.

Dont hard code int32_t size, pick using sizeof
2024-05-08 17:05:45 +05:30
HanishKVC 76791bad63 ChatON:Fix partsLengths to int32_t type, instead of int
so that the size of the elements is explicit and fixed, so that
it is inturn in sync with the fixed int size specified wrt the
c-api, even with any c compilers with different idea about int.

avoid some ununsed vars, need to update compile flags later to
enable corresponding warnings.
2024-05-07 12:40:49 +05:30
HanishKVC b3a56545d6 ChatON:Reposition alertAssistantAtEnd flag for consistency 2024-05-07 11:49:43 +05:30
HanishKVC 0852f3b7ec ChatON:ExCApi: Rename for consistency 2024-05-07 11:46:40 +05:30
HanishKVC 43a3a91b03 ChatON: Cleanup/Refine initial go at tmpl_apply_ex_capi 2024-05-07 11:44:25 +05:30
HanishKVC 7c288d3dfc ChatON: Rename to partstypes for consistency 2024-05-07 11:32:20 +05:30
HanishKVC 04b4a15177 ChatON: Initial go at chat-template-apply c-api with parts info 2024-05-07 11:08:47 +05:30
HanishKVC f6a86cd209 ChatON: Update the Note a bit 2024-05-07 10:29:16 +05:30
HanishKVC 2b14bcaddb SimpCfg:ChatON: add by Humans for All note 2024-05-06 11:27:56 +05:30
HanishKVC a09571318a ChatON: meta-dump returns flag inturn returned by meta-ok
test-chat-template-chaton now tries to check if meta-ok is ok wrt
the template-id being looked into.

Log template-id info also, where it was previously missed out.
2024-05-06 11:27:56 +05:30
HanishKVC af9a0a211b ChatON:ChatTmplApply: Avoid the stringstream 2024-05-06 11:27:56 +05:30
HanishKVC 889a45ff28 ChatON:ChatTmplApply:Update the function notes 2024-05-06 11:27:56 +05:30
HanishKVC ff5f68826b ChatON:ChatTmplApplySingle: Avoid streamstring, update func notes 2024-05-06 11:27:56 +05:30
HanishKVC 32e672c5dd ChatON: Dont log final tagged message string to screen 2024-05-06 11:27:56 +05:30
HanishKVC cad50c527e ChatON: Update the note to match current logic 2024-05-06 11:27:56 +05:30
HanishKVC a4b3285034 ChatON:Show Log on screen when template is applied 2024-05-06 11:27:56 +05:30
HanishKVC 58e1ff16bc ChatON: switch to ordered_json from json library
to be in sync with the json namespace in server.
2024-05-06 11:27:56 +05:30
HanishKVC a630564c48 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.
2024-05-06 11:27:56 +05:30
HanishKVC 308d3bf3ff ChatON:WIP:Add c api wrapper for chat_template_apply
Initial skeletons

Update existing logics to help with same. Also the inbetween helper
was having a bad signature wrt returning status and data, thats also
fixed.
2024-05-06 11:27:56 +05:30
HanishKVC e62699f923 ChatON: Add alertAssistantAtEnd flag & logic wrt MultiMsgs Apply
While sending the current chat session along with new user query
to the model, many models expect that a tag be added at the end
to indicate that user is expecting the model to respond, this
flags allows for the same.
2024-05-06 11:27:56 +05:30
HanishKVC ea3a0f19cc ChatON: Rather check for tmpl existance in single_ex 2024-05-06 11:27:56 +05:30
HanishKVC 01c8db70f7 ChatON+Main: Add C_API wrapper for single
Add a c api wrapper for a single message tagging scenario.

Inturn to match convention followed by existing chat_apply_template
code, make it return the size expected of the tagged message string
buffer. Update internal single logic to help with same.

Explicitly check if tmpl specified is available in the loaded json
or not and then return a error if not found.
2024-05-06 11:27:56 +05:30
HanishKVC 13857f29d6 ChatON+Main: Updates wrt detailed meta json
Fix a oversight wrt key name.

Add a alert in case if passed meta json file contains begin(BoS)
wrt assistant role, similar to check for end (EoS) wrt user role.
Bcas normally both (ie EoS wrt User and BoS wrt Assistant) shouldnt
be needed.

Update main wrt begin & prefix and suffix & end addition.
2024-05-06 11:27:56 +05:30
HanishKVC 0cd7c62706 ChatON: Keep compiler happy
Move helpers to the begining, so can avoid adding prototype
declerations/function signatures to the begining

Get the char * wrt string data in the c++ string.
2024-05-06 11:27:56 +05:30
HanishKVC 6a0214c067 ChatON:MetaOK->MetaDump: Alert if user->end is needed or not
Because user messages dont normally need a EoS token.
2024-05-06 11:27:56 +05:30
HanishKVC 344857b6cb ChatOn:ChatOnTemplateApply: suffix,end flag based control
Also fix a oversight wrt begin, when flag based begin adding control
was introduced.

NOTE: Currently system role suffix/end conditional adding always
triggered, if 1st system prompt seen or additional system prompt
is seen.
2024-05-06 11:27:56 +05:30
HanishKVC f8ae21cec7 ChatON:ChatTemplateApplySingle: update begin+prefix, suffix+end 2024-05-06 11:27:56 +05:30
HanishKVC 5d76f08d37 ChatON: Need to explicitly specify string to use c_str 2024-05-06 11:27:56 +05:30
HanishKVC 7ba0144e42 ChatOn:chaton_tmpl_role_kv: try except to ignore missing ifany
Cas of above reason, switch to directly accessing the keys in
dump helper, which is inturn used by meta_ok check
2024-05-06 11:27:56 +05:30
HanishKVC adab5775bf ChatON: more detailed/spreadout json fields 2024-05-06 11:27:56 +05:30
HanishKVC 3f09eb5dea ChatOn: ChatTemplateApply[Ex] return tagged msgs parts detail
Now there is a simple and extended version of returning tagged
messages.

The extended version returns the tagged string, as well as the
details of the parts that make up that tagged message interms of
the type of parts and the lengths of the parts.
2024-05-06 11:27:56 +05:30
HanishKVC 825a78abaa ChatOn: ChatTemplateApplySingle[Ex] return parts detail
Now there is a simple and extended version of returning tagged
message wrt a single role and its content.

The extended version returns the tagged string, as well as the
details of the parts that make up that tagged message interms of
the type of parts and the lengths of the parts.
2024-05-06 11:27:56 +05:30