diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index d08025a..0a05eb4 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -78,3 +78,13 @@ if (NOT TARGET nlohmann_json::nlohmann_json) FetchContent_MakeAvailable(json) endif() +if (NOT TARGET fmt::fmt) + # waiting for c++26 runtime formatters be like + FetchContent_Declare(fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 10.2.1 + EXCLUDE_FROM_ALL + ) + FetchContent_MakeAvailable(fmt) +endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5bf8dc3..060d2e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,5 +48,7 @@ target_link_libraries(solanaceae_rpbot PUBLIC solanaceae_message3 solanaceae_llama-cpp-web + + fmt::fmt # TODO: switch to header only? ) diff --git a/src/solanaceae/rpbot/rpbot.cpp b/src/solanaceae/rpbot/rpbot.cpp index c71d1c3..6747365 100644 --- a/src/solanaceae/rpbot/rpbot.cpp +++ b/src/solanaceae/rpbot/rpbot.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include #include @@ -19,22 +21,8 @@ template<> void RPBot::stateTransition(const Contact3 c, const StateIdle& from, StateNext& to) { // collect promp - { // - system promp - to.prompt = system_prompt; - } - MessagePromptBuilder mpb{_cr, c, _rmm, {}}; - { // - message history - mpb.buildNameLookup(); - to.prompt += mpb.buildPromptMessageHistory(); - } - - { // - next needs the beginning of the new message - // empty rn - to.prompt += "\n"; - } - - std::cout << "prompt for next: '" << to.prompt << "'\n"; + mpb.buildNameLookup(); int64_t self {-1}; { // get set of possible usernames (even if forced, just to make sure) @@ -54,6 +42,40 @@ void RPBot::stateTransition(const Contact3 c, const StateIdle& from, StateNext& } } + if (self < 0) { + // early exit for invalid self + to.future = std::async(std::launch::async, [self]() -> int64_t { return self; }); + return; + } + + { // - system promp (needs self name etc) + if (const auto* id_comp = _cr.try_get(c); id_comp != nullptr) { + const auto id_hex = bin2hex(id_comp->data); + to.prompt = _conf.get_string("RPBot", "system_prompt", id_hex).value(); + } else { + to.prompt = _conf.get_string("RPBot", "system_prompt").value(); + } + + to.prompt = fmt::format(fmt::runtime(to.prompt), + fmt::arg("self_name", to.possible_names.at(self)) + //fmt::arg("chat_name", "test_group"), + //fmt::arg("chat_type", "Group") + //fmt::arg("chat_topic", "Group") + // current online? + // current date? + ); + } + + // - message history + to.prompt += mpb.buildPromptMessageHistory(); + + { // - next needs the beginning of the new message + // empty rn + to.prompt += "\n"; + } + + std::cout << "prompt for next: '" << to.prompt << "'\n"; + if (!from.force) { // launch async // copy names for string view param (lol) std::vector pnames; @@ -107,25 +129,17 @@ RPBot::RPBot( ) : _completion(completion), _conf(conf), _cr(cr), _rmm(rmm), _mcd(mcd) { //system_prompt = R"sys(Transcript of a group chat, where Bob talks to online strangers. //)sys"; - // TODO: name is chat specific, leave system prompt a template - std::string self_name {"Bob"}; - if (_conf.has_string("tox", "name")) { - self_name = _conf.get_string("tox", "name").value(); + + // set default system prompt + if (!_conf.has_string("RPBot", "system_prompt")) { + _conf.set("RPBot", "system_prompt", std::string_view{ +R"sys(Transcript of a group chat, where {self_name} talks to online strangers. +{self_name} is creative and curious. {self_name} is writing with precision, but also with occasional typos. +)sys" + }); } -#if 1 - system_prompt = "Transcript of a group chat, where "; - system_prompt += self_name; - system_prompt += " talks to online strangers. "; - system_prompt += self_name; - system_prompt += " is creative and curious. "; - system_prompt += self_name; - system_prompt += " is precise in its writing, but with occasional typos."; -#else -#include "./test_system_prompt1.inl" -#endif - - system_prompt += "\n"; // last entry + assert(_conf.has_string("RPBot", "system_prompt")); registerCommands(); } diff --git a/src/solanaceae/rpbot/rpbot.hpp b/src/solanaceae/rpbot/rpbot.hpp index 594edd4..6b6a8de 100644 --- a/src/solanaceae/rpbot/rpbot.hpp +++ b/src/solanaceae/rpbot/rpbot.hpp @@ -25,8 +25,6 @@ struct RPBot { std::minstd_rand _rng{std::random_device{}()}; - std::string system_prompt; - public: RPBot( TextCompletionI& completion,