mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-01-03 03:16:45 +00:00
sync
This commit is contained in:
parent
0337e8a38b
commit
62677f4ee5
@ -2652,15 +2652,18 @@ The AI should respond in this format using data from actions_list:
|
|||||||
|
|
||||||
def extract_code_blocks(self, text: str) -> List[dict]:
|
def extract_code_blocks(self, text: str) -> List[dict]:
|
||||||
remaining = text
|
remaining = text
|
||||||
|
bloc_index = 0
|
||||||
first_index=0
|
first_index=0
|
||||||
indices = []
|
indices = []
|
||||||
while len(remaining)>0:
|
while len(remaining)>0:
|
||||||
try:
|
try:
|
||||||
index = remaining.index("```")
|
index = remaining.index("```")
|
||||||
indices.append(index+first_index)
|
indices.append(index+first_index)
|
||||||
remaining = remaining.index("```")[index+3:]
|
remaining = remaining[index+3:]
|
||||||
first_index += index+3
|
first_index += index+3
|
||||||
except:
|
bloc_index +=1
|
||||||
|
except Exception as ex:
|
||||||
|
if bloc_index%2==1:
|
||||||
index=len(remaining)
|
index=len(remaining)
|
||||||
indices.append(index)
|
indices.append(index)
|
||||||
remaining = ""
|
remaining = ""
|
||||||
@ -2691,8 +2694,8 @@ The AI should respond in this format using data from actions_list:
|
|||||||
else:
|
else:
|
||||||
block_infos["type"]=sub_text[:next_index]
|
block_infos["type"]=sub_text[:next_index]
|
||||||
|
|
||||||
next_pos = indices[index+1]-code_delimiter_position+3
|
next_pos = indices[index+1]-code_delimiter_position
|
||||||
block_infos["content"]=sub_text[start_pos:next_pos].strip()
|
block_infos["content"]=sub_text[start_pos:next_pos-3].strip()
|
||||||
code_blocks.append(block_infos)
|
code_blocks.append(block_infos)
|
||||||
is_start = False
|
is_start = False
|
||||||
else:
|
else:
|
||||||
@ -2701,6 +2704,22 @@ The AI should respond in this format using data from actions_list:
|
|||||||
|
|
||||||
return code_blocks
|
return code_blocks
|
||||||
|
|
||||||
|
|
||||||
|
def build_and_execute_python_code(self,context, instructions, execution_function_signature, inputs):
|
||||||
|
code = "```python\n"+self.fast_gen("!@>context!:\n"+context+f"\n!@>instructions: {instructions}.\nHere is the signature of the function:\n{execution_function_signature}\n!@>Code: Here is the query function that you are asking for:\n```python\n", callback=self.sink)
|
||||||
|
code=self.extract_code_blocks(code)
|
||||||
|
|
||||||
|
if len(code)>0:
|
||||||
|
# Perform the search query
|
||||||
|
code = code[0]["content"]
|
||||||
|
ASCIIColors.magenta(code)
|
||||||
|
module_name = 'custom_module'
|
||||||
|
spec = importlib.util.spec_from_loader(module_name, loader=None)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
exec(code, module.__dict__)
|
||||||
|
return module.query(*inputs)
|
||||||
|
|
||||||
|
|
||||||
def yes_no(self, question: str, context:str="", max_answer_length: int = 50, conditionning="") -> bool:
|
def yes_no(self, question: str, context:str="", max_answer_length: int = 50, conditionning="") -> bool:
|
||||||
"""
|
"""
|
||||||
Analyzes the user prompt and answers whether it is asking to generate an image.
|
Analyzes the user prompt and answers whether it is asking to generate an image.
|
||||||
|
@ -226,6 +226,15 @@ def clear_personality_files_list():
|
|||||||
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):
|
||||||
|
name:str
|
||||||
|
|
||||||
|
@router.post("/remove_file")
|
||||||
|
def remove_file(data:RemoveFileData):
|
||||||
|
if lollmsElfServer.personality is None:
|
||||||
|
return {"state":False, "error":"No personality selected"}
|
||||||
|
lollmsElfServer.personality.remove_file(data.name)
|
||||||
|
return {"state":True}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user