From dc56be951d63156d0dce91bc9171cd0a3fcece51 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Mon, 22 Apr 2024 20:50:17 +0530 Subject: [PATCH] ChatOn:Main: Load and dump any specified chaton meta file --- common/chaton.hpp | 30 ++++++++++++++++++++++++++++ examples/chaton_meta.json | 42 +++++++++++++++++++++++++++++++++++++++ examples/main/main.cpp | 6 ++++++ 3 files changed, 78 insertions(+) create mode 100644 examples/chaton_meta.json diff --git a/common/chaton.hpp b/common/chaton.hpp index cd3679409..a9af7a565 100644 --- a/common/chaton.hpp +++ b/common/chaton.hpp @@ -19,4 +19,34 @@ * */ +#include +#include +#include +#include +#include "log.h" + +using json = nlohmann::json; + +json conMeta; + +inline bool chaton_meta_load(std::string &fname) { + std::ifstream f(fname); + conMeta = json::parse(f); + return true; +} + +inline bool chaton_meta_ok() { + if (conMeta == nullptr) { + return false; + } + return true; +} + +inline void chaton_meta_dump() { + if (!chaton_meta_ok()) { + LOG_TEELN("ERRR:%s:ChatOn Meta: Not loaded yet...", __func__); + return; + } + LOG_TEELN("\n\nINFO:%s:ChatOn Meta\n%s", __func__, conMeta.dump(4).c_str()); +} diff --git a/examples/chaton_meta.json b/examples/chaton_meta.json new file mode 100644 index 000000000..77e4595d6 --- /dev/null +++ b/examples/chaton_meta.json @@ -0,0 +1,42 @@ + +{ + "llama2": { + "global": { + "prefix": "[INST] ", + "suffix": " [/INST]", + }, + "system": { + "prefix": " <>\n", + "suffix": "\n<>\n\n", + }, + "user": { + "prefix": "", + "suffix": "", + }, + "assistant": { + "prefix": "", + "suffix": "", + }, + "reverse-prompt": "", + }, + "llama3": { + "global": { + "prefix": "", + "suffix": "", + }, + "system": { + "prefix": "<|start_header_id|>system<|end_header_id|>\n\n", + "suffix": "<|eot_id|>\n\n", + }, + "user": { + "prefix": "<|start_header_id|>user<|end_header_id|>\n\n", + "suffix": "<|eot_id|>\n\n", + }, + "assistant": { + "prefix": "<|start_header_id|>assistant<|end_header_id|>\n\n", + "suffix": "", + }, + "reverse-prompt": "<|eot_id|>", + }, +} + diff --git a/examples/main/main.cpp b/examples/main/main.cpp index eabbc2db3..3432cb9f1 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -1,4 +1,5 @@ #include "common.h" +#include "chaton.hpp" #include "console.h" #include "llama.h" @@ -141,6 +142,11 @@ int main(int argc, char ** argv) { console::init(params.simple_io, params.use_color); atexit([]() { console::cleanup(); }); + if (params.chaton) { + chaton_meta_load(params.chaton_json); + chaton_meta_dump(); + } + if (params.logits_all) { printf("\n************\n"); printf("%s: please use the 'perplexity' tool for perplexity calculations\n", __func__);