refactor and prep rpbot
This commit is contained in:
@ -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
|
||||
)
|
||||
|
||||
|
@ -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 {};
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
12
src/solanaceae/rpbot/rpbot.cpp
Normal file
12
src/solanaceae/rpbot/rpbot.cpp
Normal 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;
|
||||
}
|
||||
|
18
src/solanaceae/rpbot/rpbot.hpp
Normal file
18
src/solanaceae/rpbot/rpbot.hpp
Normal 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);
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user