1
0
Fork 0
mirror of https://gitlab.com/niansa/reaktor.git synced 2025-03-06 20:53:30 +01:00

Improved reaction response cleanup

This commit is contained in:
niansa 2023-10-27 09:38:25 +02:00
parent e32cea5f52
commit 0dbd001dcd
4 changed files with 11025 additions and 8 deletions

View file

@ -13,7 +13,9 @@ add_subdirectory(commoncpp)
option(REAKTOR_WITH_CHAT "Enable model chat" No)
add_executable(reaktor main.cpp)
add_executable(reaktor
main.cpp
unicode_emojis.h)
target_link_libraries(reaktor PRIVATE commoncpp dpp justlm colohalopp fmt)
if (REAKTOR_WITH_CHAT)
target_compile_definitions(reaktor PRIVATE REAKTOR_WITH_CHAT)

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,5 @@
#include "unicode_emojis.h"
#include <iostream>
#include <string>
#include <chrono>
@ -251,7 +253,7 @@ void run(const std::string& token, const std::string& model_path, const std::str
exit(74);
}
// Move to another thread
thread.enqueue([=, &chatModel, &bot, &genCtx, &rng] () {
thread.enqueue([=, &chatModel, &bot, &genCtx, &rng/*no mutex needed*/] () {
auto msg = event.msg;
bool ok;
// Check if mentioned and resolve mentions
@ -314,12 +316,26 @@ void run(const std::string& token, const std::string& model_path, const std::str
// Stop if emoji is done
return !fres;
});
halo.stop();
halo.success("Response generated: "+result);
// Add emoji to message
bot.message_add_reaction(event.msg, result, [&last_reaction_timer] (const dpp::confirmation_callback_t& ccb) {
if (!ccb.is_error()) last_reaction_timer.reset();
});
// Extract unicode emoji
while (!result.empty()) {
if (is_unicode_emoji(result))
break;
result.pop_back();
}
// Check that there is anything left
if (result.empty()) {
// Nope, it went wrong
halo.stop();
halo.warning("Got an invalid response, discarding");
} else {
// We got it!
halo.stop();
halo.success("Response generated: "+result);
// Add emoji to message
bot.message_add_reaction(event.msg, result, [&last_reaction_timer] (const dpp::confirmation_callback_t& ccb) {
if (!ccb.is_error()) last_reaction_timer.reset();
});
}
// Finalize model
reactionModel->restore_savestate(sv);
});

5516
unicode_emojis.h Normal file

File diff suppressed because it is too large Load diff