Upgraded backend management

This commit is contained in:
saloui 2023-05-02 16:49:13 +02:00
parent cf2316fcd0
commit a7c6014adc
4 changed files with 14 additions and 9 deletions

11
app.py
View File

@ -206,8 +206,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
def list_models(self):
models_dir = Path('./models')/self.config["backend"] # replace with the actual path to the models folder
models = [f.name for f in models_dir.glob(self.backend.file_extension)]
models = self.backend.list_models(self.config)
return jsonify(models)
@ -419,11 +418,11 @@ class Gpt4AllWebUI(GPT4AllAPI):
print("New backend selected")
self.config['backend'] = backend
models_dir = Path('./models')/self.config["backend"] # replace with the actual path to the models folder
models = [f.name for f in models_dir.glob(self.backend.file_extension)]
if len(models)>0:
backend_ =self.load_backend(self.BACKENDS_LIST[self.config["backend"]])
models = backend_.list_models(self.config)
if len(models)>0:
self.backend = backend_
self.config['model'] = models[0]
self.load_backend(self.BACKENDS_LIST[self.config["backend"]])
# Build chatbot
self.chatbot_bindings = self.create_chatbot()
return jsonify({"status": "ok"})

View File

@ -45,7 +45,7 @@ class GPT4AllAPI():
# Select backend
self.BACKENDS_LIST = {f.stem:f for f in Path("backends").iterdir() if f.is_dir() and f.stem!="__pycache__"}
self.load_backend(self.BACKENDS_LIST[self.config["backend"]])
self.backend =self.load_backend(self.BACKENDS_LIST[self.config["backend"]])
# Build chatbot
self.chatbot_bindings = self.create_chatbot()
@ -65,7 +65,7 @@ class GPT4AllAPI():
loader = importlib.machinery.SourceFileLoader(module_name, str(absolute_path/"__init__.py"))
backend_module = loader.load_module()
backend_class = getattr(backend_module, backend_module.backend_name)
self.backend = backend_class
return backend_class
def create_chatbot(self):
return self.backend(self.config)

View File

@ -38,4 +38,10 @@ class GPTBackend:
new_text_callback (Callable[[str], None], optional): A callback function that is called everytime a new text element is generated. Defaults to None.
verbose (bool, optional): If true, the code will spit many informations about the generation process. Defaults to False.
"""
pass
pass
@staticmethod
def list_models(config:dict):
"""Lists the models for this backend
"""
models_dir = Path('./models')/config["backend"] # replace with the actual path to the models folder
return [f.name for f in models_dir.glob(GPTBackend.file_extension)]