now actually works

This commit is contained in:
Green Sky 2024-01-24 23:59:28 +01:00
parent 83264db09d
commit f5650475c7
No known key found for this signature in database
2 changed files with 19 additions and 5 deletions

View File

@ -121,7 +121,12 @@ std::string LlamaCppWeb::completeLine(const std::string_view prompt) {
{"stop", {"\n"}}, {"stop", {"\n"}},
}); });
return ret.dump(); if (ret.empty() || ret.count("content") == 0) {
// error
return "";
}
return ret.at("content");
} }
nlohmann::json LlamaCppWeb::complete(const nlohmann::json& request_j) { nlohmann::json LlamaCppWeb::complete(const nlohmann::json& request_j) {

View File

@ -8,6 +8,7 @@
#include <solanaceae/util/utils.hpp> #include <solanaceae/util/utils.hpp>
#include <limits> #include <limits>
#include <string_view>
#include <vector> #include <vector>
#include <atomic> #include <atomic>
#include <future> #include <future>
@ -101,7 +102,7 @@ void RPBot::stateTransition(const Contact3 c, const StateIdle& from, StateNext&
template<> template<>
void RPBot::stateTransition(const Contact3, const StateNext&, StateIdle& to) { void RPBot::stateTransition(const Contact3, const StateNext&, StateIdle& to) {
to.timeout = std::uniform_real_distribution<>{15.f, 45.f}(_rng); to.timeout = std::uniform_real_distribution<>{10.f, 45.f}(_rng);
} }
template<> template<>
@ -121,7 +122,7 @@ void RPBot::stateTransition(const Contact3 c, const StateNext& from, StateGenera
template<> template<>
void RPBot::stateTransition(const Contact3, const StateGenerateMsg&, StateIdle& to) { void RPBot::stateTransition(const Contact3, const StateGenerateMsg&, StateIdle& to) {
to.timeout = std::uniform_real_distribution<>{10.f, 30.f}(_rng); to.timeout = std::uniform_real_distribution<>{5.f, 20.f}(_rng);
} }
RPBot::RPBot( RPBot::RPBot(
@ -319,13 +320,21 @@ float RPBot::doAllGenerateMsg(float) {
std::cout << "RPBot: generatemessage compute done!\n"; std::cout << "RPBot: generatemessage compute done!\n";
std::string msg = state.future.get(); std::string msg = state.future.get();
_rmm.sendText(c, msg); if (!msg.empty()) {
std::string::size_type start_pos = 0;
if (msg.front() == ' ') {
start_pos += 1;
}
_rmm.sendText(c, std::string_view{msg}.substr(start_pos));
}
// TODO: timing check? // TODO: timing check?
// transition to Idle // transition to Idle
emplaceStateTransition<StateIdle>(_cr, c, state); emplaceStateTransition<StateIdle>(_cr, c, state);
} }
}); });
_cr.remove<StateGenerateMsg>(to_remove.cbegin(), to_remove.cend());
return min_tick_interval; return min_tick_interval;
} }