enhanced configuration

This commit is contained in:
Saifeddine ALOUI 2024-05-01 01:24:30 +02:00
parent d84083118e
commit cb17c8b917
9 changed files with 96 additions and 13 deletions

View File

@ -1,5 +1,5 @@
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
version: 84
version: 85
binding_name: null
model_name: null
model_variant: null
@ -173,7 +173,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: false

View File

@ -168,7 +168,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: False

View File

@ -168,7 +168,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: False

View File

@ -168,7 +168,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: False

View File

@ -547,6 +547,47 @@ class LollmsApplication(LoLLMsCom):
file_path.unlink()
ASCIIColors.info(f"Deleted file: {file_path}")
#languages:
def get_personality_languages(self):
languages = []
# Construire le chemin vers le dossier contenant les fichiers de langue pour la personnalité actuelle
languages_dir = self.lollms_paths.personal_configuration_path / "personalities" / self.personality.name
# Vérifier si le dossier existe
if not languages_dir.exists():
print(f"Le dossier {languages_dir} n'existe pas.")
return languages
# Itérer sur chaque fichier YAML dans le dossier
for language_file in languages_dir.glob("languages_*.yaml"):
# Extraire le code de langue depuis le nom du fichier
language_code = language_file.stem.split("_")[-1]
languages.append(language_code)
return languages
def set_personality_language(self, language:str):
if language is None or language == "":
return False
language = language.lower().strip().split()[0]
language_path = self.lollms_paths.personal_configuration_path/"personalities"/self.personality.name/f"languages_{language}.yaml"
if not language_path.exists():
self.info(f"This is the first time this personality seaks {language}\nLollms is reconditionning the persona in that language.\nThis will be done just once. Next time, the personality will speak {language} out of the box")
language_path.parent.mkdir(exist_ok=True, parents=True)
conditionning = "!@>system: "+self.personality.fast_gen(f"!@>instruction: Translate the following text to {language}:\n{self.personality.personality_conditioning.replace('!@>system:','')}\n!@>translation:\n")
welcome_message = self.personality.fast_gen(f"!@>instruction: Translate the following text to {language}:\n{self.personality.welcome_message}\n!@>translation:\n")
with open(language_path,"w",encoding="utf-8", errors="ignore") as f:
yaml.safe_dump({"conditionning":conditionning,"welcome_message":welcome_message}, f)
else:
with open(language_path,"r",encoding="utf-8", errors="ignore") as f:
language_pack = yaml.safe_load(f)
conditionning = language_pack["conditionning"]
self.config.current_language=language
self.config.save_config()
return True
# -------------------------------------- Prompt preparing
def prepare_query(self, client_id: str, message_id: int = -1, is_continue: bool = False, n_tokens: int = 0, generation_type = None, force_using_internet=False) -> Tuple[str, str, List[str]]:
"""
@ -577,8 +618,8 @@ class LollmsApplication(LoLLMsCom):
current_message = messages[message_index]
# Build the conditionning text block
if self.config.force_output_language_to_be and self.config.force_output_language_to_be.lower().strip() !="english":
language = self.config.force_output_language_to_be.lower().strip().split()[0]
if self.config.current_language and self.config.current_language.lower().strip() !="english":
language = self.config.current_language.lower().strip().split()[0]
language_path = self.lollms_paths.personal_configuration_path/"personalities"/self.personality.name/f"languages_{language}.yaml"
if not language_path.exists():
self.info(f"This is the first time this personality seaks {language}\nLollms is reconditionning the persona in that language.\nThis will be done just once. Next time, the personality will speak {language} out of the box")
@ -619,8 +660,8 @@ class LollmsApplication(LoLLMsCom):
negative_boost=""
n_negative_boost = 0
if self.config.force_output_language_to_be:
force_language="\n!@>important information: Answer the user in "+self.config.force_output_language_to_be+" and do not translate your answer to english\n"
if self.config.current_language:
force_language="\n!@>important information: Answer the user in "+self.config.current_language+" and do not translate your answer to english\n"
n_force_language = len(self.model.tokenize(force_language))
else:
force_language=""

View File

@ -1,5 +1,5 @@
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
version: 84
version: 85
binding_name: null
model_name: null
model_variant: null
@ -173,7 +173,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: false

View File

@ -172,7 +172,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: False

View File

@ -254,6 +254,48 @@ def remove_file(data:RemoveFileData):
return {"state":False, "error":"No personality selected"}
lollmsElfServer.personality.remove_file(data.name)
return {"state":True}
# ------------------------------------------- Languages endpoints ------------------------------------------------
class Identification(BaseModel):
client_id:str
@router.post("/get_personality_languages_list")
def get_current_personality_files_list(data:Identification):
check_access(lollmsElfServer, data.client_id)
languages_list = lollmsElfServer.get_personality_languages()
# Return the languages list
return languages_list
@router.post("/get_personality_language")
def set_personality_language(request: Identification):
# Access verification
check_access(lollmsElfServer, request.client_id)
return lollmsElfServer.config.current_language
class SetLanguageRequest(BaseModel):
client_id: str
language: str
# Definition of the endpoint for setting the personality language
@router.post("/set_personality_language")
def set_personality_language(request: SetLanguageRequest):
# Access verification
check_access(lollmsElfServer, request.client_id)
# Calling the method to set the personality language
success = lollmsElfServer.set_personality_language(request.language)
# Returning an appropriate response depending on whether the operation was successful or not
if success:
return {"message": f"The personality language has been successfully set to {request.language}."}
else:
raise HTTPException(status_code=400, detail="Failed to set the personality language")
# ------------------------------------------- Mounting/Unmounting/Remounting ------------------------------------------------
class PersonalityDataRequest(BaseModel):
client_id:str

View File

@ -168,7 +168,7 @@ pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null
current_language: null
fun_mode: False