back to http.server, improved implementation

This commit is contained in:
SammCheese 2023-06-09 12:17:55 +02:00
parent 4f665cd63d
commit e6231c3055
No known key found for this signature in database
GPG key ID: 28CFE2321A140BA1
4 changed files with 196 additions and 150 deletions

View file

@ -24,9 +24,8 @@ std::string executable_path = "";
std::string lora_filename = "";
static std::string current_token = "";
static bool new_token_available = false;
static bool finished_stream = false;
bool generation_finished;
std::vector<std::string> generated_tokens;
extern "C"
{
@ -213,35 +212,17 @@ extern "C"
return gpttype_generate(inputs, output);
}
const char* new_token(int idx) {
if (generated_tokens.size() <= idx || idx < 0) return nullptr;
const char* new_token() {
if (new_token_available) {
new_token_available = false;
return current_token.c_str();
}
return nullptr;
return generated_tokens[idx].c_str();
}
bool is_locked() {
return !new_token_available;
int get_stream_count() {
return generated_tokens.size();
}
bool has_finished() {
return finished_stream;
}
// TODO: dont duplicate code
void bind_set_stream_finished(bool status) {
finished_stream = status;
return generation_finished;
}
}
void receive_current_token(std::string token) {
current_token = token;
new_token_available = true;
}
void set_stream_finished(bool status) {
finished_stream = status;
}