From f8c0b474ec0a2003e2636a1f7ff5b5a05bdc9f5d Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Tue, 14 May 2024 21:34:53 +0530 Subject: [PATCH] ChatON+:RenameTo chaton_meta_load_json to match semantic Also add simple note wrt itself and its helper. --- common/chaton.hpp | 6 +++++- examples/main/main.cpp | 2 +- tests/test-chat-template-chaton.cpp | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/chaton.hpp b/common/chaton.hpp index b7132e61d..cc8380d5a 100644 --- a/common/chaton.hpp +++ b/common/chaton.hpp @@ -515,11 +515,14 @@ public: }; +// The compiled-in configurable template data (the meta) #include "chaton_meta.hpp" //ChatTemplates gCT = {{}}; #ifdef CHATON_JSON +// Get value corresponding to the specified hierarchy/chain of keys. +// Also throw a more informative exception, if it is not found. template inline SupportedType json_get(json &j, const std::vector &keys, const std::string &msgTag) { json curJ = j; @@ -540,7 +543,8 @@ inline SupportedType json_get(json &j, const std::vector &keys return curJ; } -inline bool chaton_meta_load(const std::string &fname) { +// Update/Extend the compiled-in configurable template data (the meta) from the specified json file. +inline bool chaton_meta_load_json(const std::string &fname) { std::ifstream f(fname); json conMeta = json::parse(f); for(auto it=conMeta.begin(); it != conMeta.end(); ++it) { diff --git a/examples/main/main.cpp b/examples/main/main.cpp index f86592fc7..39fdcdc54 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -144,7 +144,7 @@ int main(int argc, char ** argv) { if (params.chaton) { if (!params.chaton_meta_json.empty()) { - chaton_meta_load(params.chaton_meta_json); + chaton_meta_load_json(params.chaton_meta_json); } if (!chaton_meta_ok(params.chaton_template_id)) { exit(1); diff --git a/tests/test-chat-template-chaton.cpp b/tests/test-chat-template-chaton.cpp index ce65cc31e..e14266ad5 100644 --- a/tests/test-chat-template-chaton.cpp +++ b/tests/test-chat-template-chaton.cpp @@ -116,7 +116,7 @@ static void check_chaton(std::string &metaJson) { std::vector formatted_chat(1024); int32_t res; - chaton_meta_load(metaJson); + chaton_meta_load_json(metaJson); for(auto tmplId: templateIds) { formatted_chat.resize(1024); std::cout << "\n----------" << tmplId << "---------------\n"; @@ -137,7 +137,7 @@ static void check_chaton_ex(std::string &metaJson) { std::vector formatted_chat(1024); int32_t res; - chaton_meta_load(metaJson); + chaton_meta_load_json(metaJson); for(auto tmplId: templateIds) { formatted_chat.resize(1024); std::cout << "\n----------" << tmplId << "---------------\n";