diff --git a/app.py b/app.py index 0a6543d9..957715b8 100644 --- a/app.py +++ b/app.py @@ -45,6 +45,8 @@ def run_update_script(args=None): os.system(f"python {update_script}") sys.exit(0) + +from lollms.helpers import ASCIIColors, get_trace_exception, trace_exception try: import git @@ -58,7 +60,6 @@ try: from lollms.binding import LOLLMSConfig, BindingBuilder from lollms.personality import AIPersonality from lollms.config import BaseConfig - from lollms.helpers import ASCIIColors, get_trace_exception, trace_exception from lollms.paths import LollmsPaths from api.db import Discussion @@ -87,8 +88,7 @@ try: import socket except Exception as ex: - print(ex) - print("Error importing some libraries. Updating lollms...") + trace_exception(ex) run_update_script() @@ -333,14 +333,6 @@ class LoLLMsWebUI(LoLLMsAPPI): "/delete_message", "delete_message", self.delete_message, methods=["GET"] ) - self.add_endpoint( - "/set_binding", "set_binding", self.set_binding, methods=["POST"] - ) - - self.add_endpoint( - "/set_model", "set_model", self.set_model, methods=["POST"] - ) - self.add_endpoint( "/get_config", "get_config", self.get_config, methods=["GET"] @@ -704,6 +696,15 @@ class LoLLMsWebUI(LoLLMsAPPI): self.config["model_name"]=data['setting_value'] if self.config["model_name"] is not None: try: + if self.binding: + self.binding.destroy_model() + + self.binding = None + self.model = None + for per in self.mounted_personalities: + per.model = None + gc.collect() + self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths) self.model = self.binding.build_model() self.rebuild_personalities(reload_all=True) except Exception as ex: @@ -1615,42 +1616,7 @@ class LoLLMsWebUI(LoLLMsAPPI): ASCIIColors.yellow("Message deleted") return jsonify({"status":True,"new_rank": new_rank}) - - - def set_binding(self): - data = request.get_json() - binding = str(data["binding"]) - if self.config['binding_name']!= binding: - print("New binding selected") - - self.config['binding_name'] = binding - try: - binding_ =self.process.load_binding(config["binding_name"],True) - models = binding_.list_models(self.config) - if len(models)>0: - self.binding = binding_ - self.config['model_name'] = models[0] - # Build chatbot - return jsonify(self.process.set_config(self.config)) - else: - return jsonify({"status": "no_models_found"}) - except : - return jsonify({"status": "failed"}) - - return jsonify({"status": "error"}) - - def set_model(self): - data = request.get_json() - model = str(data["model_name"]) - if self.config['model_name']!= model: - print("set_model: New model selected") - self.config['model_name'] = model - # Build chatbot - return jsonify(self.process.set_config(self.config)) - - return jsonify({"status": "succeeded"}) - - + def get_available_models(self): """Get the available models diff --git a/presets/presets.json b/presets/presets.json index 4dd1df53..727111e8 100644 --- a/presets/presets.json +++ b/presets/presets.json @@ -1,20 +1,14 @@ { - "Build a Latex Book": "@@\n```latex\n\\documentclass[12pt]{book}\n\\usepackage{url}\n\\begin{document}\n\\title{@@}\n\\author{@@} % Author\n\\date{\\today} % Date\n\\maketitle\n\\tableofcontents\n\\chapter{Introduction}\n@@\n\\end{document}\n```", "Simple Book writing":"Once apon a time", - "Simple Question Answer":"User:@@\nAssistant:", - "Question Answer with conditionning":"Assistant is a highly developed AI capable of answering any question about any subject.\nUser:@\nAssistant:", - "Instruct mode": "Instructions:\n@@\nAnswer:", - "Make full python code": "```python\n# project: @@ \n# author: @@\n# description: @@\n\n@@\n```\n---------\nExtra information:\nLicence: apache 2.0\nProgram type: Stand alone.\nDocumentation:\nMake README.md with the following table of contents:\n## Description\n## Installation\n## Usage\n## Licence\n## Contribute\n## Ethical guidelines\nInstructions:\nWrite a user side README.md\nStick to the provided code content and do not invent extra information.\nMake sure all sections of the table of contents are present in the file.\n----\nREADME.md:\n```markdown\n@@\n```", - "Make a python function": "Here is a python function that @@:\n```python\ndef", - "Make a c++ function": "Here is a c++ function that @@:\n```c++\n/*", - "Make a c# function": "Here is a c# function that @@:\n```c#\n/*", - "Make a objective-c function": "Here is a objective-c function that @@:\n```objective-c\n/*", - "Make a java function": "Here is a java function that @@:\n```java\n/*", - "Make a visual basic.net function": "Here is a visual basic function that @:\n```vb.net\n/*", - "Make a vue.js ui": "Here is a vue.js template that @@:\n```vue.js\n