mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-18 20:17:50 +00:00
enhanced backends
This commit is contained in:
parent
2b5876c5dc
commit
308dd2d739
1
.gitignore
vendored
1
.gitignore
vendored
@ -165,4 +165,5 @@ web/.env.dev
|
||||
web/.env.development
|
||||
node_modules/
|
||||
|
||||
# Google chrome files
|
||||
*.crdownload
|
@ -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,
|
||||
|
@ -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
|
||||
|
1
backends/gpt_4all/requirements.txt
Normal file
1
backends/gpt_4all/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
gpt4all
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
return yaml_data
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -1 +1 @@
|
||||
pyllamacpp
|
||||
pyllamacpp>=2.1.3
|
@ -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
|
||||
return yaml_data
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
<label for="model" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
Model:
|
||||
</label>
|
||||
<select id="model" @change="update_model($event.target.value)"
|
||||
<select id="model" @change="update_model($event.target.value)" @mouseup="update_model($event.target.value)"
|
||||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
||||
|
||||
<option v-for="item in modelsArr" :selected="item === configFile.model">{{ item }}</option>
|
||||
|
Loading…
Reference in New Issue
Block a user