refactor and prep rpbot

This commit is contained in:
2024-01-23 23:05:55 +01:00
parent c497b19b20
commit e504d7a8ef
10 changed files with 129 additions and 12 deletions

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
project(solanaceae)
add_library(solanaceae_llama-cpp-web
./solanaceae/llama-cpp-web/llama_cpp_web_interface.hpp
./solanaceae/llama-cpp-web/text_completion_interface.hpp
./solanaceae/llama-cpp-web/llama_cpp_web_impl.hpp
./solanaceae/llama-cpp-web/llama_cpp_web_impl.cpp
)
@ -16,7 +16,6 @@ target_link_libraries(solanaceae_llama-cpp-web PUBLIC
nlohmann_json::nlohmann_json
solanaceae_util
solanaceae_message3
)
########################################
@ -29,3 +28,20 @@ target_link_libraries(test1 PUBLIC
solanaceae_llama-cpp-web
)
########################################
add_library(solanaceae_rpbot
./solanaceae/rpbot/rpbot.hpp
./solanaceae/rpbot/rpbot.cpp
)
target_include_directories(solanaceae_rpbot PUBLIC .)
target_compile_features(solanaceae_rpbot PRIVATE cxx_std_20)
target_compile_features(solanaceae_rpbot INTERFACE cxx_std_17)
target_link_libraries(solanaceae_rpbot PUBLIC
solanaceae_util
solanaceae_message3
solanaceae_llama-cpp-web
)

View File

@ -19,7 +19,7 @@ static std::string convertToSafeGrammarString(std::string_view input) {
LlamaCppWeb::~LlamaCppWeb(void) {
}
bool LlamaCppWeb::isHealthy(void) {
bool LlamaCppWeb::isGood(void) {
auto res = _cli.Get("/health");
if (
res.error() != httplib::Error::Success ||
@ -123,7 +123,8 @@ std::string LlamaCppWeb::completeLine(const std::string_view prompt) {
}
nlohmann::json LlamaCppWeb::complete(const nlohmann::json& request_j) {
if (!isHealthy()) {
// TODO: dont check ourself
if (!isGood()) {
return {};
}

View File

@ -1,19 +1,19 @@
#pragma once
#include "./llama_cpp_web_interface.hpp"
#include "./text_completion_interface.hpp"
#include <httplib.h>
#include <nlohmann/json_fwd.hpp>
#include <random>
struct LlamaCppWeb : public LlamaCppWebI {
struct LlamaCppWeb : public TextCompletionI {
httplib::Client _cli{"http://localhost:8080"};
std::minstd_rand _rng{std::random_device{}()};
~LlamaCppWeb(void);
bool isHealthy(void) override;
bool isGood(void) override;
int64_t completeSelect(const std::string_view prompt, const std::vector<std::string_view>& possible) override;
std::string completeLine(const std::string_view prompt) override;

View File

@ -4,10 +4,10 @@
#include <string_view>
#include <vector>
struct LlamaCppWebI {
virtual ~LlamaCppWebI(void) {}
struct TextCompletionI {
virtual ~TextCompletionI(void) {}
virtual bool isHealthy(void) = 0;
virtual bool isGood(void) = 0;
// TODO: add more complex api

View File

@ -0,0 +1,12 @@
#include "./rpbot.hpp"
RPBot::RPBot(
TextCompletionI& completion,
ConfigModelI& conf
) : _completion(completion), _conf(conf) {
}
float RPBot::tick(float time_delta) {
return 10.f;
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <solanaceae/util/config_model.hpp>
#include <solanaceae/llama-cpp-web/text_completion_interface.hpp>
struct RPBot {
TextCompletionI& _completion;
ConfigModelI& _conf;
public:
RPBot(
TextCompletionI& completion,
ConfigModelI& conf
);
float tick(float time_delta);
};

View File

@ -11,7 +11,7 @@
int main(void) {
LlamaCppWeb lcw;
if (!lcw.isHealthy()) {
if (!lcw.isGood()) {
std::cerr << lcw._cli.host() << " " << lcw._cli.port() << " endpoint not healthy\n";
return 1;
}