make llama server configurable

This commit is contained in:
Green Sky 2024-01-26 15:47:02 +01:00
parent 06eca937bf
commit 2aea0bbdac
No known key found for this signature in database
4 changed files with 20 additions and 5 deletions

View File

@ -28,11 +28,11 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
} }
try { try {
//auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
// static store, could be anywhere tho // static store, could be anywhere tho
// construct with fetched dependencies // construct with fetched dependencies
g_lcw = std::make_unique<LlamaCppWeb>(); g_lcw = std::make_unique<LlamaCppWeb>(*conf);
// register types // register types
PLUG_PROVIDE_INSTANCE(LlamaCppWeb, plugin_name, g_lcw.get()); PLUG_PROVIDE_INSTANCE(LlamaCppWeb, plugin_name, g_lcw.get());

View File

@ -18,6 +18,11 @@ static std::string convertToSafeGrammarString(std::string_view input) {
return res; return res;
} }
LlamaCppWeb::LlamaCppWeb(
ConfigModelI& conf
) : _conf(conf), _cli(_conf.get_string("LlamaCppWeb", "server").value_or("localhost:8080")) {
}
LlamaCppWeb::~LlamaCppWeb(void) { LlamaCppWeb::~LlamaCppWeb(void) {
} }

View File

@ -2,6 +2,8 @@
#include "./text_completion_interface.hpp" #include "./text_completion_interface.hpp"
#include <solanaceae/util/config_model.hpp>
#include <httplib.h> #include <httplib.h>
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
@ -9,14 +11,19 @@
#include <atomic> #include <atomic>
struct LlamaCppWeb : public TextCompletionI { struct LlamaCppWeb : public TextCompletionI {
// this mutex locks internally ConfigModelI& _conf;
httplib::Client _cli{"http://localhost:8080"};
// this mutex-locks internally
httplib::Client _cli;
// this is a bad idea // this is a bad idea
static std::minstd_rand thread_local _rng; static std::minstd_rand thread_local _rng;
std::atomic<bool> _use_server_cache {true}; std::atomic<bool> _use_server_cache {true};
LlamaCppWeb(
ConfigModelI& conf
);
~LlamaCppWeb(void); ~LlamaCppWeb(void);
bool isGood(void) override; bool isGood(void) override;

View File

@ -1,5 +1,7 @@
#include <solanaceae/llama-cpp-web/llama_cpp_web_impl.hpp> #include <solanaceae/llama-cpp-web/llama_cpp_web_impl.hpp>
#include <solanaceae/util/simple_config_model.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <iostream> #include <iostream>
@ -9,7 +11,8 @@
#include <cstdint> #include <cstdint>
int main(void) { int main(void) {
LlamaCppWeb lcw; SimpleConfigModel scm;
LlamaCppWeb lcw{scm};
if (!lcw.isGood()) { if (!lcw.isGood()) {
std::cerr << lcw._cli.host() << " " << lcw._cli.port() << " endpoint not healthy\n"; std::cerr << lcw._cli.host() << " " << lcw._cli.port() << " endpoint not healthy\n";