Package: lollms
Lord of Large Language Models (LoLLMs)Lord of Large Language Models (LoLLMs) Server is a text generation server based on large language models. It provides a Flask-based API for generating text using various pre-trained language models. This server is designed to be easy to install and use, allowing developers to integrate powerful text generation capabilities into their applications.FeaturesFully integrated library with access to bindings, personalities and helper tools.Generate text using large language models.Supports multiple personalities for generating text with different styles and tones.Real-time text generation with WebSocket-based communication.RESTful API for listing personalities and adding new personalities.Easy integration with various applications and frameworks.Possibility to send files to personalitiesPossibility to run on multiple nodes and provide a generation service to many outputs at once.Data stays local even in the remote version. Only generations are sent to the host node. The logs, data and discussion history are kept in your local disucssion folder.InstallationYou can install LoLLMs using pip, the Python package manager. Open your terminal or command prompt and run the following command:pipinstall--upgradelollmsOr if you want to get the latest version from the git:pipinstall--upgradegit+https://github.com/ParisNeo/lollms.gitGPU supportIf you want to use cuda. Either install it directly or use conda to install everything:condacreate--namelollmspython=3.10Activate the environmentcondaactivatelollmsInstall cudatoolkitcondainstall-canacondacudatoolkitInstall lollmspipinstall--upgradelollmsNow you are ready.To simply configure your environment run the settings app:lollms-settingsThe tool is intuitive and will guide you through configuration process.The first time you will be prompted to select a binding.Once the binding is selected, you have to install at least a model. You have two options:1- install from internet. Just give the link to a model on hugging face. For example. if you select the default llamacpp python bindings (7), you can install this model:https://huggingface.co/TheBloke/airoboros-7b-gpt4-GGML/resolve/main/airoboros-7b-gpt4.ggmlv3.q4_1.bin2- install from local drive. Just give the path to a model on your pc. The model will not be copied. We only create a reference to the model. This is useful if you use multiple clients so that you can mutualize your models with other tools.Now you are ready to use the server.Library exampleHere is the smallest possible example that allows you to use the full potential of the tool with nearly no codefromlollms.consoleimportConversationcv=Conversation(None)cv.start_conversation()Now you can reimplement the start_conversation method to do the things you want:fromlollms.consoleimportConversationclassMyConversation(Conversation):def__init__(self,cfg=None):super().__init__(cfg,show_welcome_message=False)defstart_conversation(self):prompt="Once apon a time"defcallback(text,type=None):print(text,end="",flush=True)returnTrueprint(prompt,end="",flush=True)output=self.safe_generate(prompt,callback=callback)if__name__=='__main__':cv=MyConversation()cv.start_conversation()Or if you want here is a conversation tool written in few linesfromlollms.consoleimportConversationclassMyConversation(Conversation):def__init__(self,cfg=None):super().__init__(cfg,show_welcome_message=False)defstart_conversation(self):full_discussion=""whileTrue:prompt=input("You: ")ifprompt=="exit":returnifprompt=="menu":self.menu.main_menu()full_discussion+=self.personality.user_message_prefix+prompt+self.personality.link_textfull_discussion+=self.personality.ai_message_prefixdefcallback(text,type=None):print(text,end="",flush=True)returnTrueprint(self.personality.name+": ",end="",flush=True)output=self.safe_generate(full_discussion,callback=callback)full_discussion+=output.strip()+self.personality.link_textprint()if__name__=='__main__':cv=MyConversation()cv.start_conversation()Here we use the safe_generate method that does all the cropping for you ,so you can chat forever and will never run out of context.Socket IO Server UsageOnce installed, you can start the LoLLMs Server using thelollms-servercommand followed by the desired parameters.lollms-server --host <host> --port <port> --config <config_file> --bindings_path <bindings_path> --personalities_path <personalities_path> --models_path <models_path> --binding_name <binding_name> --model_name <model_name> --personality_full_name <personality_full_name>Parameters--host: The hostname or IP address to bind the server (default: localhost).--port: The port number to run the server (default: 9600).--config: Path to the configuration file (default: None).--bindings_path: The path to the Bindings folder (default: "./bindings_zoo").--personalities_path: The path to the personalities folder (default: "./personalities_zoo").--models_path: The path to the models folder (default: "./models").--binding_name: The default binding to be used (default: "llama_cpp_official").--model_name: The default model name (default: "Manticore-13B.ggmlv3.q4_0.bin").--personality_full_name: The full name of the default personality (default: "personality").ExamplesStart the server with default settings:lollms-serverStart the server on a specific host and port:lollms-server --host 0.0.0.0 --port 5000API EndpointsWebSocket Eventsconnect: Triggered when a client connects to the server.disconnect: Triggered when a client disconnects from the server.list_personalities: List all available personalities.add_personality: Add a new personality to the server.generate_text: Generate text based on the provided prompt and selected personality.RESTful APIGET /personalities: List all available personalities.POST /personalities: Add a new personality to the server.Sure! Here are examples of how to communicate with the LoLLMs Server using JavaScript and Python.JavaScript Example// Establish a WebSocket connection with the serverconstsocket=io.connect('http://localhost:9600');// Event: When connected to the serversocket.on('connect',()=>{console.log('Connected to the server');// Request the list of available personalitiessocket.emit('list_personalities');});// Event: Receive the list of personalities from the serversocket.on('personalities_list',(data)=>{constpersonalities=data.personalities;console.log('Available Personalities:',personalities);// Select a personality and send a text generation requestconstselectedPersonality=personalities[0];constprompt='Once upon a time...';socket.emit('generate_text',{personality:selectedPersonality,prompt:prompt});});// Event: Receive the generated text from the serversocket.on('text_generated',(data)=>{constgeneratedText=data.text;console.log('Generated Text:',generatedText);// Do something with the generated text});// Event: When disconnected from the serversocket.on('disconnect',()=>{console.log('Disconnected from the server');});Python Exampleimportsocketio# Create a SocketIO clientsio=socketio.Client()# Event: When connected to the server@sio.on('connect')defon_connect():print('Connected to the server')# Request the list of available personalitiessio.emit('list_personalities')# Event: Receive the list of personalities from the server@sio.on('personalities_list')defon_personalities_list(data):personalities=data['personalities']print('Available Personalities:',personalities)# Select a personality and send a text generation requestselected_personality=personalities[0]prompt='Once upon a time...'sio.emit('generate_text',{'personality':selected_personality,'prompt':prompt})# Event: Receive the generated text from the server@sio.on('text_generated')defon_text_generated(data):generated_text=data['text']print('Generated Text:',generated_text)# Do something with the generated text# Event: When disconnected from the server@sio.on('disconnect')defon_disconnect():print('Disconnected from the server')# Connect to the serversio.connect('http://localhost:9600')# Keep the client runningsio.wait()Make sure to have the necessary dependencies installed for the JavaScript and Python examples. For JavaScript, you need thesocket.io-clientpackage, and for Python, you need thepython-socketiopackage.ContributingContributions to the LoLLMs Server project are welcome and appreciated. If you would like to contribute, please follow the guidelines outlined in theCONTRIBUTING.mdfile.LicenseLoLLMs Server is licensed under the Apache 2.0 License. See theLICENSEfile for more information.RepositoryThe source code for LoLLMs Server can be found on GitHub