This commit is contained in:
Saifeddine ALOUI 2024-02-05 00:43:23 +01:00
parent ac0e86c29b
commit d011fec1bc
2 changed files with 49 additions and 27 deletions

View File

@ -107,21 +107,29 @@ async def open_code_folder_in_vs_code(request: Request):
""" """
try: try:
data = (await request.json()) if "discussion_id" in data:
code = data["code"] data = (await request.json())
discussion_id = data.get("discussion_id","unknown_discussion") code = data["code"]
message_id = data.get("message_id","unknown_message") discussion_id = data.get("discussion_id","unknown_discussion")
language = data.get("language","python") message_id = data.get("message_id","unknown_message")
language = data.get("language","python")
ASCIIColors.info("Opening folder:") ASCIIColors.info("Opening folder:")
# Create a temporary file. # Create a temporary file.
root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}" root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}"
root_folder.mkdir(parents=True,exist_ok=True) root_folder.mkdir(parents=True,exist_ok=True)
tmp_file = root_folder/f"ai_code_{message_id}.py" tmp_file = root_folder/f"ai_code_{message_id}.py"
with open(tmp_file,"w") as f: with open(tmp_file,"w") as f:
f.write(code) f.write(code)
os.system('code ' + str(root_folder))
elif "folder_path" in data:
ASCIIColors.info("Opening folder:")
# Create a temporary file.
root_folder = data["folder_path"]
root_folder.mkdir(parents=True,exist_ok=True)
os.system('code ' + str(root_folder))
os.system('code ' + str(root_folder))
return {"output": "OK", "execution_time": 0} return {"output": "OK", "execution_time": 0}
except Exception as ex: except Exception as ex:
trace_exception(ex) trace_exception(ex)
@ -192,19 +200,33 @@ async def open_code_folder(request: Request):
try: try:
data = (await request.json()) data = (await request.json())
discussion_id = data.get("discussion_id","unknown_discussion") if "discussion_id" in data:
discussion_id = data.get("discussion_id","unknown_discussion")
ASCIIColors.info("Opening folder:")
# Create a temporary file.
root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}"
root_folder.mkdir(parents=True,exist_ok=True)
if platform.system() == 'Windows':
os.startfile(str(root_folder))
elif platform.system() == 'Linux':
os.system('xdg-open ' + str(root_folder))
elif platform.system() == 'Darwin':
os.system('open ' + str(root_folder))
return {"output": "OK", "execution_time": 0}
elif "folder_path" in data:
ASCIIColors.info("Opening folder:")
# Create a temporary file.
root_folder = data["folder_path"]
root_folder.mkdir(parents=True,exist_ok=True)
if platform.system() == 'Windows':
os.startfile(str(root_folder))
elif platform.system() == 'Linux':
os.system('xdg-open ' + str(root_folder))
elif platform.system() == 'Darwin':
os.system('open ' + str(root_folder))
return {"output": "OK", "execution_time": 0}
ASCIIColors.info("Opening folder:")
# Create a temporary file.
root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}"
root_folder.mkdir(parents=True,exist_ok=True)
if platform.system() == 'Windows':
os.startfile(str(root_folder))
elif platform.system() == 'Linux':
os.system('xdg-open ' + str(root_folder))
elif platform.system() == 'Darwin':
os.system('open ' + str(root_folder))
return {"output": "OK", "execution_time": 0}
except Exception as ex: except Exception as ex:
trace_exception(ex) trace_exception(ex)
lollmsElfServer.error(ex) lollmsElfServer.error(ex)

@ -1 +1 @@
Subproject commit 5cb7a7598716dbe733cb2cbbc911e87c50fdf9fb Subproject commit 3a2c5c3995076d2a415e79c23439dee92cb049ad