mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-02-08 03:50:22 +00:00
more security
This commit is contained in:
parent
227df34a42
commit
6bd5ce17c4
@ -24,7 +24,7 @@ import importlib
|
|||||||
import sys, os
|
import sys, os
|
||||||
import platform
|
import platform
|
||||||
import gc
|
import gc
|
||||||
|
import yaml
|
||||||
class LollmsApplication(LoLLMsCom):
|
class LollmsApplication(LoLLMsCom):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -577,8 +577,26 @@ class LollmsApplication(LoLLMsCom):
|
|||||||
current_message = messages[message_index]
|
current_message = messages[message_index]
|
||||||
|
|
||||||
# Build the conditionning text block
|
# 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]
|
||||||
|
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
|
conditionning = self.personality.personality_conditioning
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Check if there are document files to add to the prompt
|
# Check if there are document files to add to the prompt
|
||||||
internet_search_results = ""
|
internet_search_results = ""
|
||||||
internet_search_infos = []
|
internet_search_infos = []
|
||||||
@ -603,7 +621,7 @@ class LollmsApplication(LoLLMsCom):
|
|||||||
n_negative_boost = 0
|
n_negative_boost = 0
|
||||||
|
|
||||||
if self.config.force_output_language_to_be:
|
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))
|
n_force_language = len(self.model.tokenize(force_language))
|
||||||
else:
|
else:
|
||||||
force_language=""
|
force_language=""
|
||||||
|
@ -47,6 +47,7 @@ def list_personalities_categories():
|
|||||||
|
|
||||||
@router.get("/list_personalities")
|
@router.get("/list_personalities")
|
||||||
def list_personalities(category:str):
|
def list_personalities(category:str):
|
||||||
|
category = sanitize_path(category)
|
||||||
if not category:
|
if not category:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
@ -220,19 +221,24 @@ async def reinstall_personality(personality_in: PersonalityIn):
|
|||||||
|
|
||||||
|
|
||||||
# ------------------------------------------- Files manipulation -----------------------------------------------------
|
# ------------------------------------------- Files manipulation -----------------------------------------------------
|
||||||
|
class Identification(BaseModel):
|
||||||
|
client_id:str
|
||||||
|
|
||||||
@router.get("/get_current_personality_files_list")
|
@router.post("/get_current_personality_files_list")
|
||||||
def get_current_personality_files_list():
|
def get_current_personality_files_list(data:Identification):
|
||||||
|
check_access(lollmsElfServer, data.client_id)
|
||||||
if lollmsElfServer.personality is None:
|
if lollmsElfServer.personality is None:
|
||||||
return {"state":False, "error":"No personality selected"}
|
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]}
|
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")
|
@router.post("/clear_personality_files_list")
|
||||||
def clear_personality_files_list():
|
def clear_personality_files_list(data:Identification):
|
||||||
|
check_access(lollmsElfServer, data.client_id)
|
||||||
if lollmsElfServer.personality is None:
|
if lollmsElfServer.personality is None:
|
||||||
return {"state":False, "error":"No personality selected"}
|
return {"state":False, "error":"No personality selected"}
|
||||||
lollmsElfServer.personality.remove_all_files()
|
lollmsElfServer.personality.remove_all_files()
|
||||||
return {"state":True}
|
return {"state":True}
|
||||||
|
|
||||||
class RemoveFileData(BaseModel):
|
class RemoveFileData(BaseModel):
|
||||||
client_id:str
|
client_id:str
|
||||||
name:str
|
name:str
|
||||||
|
Loading…
x
Reference in New Issue
Block a user