diff --git a/doc/server_endpoints.md b/doc/server_endpoints.md index 2657a1b..245fd86 100644 --- a/doc/server_endpoints.md +++ b/doc/server_endpoints.md @@ -308,3 +308,4 @@ Events generated: - `'buzzy'`: when the server is buzzy and can't process the request, it sends this event and returns. This event have parameter `message` containing a string. - `'text_chunk'`: Generated text chunks are emitted to the client through this event during the text generation process. The event has two parameters `chunk` and `type`. - `'text_generated'`: Once the text generation process is complete, the final generated text is emitted to the client through this event. The event has one parameter `text` containing the full generated text. +- `'generation_canceled'`: Answer to `cancel_generation` endpoint call diff --git a/examples/lollms_playground/README.md b/examples/lollms_playground/README.md new file mode 100644 index 0000000..a7e2dd5 --- /dev/null +++ b/examples/lollms_playground/README.md @@ -0,0 +1,79 @@ +``` +# LoLLMs Endpoint Test Tool + +This tool provides a web-based interface to test LoLLMs endpoints and generate text using a LoLLMs server. + +## Prerequisites + +To use this tool, you need to have [Node.js](https://nodejs.org) installed on your machine. + +## Installation + +1. Clone this repository or download the source code. + + ```bash + git clone https://github.com/ParisNeo/lollms-playground.git + ``` + +2. Navigate to the project directory. + + ```bash + cd socketio-endpoint-test-tool + ``` + +3. Install the dependencies. + + ```bash + npm install + ``` + +## Usage + +1. Start the LoLLMs server. You can use `lollms-server` to run the server with the desired configuration. Here are a few examples: + + - To run the server on `localhost` and port `9600`: + + ```bash + lollms-server --host localhost --port 9600 + ``` + + - To run the server on a different host and port: + + ```bash + lollms-server --host mydomain.com --port 8080 + ``` + + - For more information on the available options, you can use the `--help` flag: + + ```bash + lollms-server --help + ``` + +2. Start the web server for the LoLLMs Endpoint Test Tool. + + ```bash + npm start + ``` + +3. Open your web browser and visit `http://localhost:8080/lollms_playground.html` (or the appropriate URL) to access the LoLLMs Endpoint Test Tool. + +4. Fill in the host and port fields with the appropriate values for your LoLLMs server. + +5. Click the "Connect" button to establish a connection with the LoLLMs server. + +6. Once connected, you can enter a prompt and click the "Generate Text" button to initiate text generation. + +7. The generated text will be displayed in the output section of the page. + +## Customization + +You can customize the appearance and behavior of the tool by modifying the HTML, CSS, and JavaScript code in the `test_generation.html` file. + +## Contributing + +Contributions are welcome! If you find any issues or want to add new features, feel free to open an issue or submit a pull request. + +## License + +This project is licensed under the [MIT License](LICENSE). +``` diff --git a/examples/lollms_playground/lollms_playground.html b/examples/lollms_playground/lollms_playground.html new file mode 100644 index 0000000..56b7485 --- /dev/null +++ b/examples/lollms_playground/lollms_playground.html @@ -0,0 +1,154 @@ + + + +
+ + +Error: ${error.message}
`; + socket.on('buzzy', error => { + console.error('Server is busy. Wait for your turn', error); + const outputDiv = document.getElementById('text'); + outputDiv.value += `Error: ${error.message}
`; outputDiv.scrollTop = outputDiv.scrollHeight; + // Toggle button visibility + generateButton.classList.remove('hidden'); + stopButton.classList.add('hidden'); + }); + // Event handler for error during text generation + socket.on('generation_canceled', error => { + // Toggle button visibility + generateButton.classList.remove('hidden'); + stopButton.classList.add('hidden'); + + }); + + + // Triggered when the "Connect" button is clicked connectButton.addEventListener('click', () => { const hostInput = document.getElementById('host'); @@ -94,25 +125,28 @@ if (host && port) { socket.io.uri = `http://${host}:${port}`; socket.connect(); - connectButton.disabled = true; - connectionSection.classList.add('hidden'); - generationSection.classList.remove('hidden'); + connectingText.classList.remove("hidden") } }); // Triggered when the "Generate Text" button is clicked generateButton.addEventListener('click', () => { - const promptInput = document.getElementById('prompt'); - const prompt = promptInput.value.trim(); + const outputDiv = document.getElementById('text'); + var prompt = outputDiv.value + console.log(prompt) + // Trigger the 'generate_text' event with the prompt + socket.emit('generate_text', { prompt, personality: -1, n_predicts: 1024 }); - if (prompt) { - // Clear output div - document.getElementById('output').innerHTML = ''; + // Toggle button visibility + generateButton.classList.add('hidden'); + stopButton.classList.remove('hidden'); + }); + + // Triggered when the "Stop Generation" button is clicked + stopButton.addEventListener('click', () => { + // Trigger the 'cancel_generation' event + socket.emit('cancel_generation',{}); - // Trigger the 'generate_text' event with the prompt - socket.emit('generate_text', { prompt, personality: -1, n_predicts: 1024 }); - promptInput.value = ''; - } }); diff --git a/tests/endoints_unit_tests/example_text_gen.txt b/tests/endoints_unit_tests/python/example_text_gen.txt similarity index 100% rename from tests/endoints_unit_tests/example_text_gen.txt rename to tests/endoints_unit_tests/python/example_text_gen.txt diff --git a/tests/endoints_unit_tests/test_generation.py b/tests/endoints_unit_tests/python/test_generation.py similarity index 100% rename from tests/endoints_unit_tests/test_generation.py rename to tests/endoints_unit_tests/python/test_generation.py