mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-18 20:27:58 +00:00
new lollms version
This commit is contained in:
parent
c59fa57547
commit
ec43807bc8
@ -330,6 +330,24 @@ class LLMBinding:
|
|||||||
"""
|
"""
|
||||||
self.binding_config.config.save_config(self.configuration_file_path)
|
self.binding_config.config.save_config(self.configuration_file_path)
|
||||||
|
|
||||||
|
def generate_with_images(self,
|
||||||
|
prompt:str,
|
||||||
|
images:list=[],
|
||||||
|
n_predict: int = 128,
|
||||||
|
callback: Callable[[str, int, dict], bool] = None,
|
||||||
|
verbose: bool = False,
|
||||||
|
**gpt_params ):
|
||||||
|
"""Generates text out of a prompt and a bunch of images
|
||||||
|
This should be implemented by child class
|
||||||
|
|
||||||
|
Args:
|
||||||
|
prompt (str): The prompt to use for generation
|
||||||
|
images(list): A list of images to interpret
|
||||||
|
n_predict (int, optional): Number of tokens to prodict. Defaults to 128.
|
||||||
|
callback (Callable[[str, int, dict], 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -340,7 +358,7 @@ class LLMBinding:
|
|||||||
verbose: bool = False,
|
verbose: bool = False,
|
||||||
**gpt_params ):
|
**gpt_params ):
|
||||||
"""Generates text out of a prompt
|
"""Generates text out of a prompt
|
||||||
This should ber implemented by child class
|
This should be implemented by child class
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prompt (str): The prompt to use for generation
|
prompt (str): The prompt to use for generation
|
||||||
|
@ -76,7 +76,8 @@ class AIPersonality:
|
|||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
self.files = []
|
self.text_files = []
|
||||||
|
self.image_files = []
|
||||||
self.vectorizer = None
|
self.vectorizer = None
|
||||||
|
|
||||||
self.installation_option = installation_option
|
self.installation_option = installation_option
|
||||||
@ -290,9 +291,10 @@ Date: {{date}}
|
|||||||
return config
|
return config
|
||||||
def remove_file(self, path, callback=None):
|
def remove_file(self, path, callback=None):
|
||||||
try:
|
try:
|
||||||
self.files.remove(path)
|
if path in self.text_files:
|
||||||
|
self.text_files.remove(path)
|
||||||
Path(path).unlink()
|
Path(path).unlink()
|
||||||
if len(self.files)>0:
|
if len(self.text_files)>0:
|
||||||
try:
|
try:
|
||||||
self.vectorizer.remove_document(path)
|
self.vectorizer.remove_document(path)
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
@ -303,22 +305,52 @@ Date: {{date}}
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.vectorizer = None
|
self.vectorizer = None
|
||||||
|
elif path in self.image_files:
|
||||||
|
self.image_files.remove(path)
|
||||||
|
Path(path).unlink()
|
||||||
|
if len(self.text_files)>0:
|
||||||
|
try:
|
||||||
|
self.vectorizer.remove_document(path)
|
||||||
|
if callback is not None:
|
||||||
|
callback("File added successfully",MSG_TYPE.MSG_TYPE_INFO)
|
||||||
|
return True
|
||||||
|
except ValueError as ve:
|
||||||
|
ASCIIColors.error(f"Unsupported file format. Supported formats are {GenericDataLoader.get_supported_file_types()}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
self.vectorizer = None
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
ASCIIColors.warning(f"Couldn't remove the file {path}")
|
ASCIIColors.warning(f"Couldn't remove the file {path}")
|
||||||
|
|
||||||
def remove_all_files(self, callback=None):
|
def remove_all_files(self, callback=None):
|
||||||
for file in self.files:
|
for file in self.text_files:
|
||||||
try:
|
try:
|
||||||
Path(file).unlink()
|
Path(file).unlink()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
ASCIIColors.warning(f"Couldn't remove the file {file}")
|
ASCIIColors.warning(f"Couldn't remove the file {file}")
|
||||||
self.files=[]
|
for file in self.image_files:
|
||||||
|
try:
|
||||||
|
Path(file).unlink()
|
||||||
|
except Exception as ex:
|
||||||
|
ASCIIColors.warning(f"Couldn't remove the file {file}")
|
||||||
|
self.text_files=[]
|
||||||
|
self.image_files=[]
|
||||||
self.vectorizer = None
|
self.vectorizer = None
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_file(self, path, callback=None):
|
def add_file(self, path, callback=None):
|
||||||
self.files.append(path)
|
|
||||||
db_path = self.lollms_paths.personal_databases_path / "personalities" / self.name / "db.json"
|
db_path = self.lollms_paths.personal_databases_path / "personalities" / self.name / "db.json"
|
||||||
db_path.parent.mkdir(parents=True, exist_ok=True)
|
db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path = Path(path)
|
||||||
|
if path.suffix in [".png",".jpg",".gif",".bmp"]:
|
||||||
|
self.image_files.append(path)
|
||||||
|
ASCIIColors.info("Received image file")
|
||||||
|
if callback is not None:
|
||||||
|
callback("Image file added successfully",MSG_TYPE.MSG_TYPE_INFO)
|
||||||
|
else:
|
||||||
|
self.text_files.append(path)
|
||||||
|
ASCIIColors.info("Received text compatible file")
|
||||||
if self.vectorizer is None:
|
if self.vectorizer is None:
|
||||||
self.vectorizer = TextVectorizer(
|
self.vectorizer = TextVectorizer(
|
||||||
self.config.data_vectorization_method, # supported "model_embedding" or "tfidf_vectorizer"
|
self.config.data_vectorization_method, # supported "model_embedding" or "tfidf_vectorizer"
|
||||||
@ -1018,7 +1050,9 @@ class APScript(StateMachine):
|
|||||||
callback = None
|
callback = None
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(states_dict)
|
super().__init__(states_dict)
|
||||||
self.files=[]
|
self.text_files = []
|
||||||
|
self.image_files = []
|
||||||
|
|
||||||
self.personality = personality
|
self.personality = personality
|
||||||
self.personality_config = personality_config
|
self.personality_config = personality_config
|
||||||
self.installation_option = personality.installation_option
|
self.installation_option = personality.installation_option
|
||||||
@ -1118,12 +1152,14 @@ class APScript(StateMachine):
|
|||||||
def add_file(self, path, callback=None):
|
def add_file(self, path, callback=None):
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
callback("File added successfully",MSG_TYPE.MSG_TYPE_INFO)
|
callback("File added successfully",MSG_TYPE.MSG_TYPE_INFO)
|
||||||
self.files.append(path)
|
self.text_files.append(path)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def remove_file(self, path):
|
def remove_file(self, path):
|
||||||
self.files.remove(path)
|
if path in self.text_files:
|
||||||
|
self.text_files.remove(path)
|
||||||
|
elif path in self.image_files:
|
||||||
|
self.image_files.remove(path)
|
||||||
def load_config_file(self, path, default_config=None):
|
def load_config_file(self, path, default_config=None):
|
||||||
"""
|
"""
|
||||||
Load the content of local_config.yaml file.
|
Load the content of local_config.yaml file.
|
||||||
|
2
setup.py
2
setup.py
@ -26,7 +26,7 @@ def get_all_files(path):
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="lollms",
|
name="lollms",
|
||||||
version="6.1.1",
|
version="6.2.0",
|
||||||
author="Saifeddine ALOUI",
|
author="Saifeddine ALOUI",
|
||||||
author_email="aloui.saifeddine@gmail.com",
|
author_email="aloui.saifeddine@gmail.com",
|
||||||
description="A python library for AI personality definition",
|
description="A python library for AI personality definition",
|
||||||
|
Loading…
Reference in New Issue
Block a user