1
0
Fork 0
mirror of https://gitlab.com/niansa/libjustchat.git synced 2025-03-06 20:48:31 +01:00
libjustchat/examples/cli.cpp
2023-06-10 13:36:32 +02:00

34 lines
936 B
C++

#include <iostream>
#include <string>
#include <justchat/chat.hpp>
int main(int argc, char **argv) {
// Check usage
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <model config path>" << std::endl;
return EXIT_FAILURE;
}
// Get args
const auto model_config = argv[1];
// Construct chat model
LM::Chat::Inference model(model_config);
if (!model.start()) {
std::cerr << "Failed to load model." << std::endl;
return EXIT_FAILURE;
}
std::string instruction;
for (;;) {
std::cout << "> ";
std::getline(std::cin, instruction);
model.prompt(instruction, [] (auto token) {
std::cout << token << std::flush;
return true;
}, [] (float progress, bool) {
std::cout << ' ' << unsigned(progress) << "% \r" << std::flush;
return true;
});
std::cout << '\n';
}
}