#include #include #include #include #include #include #include using namespace sio; class lollmsClient { public: lollmsClient(const std::string& serverUrl) : connected_(false) { // Set up event listeners setupEventListeners(); std::cout<<"Built listeners"<get_map()["prompt"]=sio::string_message::create(prompt); om->get_map()["n_predicts"]=sio::int_message::create(n_predicts); client_.socket()->emit("generate_text", om); // client_.socket()->emit("generate_text", sio::object_message(*message)); } else { std::cerr << "Not connected to the server. Cannot generate text." << std::endl; } } void cancelGeneration() { if (connected_) { client_.socket()->emit("cancel_generation"); } else { std::cerr << "Not connected to the server. Cannot cancel generation." << std::endl; } } // Getter for client_ const sio::client& getClient() const { return client_; } void closeConnection() { client_.close(); // Ou utilisez une autre méthode de fermeture selon la bibliothèque sio } private: client client_; bool connected_; void setupEventListeners() { std::cout<<"Adding open listener"<on("text_chunk", [&](const sio::event& event) { sio::message::ptr message = event.get_message(); if (message->get_map().find("chunk") != message->get_map().end()) { sio::message::ptr chunkMessage = message->get_map()["chunk"]; if (chunkMessage->get_flag() == sio::message::flag_string) { std::string chunk = chunkMessage->get_string(); std::cout << chunk; // Append the chunk to the output or perform any other required actions // ... } else { std::cerr << "Received 'chunk' data is not a string." << std::endl; } } else { std::cerr << "Received event 'text_chunk' without 'chunk' data." << std::endl; } }); // Event handler for receiving generated text client_.socket()->on("text_generated", [&](const sio::event& event) { sio::message::ptr message = event.get_message(); if (message->get_map().find("text") != message->get_map().end()) { sio::message::ptr chunkMessage = message->get_map()["text"]; if (chunkMessage->get_flag() == sio::message::flag_string) { std::string chunk = chunkMessage->get_string(); std::cout << chunk; // Append the chunk to the output or perform any other required actions // ... } else { std::cerr << "Received 'text' data is not a string." << std::endl; } } else { std::cerr << "Received event 'text_generated' without 'text' data." << std::endl; } }); // Event handler for error during text generation client_.socket()->on("buzzy", [&](const sio::event& event) { const std::string error = event.get_message()->get_string(); std::cerr << "Server is busy. Wait for your turn. Error: " << error << std::endl; // Handle the error or perform any other required actions // ... }); // Event handler for generation cancellation client_.socket()->on("generation_canceled", [&](const sio::event& event) { // Toggle button visibility or perform any other required actions std::cout << "Generation canceled" << std::endl; }); } void onConnected() { std::cout << "Connected to the LoLLMs server" << std::endl; connected_ = true; // Perform actions upon successful connection // ... } void onDisconnected() { std::cout << "Disconnected from the server" << std::endl; connected_ = false; // Perform actions upon disconnection // ... } void onConnectionFailed() { std::cout << "Connection to the server failed" << std::endl; // Perform actions upon connection failure // ... } void onReconnecting(unsigned int reconnectionAttempts, unsigned int delay) { std::cout << "Reconnecting to the server (attempt " << reconnectionAttempts << ") in " << delay << " milliseconds" << std::endl; // Perform actions upon reconnection attempt // ... } void onSocketClosed() { std::cout << "Socket closed" << std::endl; connected_ = false; // Perform actions upon socket closure // ... } }; int main() { ASCIIColors::red(R"( ___ ___ ___ ___ ___ ___ )"); ASCIIColors::red(R"( /\__\ /\ \ /\__\ /\__\ /\__\ /\ \ )"); ASCIIColors::red(R"( /:/ / /::\ \ /:/ / /:/ / /::| | /::\ \ )"); ASCIIColors::red(R"( /:/ / /:/\:\ \ /:/ / /:/ / /:|:| | /:/\ \ \ )"); ASCIIColors::red(R"( /:/ / /:/ \:\ \ /:/ / /:/ / /:/|:|__|__ _\:\~\ \ \ )"); ASCIIColors::red(R"( /:/__/ /:/__/ \:\__\ /:/__/ /:/__/ /:/ |::::\__\ /\ \:\ \ \__\ )"); ASCIIColors::red(R"( \:\ \ \:\ \ /:/ / \:\ \ \:\ \ \/__/~~/:/ / \:\ \:\ \/__/ )"); ASCIIColors::red(R"( \:\ \ \:\ /:/ / \:\ \ \:\ \ /:/ / \:\ \:\__\ )"); ASCIIColors::red(R"( \:\ \ \:\/:/ / \:\ \ \:\ \ /:/ / \:\/:/ / )"); ASCIIColors::red(R"( \:\__\ \::/ / \:\__\ \:\__\ /:/ / \::/ / )"); ASCIIColors::red(R"( \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ )"); ASCIIColors::yellow("By ParisNeo"); ASCIIColors::red("Lollms c++ Client V 1.0"); // Create a lollmsClient instance and connect to the server lollmsClient client("http://localhost:9600"); std::cout<<"Created"<