diff --git a/app.py b/app.py index e6cc8458..58d59fa1 100644 --- a/app.py +++ b/app.py @@ -109,7 +109,7 @@ class Gpt4AllWebUI(GPT4AllAPI): self.add_endpoint("/", "", self.index, methods=["GET"]) self.add_endpoint("/", "serve_static", self.serve_static, methods=["GET"]) self.add_endpoint("/personalities/", "serve_personalities", self.serve_personalities, methods=["GET"]) - + self.add_endpoint("/export_discussion", "export_discussion", self.export_discussion, methods=["GET"]) self.add_endpoint("/export", "export", self.export, methods=["GET"]) @@ -778,8 +778,13 @@ class Gpt4AllWebUI(GPT4AllAPI): def get_available_models(self): - response = requests.get(f'https://gpt4all.io/models/models.json') - model_list = response.json() + """Get the available models + + Returns: + _type_: _description_ + """ + + model_list = self.backend.get_available_models() models = [] for model in model_list: diff --git a/backends/gpt4all/__init__.py b/backends/gpt4all/__init__.py index 6b192115..faea2f7f 100644 --- a/backends/gpt4all/__init__.py +++ b/backends/gpt4all/__init__.py @@ -11,6 +11,7 @@ from pathlib import Path from typing import Callable from pygpt4all import GPT4All as Model from pyGpt4All.backend import GPTBackend +import yaml __author__ = "parisneo" __github__ = "https://github.com/nomic-ai/gpt4all-ui" @@ -21,6 +22,7 @@ backend_name = "GPT4ALL" class GPT4ALL(GPTBackend): file_extension='*.bin' + def __init__(self, config:dict) -> None: """Builds a GPT4ALL backend @@ -67,4 +69,15 @@ class GPT4ALL(GPTBackend): if not new_text_callback(tok): return except Exception as ex: - print(ex) \ No newline at end of file + print(ex) + + @staticmethod + def get_available_models(): + # Create the file path relative to the child class's directory + backend_path = Path(__file__).parent + file_path = backend_path/"models.yaml" + + with open(file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + + return yaml_data \ No newline at end of file diff --git a/backends/llama_cpp/__init__.py b/backends/llama_cpp/__init__.py index 0c410d66..816979d5 100644 --- a/backends/llama_cpp/__init__.py +++ b/backends/llama_cpp/__init__.py @@ -11,6 +11,7 @@ from pathlib import Path from typing import Callable from pyllamacpp.model import Model from pyGpt4All.backend import GPTBackend +import yaml __author__ = "parisneo" __github__ = "https://github.com/nomic-ai/gpt4all-ui" @@ -67,4 +68,15 @@ class LLAMACPP(GPTBackend): if not new_text_callback(tok): return except Exception as ex: - print(ex) \ No newline at end of file + print(ex) + + @staticmethod + def get_available_models(): + # Create the file path relative to the child class's directory + backend_path = Path(__file__).parent + file_path = backend_path/"models.yaml" + + with open(file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + + return yaml_data \ No newline at end of file diff --git a/configs/default.yaml b/configs/default.yaml index 6c12b3d4..fa50fc95 100644 --- a/configs/default.yaml +++ b/configs/default.yaml @@ -7,7 +7,7 @@ n_threads: 8 host: localhost language: en-US # Supported backends are llamacpp and gpt-j -backend: gpt4all +backend: llamacpp model: null n_predict: 1024 nb_messages_to_remember: 5 diff --git a/pyGpt4All/backend.py b/pyGpt4All/backend.py index aa301a4c..d5516295 100644 --- a/pyGpt4All/backend.py +++ b/pyGpt4All/backend.py @@ -9,6 +9,9 @@ ###### from pathlib import Path from typing import Callable +import inspect +import yaml +import sys __author__ = "parisneo" __github__ = "https://github.com/nomic-ai/gpt4all-ui" @@ -18,6 +21,7 @@ __license__ = "Apache 2.0" class GPTBackend: file_extension='*.bin' + backend_path = Path(__file__).parent def __init__(self, config:dict, inline:bool) -> None: self.config = config self.inline = inline @@ -45,3 +49,13 @@ class GPTBackend: """ 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)] + @staticmethod + def get_available_models(): + # Create the file path relative to the child class's directory + backend_path = Path(__file__).parent + file_path = backend_path/"models.yaml" + + with open(file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + + return yaml_data \ No newline at end of file diff --git a/web/src/views/SettingsView.vue b/web/src/views/SettingsView.vue index 788ebbd4..05d3b828 100644 --- a/web/src/views/SettingsView.vue +++ b/web/src/views/SettingsView.vue @@ -450,13 +450,17 @@ export default { axios.post('/update_setting', obj).then((res) => { if (res) { if (next !== undefined) { - next() + next(res) } return res.data; } }) .catch(error => { return { 'status': false } }); }, + update_backend(value) { + console.log("Upgrading backend") + res = this.update_setting('backend', value, (res)=>{console.log("Backend changed"); }) + }, save_configuration() { this.showConfirmation = false axios.post('/save_settings', {}) @@ -502,13 +506,7 @@ export default { } }); }, - update_backend(value) { - res = update_setting('backend', value) - if (res.status) { - console.log("Backend changed") - } - }, async api_get_req(endpoint) { try { const res = await axios.get("/" + endpoint);