diff --git a/.gitignore b/.gitignore index 9ebb9d3e..31077542 100644 --- a/.gitignore +++ b/.gitignore @@ -165,4 +165,5 @@ web/.env.dev web/.env.development node_modules/ +# Google chrome files *.crdownload \ No newline at end of file diff --git a/backends/c_transformers/__init__.py b/backends/c_transformers/__init__.py index ef1f989c..249c12eb 100644 --- a/backends/c_transformers/__init__.py +++ b/backends/c_transformers/__init__.py @@ -57,7 +57,31 @@ class GPTJ(GPTBackend): self.model = AutoModelForCausalLM.from_pretrained( f"./models/c_transformers/{self.config['model']}", model_type=model_type, lib = "avx" ) + + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return self.model.tokenize(prompt.encode()) + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return self.model.detokenize(tokens_list) + def generate(self, prompt:str, n_predict: int = 128, diff --git a/backends/gpt_4all/__init__.py b/backends/gpt_4all/__init__.py index 34aa5421..ba2d1bde 100644 --- a/backends/gpt_4all/__init__.py +++ b/backends/gpt_4all/__init__.py @@ -40,6 +40,30 @@ class GPT4ALL(GPTBackend): model_path=f"./models/gpt_4all/{self.config['model']}", ) + + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return None + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return None def generate(self, prompt:str, n_predict: int = 128, @@ -63,6 +87,7 @@ class GPT4ALL(GPTBackend): repeat_penalty=self.config['repeat_penalty'], repeat_last_n = self.config['repeat_last_n'], # n_threads=self.config['n_threads'], + streaming=True ): if not new_text_callback(tok): return diff --git a/backends/gpt_4all/requirements.txt b/backends/gpt_4all/requirements.txt new file mode 100644 index 00000000..461121c3 --- /dev/null +++ b/backends/gpt_4all/requirements.txt @@ -0,0 +1 @@ +gpt4all \ No newline at end of file diff --git a/backends/gpt_j_a/__init__.py b/backends/gpt_j_a/__init__.py index 4129d7b9..bf99fd45 100644 --- a/backends/gpt_j_a/__init__.py +++ b/backends/gpt_j_a/__init__.py @@ -38,7 +38,29 @@ class GptJ(GPTBackend): model_path=f"./models/gpt_j/{self.config['model']}", prompt_context="", prompt_prefix="", prompt_suffix="" ) + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return None + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return None def generate(self, prompt:str, n_predict: int = 128, diff --git a/backends/gpt_j_m/__init__.py b/backends/gpt_j_m/__init__.py index 4cc43eb0..bf32919d 100644 --- a/backends/gpt_j_m/__init__.py +++ b/backends/gpt_j_m/__init__.py @@ -38,7 +38,29 @@ class GPTJ(GPTBackend): self.model = Model( model=f"./models/llama_cpp/{self.config['model']}", avx2 = self.config["use_avx2"] ) + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return None + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return None def generate(self, prompt:str, n_predict: int = 128, diff --git a/backends/gptq/__init__.py b/backends/gptq/__init__.py index 77aea56c..d52d6077 100644 --- a/backends/gptq/__init__.py +++ b/backends/gptq/__init__.py @@ -37,7 +37,29 @@ class GPTQ(GPTBackend): # load quantized model, currently only support cpu or single gpu self.model = AutoGPTQForCausalLM.from_pretrained(self.model_dir, BaseQuantizeConfig()) self.tokenizer = AutoTokenizer.from_pretrained(self.model_dir, use_fast=True ) + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return None + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return None def generate(self, prompt:str, n_predict: int = 128, diff --git a/backends/llama_cpp_official/__init__.py b/backends/llama_cpp_official/__init__.py index 2584c5fc..c481f66b 100644 --- a/backends/llama_cpp_official/__init__.py +++ b/backends/llama_cpp_official/__init__.py @@ -40,6 +40,31 @@ class LLAMACPP(GPTBackend): self.model = Llama(model_path=f"./models/llama_cpp_official/{self.config['model']}", n_gpu_layers=40, seed=seed) + + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return self.model.tokenize(prompt.encode()) + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return self.model.detokenize(tokens_list).decode() + def generate(self, prompt:str, n_predict: int = 128, @@ -82,4 +107,6 @@ class LLAMACPP(GPTBackend): with open(file_path, 'r') as file: yaml_data = yaml.safe_load(file) - return yaml_data \ No newline at end of file + return yaml_data + + diff --git a/backends/py_llama_cpp/__init__.py b/backends/py_llama_cpp/__init__.py index 37b89f1b..ce4da512 100644 --- a/backends/py_llama_cpp/__init__.py +++ b/backends/py_llama_cpp/__init__.py @@ -40,7 +40,30 @@ class PyLLAMACPP(GPTBackend): n_ctx=self.config['ctx_size'], seed=self.config['seed'], ) + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + return self.model.tokenize(prompt) + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + return self.model.detokenize(tokens_list) + def generate(self, prompt:str, n_predict: int = 128, diff --git a/backends/py_llama_cpp/requirements.txt b/backends/py_llama_cpp/requirements.txt index aa3c1719..4017323b 100644 --- a/backends/py_llama_cpp/requirements.txt +++ b/backends/py_llama_cpp/requirements.txt @@ -1 +1 @@ -pyllamacpp \ No newline at end of file +pyllamacpp>=2.1.3 \ No newline at end of file diff --git a/gpt4all_api/backend.py b/gpt4all_api/backend.py index d5516295..5f7930c5 100644 --- a/gpt4all_api/backend.py +++ b/gpt4all_api/backend.py @@ -43,6 +43,30 @@ class GPTBackend: verbose (bool, optional): If true, the code will spit many informations about the generation process. Defaults to False. """ pass + def tokenize(self, prompt): + """ + Tokenizes the given prompt using the model's tokenizer. + + Args: + prompt (str): The input prompt to be tokenized. + + Returns: + list: A list of tokens representing the tokenized prompt. + """ + pass + + def detokenize(self, tokens_list): + """ + Detokenizes the given list of tokens using the model's tokenizer. + + Args: + tokens_list (list): A list of tokens to be detokenized. + + Returns: + str: The detokenized text as a string. + """ + pass + @staticmethod def list_models(config:dict): """Lists the models for this backend @@ -58,4 +82,5 @@ class GPTBackend: with open(file_path, 'r') as file: yaml_data = yaml.safe_load(file) - return yaml_data \ No newline at end of file + return yaml_data + diff --git a/web/src/views/SettingsView.vue b/web/src/views/SettingsView.vue index 168ad991..a25d060b 100644 --- a/web/src/views/SettingsView.vue +++ b/web/src/views/SettingsView.vue @@ -58,7 +58,7 @@ -