more security

This commit is contained in:
Saifeddine ALOUI 2024-04-29 22:39:41 +02:00
parent 227df34a42
commit 6bd5ce17c4
2 changed files with 31 additions and 7 deletions

View File

@ -24,7 +24,7 @@ import importlib
import sys, os
import platform
import gc
import yaml
class LollmsApplication(LoLLMsCom):
def __init__(
self,
@ -577,7 +577,25 @@ class LollmsApplication(LoLLMsCom):
current_message = messages[message_index]
# Build the conditionning text block
conditionning = self.personality.personality_conditioning
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]
language_path = self.lollms_paths.personal_configuration_path/"personalities"/self.personality.name/f"languages_{language}.yaml"
if not language_path.exists():
self.ShowBlockingMessage(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.dump({"conditionning":conditionning,"welcome_message":welcome_message})
self.HideBlockingMessage()
else:
with open(language_path,"w",encoding="utf-8", errors="ignore") as f:
language_pack = yaml.load(f)
welcome_message = language_pack["welcome_message"]
else:
conditionning = self.personality.personality_conditioning
# Check if there are document files to add to the prompt
internet_search_results = ""
@ -603,7 +621,7 @@ class LollmsApplication(LoLLMsCom):
n_negative_boost = 0
if self.config.force_output_language_to_be:
force_language="\n!@>important information: Answer the user in this language :"+self.config.force_output_language_to_be+"\n"
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"
n_force_language = len(self.model.tokenize(force_language))
else:
force_language=""

View File

@ -47,6 +47,7 @@ def list_personalities_categories():
@router.get("/list_personalities")
def list_personalities(category:str):
category = sanitize_path(category)
if not category:
return []
try:
@ -220,19 +221,24 @@ async def reinstall_personality(personality_in: PersonalityIn):
# ------------------------------------------- Files manipulation -----------------------------------------------------
class Identification(BaseModel):
client_id:str
@router.get("/get_current_personality_files_list")
def get_current_personality_files_list():
@router.post("/get_current_personality_files_list")
def get_current_personality_files_list(data:Identification):
check_access(lollmsElfServer, data.client_id)
if lollmsElfServer.personality is None:
return {"state":False, "error":"No personality selected"}
return {"state":True, "files":[{"name":Path(f).name, "size":Path(f).stat().st_size} for f in lollmsElfServer.personality.text_files]+[{"name":Path(f).name, "size":Path(f).stat().st_size} for f in lollmsElfServer.personality.image_files]}
@router.get("/clear_personality_files_list")
def clear_personality_files_list():
@router.post("/clear_personality_files_list")
def clear_personality_files_list(data:Identification):
check_access(lollmsElfServer, data.client_id)
if lollmsElfServer.personality is None:
return {"state":False, "error":"No personality selected"}
lollmsElfServer.personality.remove_all_files()
return {"state":True}
class RemoveFileData(BaseModel):
client_id:str
name:str