mirror of
https://gitlab.com/niansa/anyproc.git
synced 2025-03-06 20:49:24 +01:00
Updated justlm
This commit is contained in:
parent
4fbba2dc6e
commit
a274099720
2 changed files with 19 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
#define ANYPROC_HPP
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
#include <justlm.hpp>
|
||||
|
@ -88,6 +89,17 @@ public:
|
|||
buffer += response;
|
||||
if (!response.empty()) buffer += "\n";
|
||||
}
|
||||
|
||||
void create_savestate(Savestate &sv, const std::function<bool (float)> &on_append_tick = nullptr) {
|
||||
if (!buffer.empty()) {
|
||||
append(buffer, on_append_tick);
|
||||
buffer.clear();
|
||||
}
|
||||
LM::Inference::create_savestate(sv);
|
||||
}
|
||||
void restore_savestate(const Savestate &sv) {
|
||||
LM::Inference::restore_savestate(sv);
|
||||
}
|
||||
};
|
||||
|
||||
class Dictionary : PyEval {
|
||||
|
@ -129,6 +141,8 @@ public:
|
|||
};
|
||||
|
||||
class Translator : PyEval {
|
||||
LM::Inference::Savestate sv;
|
||||
|
||||
static inline LM::Inference::Params get_params() {
|
||||
auto p = get_recommended_params();
|
||||
p.top_k = 5;
|
||||
|
@ -173,8 +187,11 @@ public:
|
|||
}
|
||||
|
||||
std::string translate(std::string_view text, std::string_view language, const std::function<bool (float)> &on_append_tick = nullptr, const std::function<bool (const char *generated)>& on_generation_tick = nullptr) {
|
||||
return unescape(begin().expression(translation_exprgen(escape(text), escape(language)))
|
||||
if (sv.is_valid()) restore_savestate(sv);
|
||||
else create_savestate(sv, on_append_tick);
|
||||
auto fres = unescape(begin().expression(translation_exprgen(escape(text), escape(language)))
|
||||
.run(on_append_tick, on_generation_tick));
|
||||
return fres;
|
||||
}
|
||||
};
|
||||
#endif // ANYPROC_HPP
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 2d97e7b2bd0db84823687f8bd61a94e583f8a792
|
||||
Subproject commit f57a729853c3f65ebd3e88c5b097f908961c55fe
|
Loading…
Add table
Reference in a new issue