From 7b5fb0a2fa2f1df3422b7a8cea83bd8b418f5dea Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sun, 12 May 2024 13:06:22 +0530 Subject: [PATCH] ChatON:P3:meta json to hpp: Retain esc seqs and more kv pairs Use repr to retain the escape sequences in the read string. And parallely skip the single quote around strings wrt repr. Bring in more k-v pairs wrt chaton_meta.json --- scripts/chaton-meta-json-to-hpp.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/chaton-meta-json-to-hpp.py b/scripts/chaton-meta-json-to-hpp.py index a5e68d823..2ee0a065a 100755 --- a/scripts/chaton-meta-json-to-hpp.py +++ b/scripts/chaton-meta-json-to-hpp.py @@ -7,15 +7,31 @@ import json def kv(j, tmpl, k1, k2, comma): - print("\t\t{{ \"{}\", \"{}\" }}{}".format("{}-{}".format(k1,k2), j[tmpl][k1][k2], comma)) + print("\t\t{{ \"{}\", \"{}\" }}{}".format("{}-{}".format(k1,k2), repr(j[tmpl][k1][k2])[1:-1], comma)) fp=open(sys.argv[1]) j=json.load(fp) print("{") for tmpl in j: - print("\t{{ \"{}\", {{".format(tmpl)) - kv(j, tmpl, "global", "begin", ",") - kv(j, tmpl, "global", "end", ",") - print("\t}},") - + print("\t{{ \"{}\", {{".format(tmpl)) + + kv(j, tmpl, "global", "begin", ",") + kv(j, tmpl, "global", "end", ",") + + kv(j, tmpl, "system", "begin", ",") + kv(j, tmpl, "system", "prefix", ",") + kv(j, tmpl, "system", "suffix", ",") + kv(j, tmpl, "system", "end", ",") + + kv(j, tmpl, "user", "begin", ",") + kv(j, tmpl, "user", "prefix", ",") + kv(j, tmpl, "user", "suffix", ",") + kv(j, tmpl, "user", "end", ",") + + kv(j, tmpl, "assistant", "begin", ",") + kv(j, tmpl, "assistant", "prefix", ",") + kv(j, tmpl, "assistant", "suffix", ",") + kv(j, tmpl, "assistant", "end", ",") + + print("\t}},")