mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-18 20:17:50 +00:00
enhanced ui
This commit is contained in:
parent
54af20130e
commit
0bb3c2f884
@ -54,6 +54,7 @@ lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
|
||||
class CodeRequest(BaseModel):
|
||||
client_id: str = Field(...)
|
||||
code: str = Field(..., description="Code to be executed")
|
||||
discussion_id: int = Field(..., description="Discussion ID")
|
||||
message_id: int = Field(..., description="Message ID")
|
||||
@ -67,7 +68,7 @@ async def execute_code(request: CodeRequest):
|
||||
:param request: The HTTP request object.
|
||||
:return: A JSON response with the status of the operation.
|
||||
"""
|
||||
|
||||
client = lollmsElfServer.session.get_client(request.client_id)
|
||||
if lollmsElfServer.config.headless_server_mode:
|
||||
return {"status":False,"error":"Code execution is blocked when in headless mode for obvious security reasons!"}
|
||||
|
||||
@ -90,7 +91,7 @@ async def execute_code(request: CodeRequest):
|
||||
if language=="python":
|
||||
ASCIIColors.info("Executing python code:")
|
||||
ASCIIColors.yellow(code)
|
||||
return execute_python(code, discussion_id, message_id)
|
||||
return execute_python(code, client, message_id)
|
||||
if language=="javascript":
|
||||
ASCIIColors.info("Executing javascript code:")
|
||||
ASCIIColors.yellow(code)
|
||||
@ -247,7 +248,7 @@ async def open_code_in_vs_code(vs_code_data: VSCodeData):
|
||||
f.write(code)
|
||||
|
||||
# Use subprocess.Popen to safely open the file
|
||||
subprocess.Popen(["code", str(root_folder)], shell=True)
|
||||
subprocess.Popen(["code", str(tmp_file)], shell=True)
|
||||
|
||||
return {"status": True, "execution_time": 0}
|
||||
except Exception as ex:
|
||||
@ -280,39 +281,17 @@ async def open_code_folder(request: FolderRequest):
|
||||
return {"status":False,"error":"User refused the opeining folder!"}
|
||||
|
||||
try:
|
||||
if request.discussion_id:
|
||||
discussion_id = request.discussion_id
|
||||
|
||||
ASCIIColors.info("Opening folder:")
|
||||
# Create a temporary file.
|
||||
root_folder = client.discussion.discussion_folder
|
||||
root_folder.mkdir(parents=True, exist_ok=True)
|
||||
if platform.system() == 'Windows':
|
||||
subprocess.run(['start', str(root_folder)], check=True)
|
||||
elif platform.system() == 'Linux':
|
||||
subprocess.run(['xdg-open', str(root_folder)], check=True)
|
||||
elif platform.system() == 'Darwin':
|
||||
subprocess.run(['open', str(root_folder)], check=True)
|
||||
return {"status": True, "execution_time": 0}
|
||||
elif request.folder_path:
|
||||
folder_path = os.path.realpath(request.folder_path)
|
||||
# Verify that this is a file and not an executable
|
||||
root_folder = Path(folder_path)
|
||||
is_valid_folder_path = root_folder.is_dir()
|
||||
|
||||
if not is_valid_folder_path:
|
||||
return {"status":False, "error":"Invalid folder path"}
|
||||
|
||||
ASCIIColors.info("Opening folder:")
|
||||
# Create a temporary file.
|
||||
root_folder.mkdir(parents=True, exist_ok=True)
|
||||
if platform.system() == 'Windows':
|
||||
subprocess.run(['start', str(root_folder)], check=True)
|
||||
elif platform.system() == 'Linux':
|
||||
subprocess.run(['xdg-open', str(root_folder)], check=True)
|
||||
elif platform.system() == 'Darwin':
|
||||
subprocess.run(['open', str(root_folder)], check=True)
|
||||
return {"status": True, "execution_time": 0}
|
||||
ASCIIColors.info("Opening folder:")
|
||||
# Create a temporary file.
|
||||
root_folder = client.discussion.discussion_folder
|
||||
root_folder.mkdir(parents=True, exist_ok=True)
|
||||
if platform.system() == 'Windows':
|
||||
subprocess.run(['start', '"'+str(root_folder)+'"'], check=True)
|
||||
elif platform.system() == 'Linux':
|
||||
subprocess.run(['xdg-open', str(root_folder)], check=True)
|
||||
elif platform.system() == 'Darwin':
|
||||
subprocess.run(['open', str(root_folder)], check=True)
|
||||
return {"status": True, "execution_time": 0}
|
||||
|
||||
except Exception as ex:
|
||||
trace_exception(ex)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 1e0e91ed945f0f9b44b68e137c4b99d621a363f6
|
||||
Subproject commit f7bc693b355706a20acd792d0fbd45975cbbf82e
|
@ -11,6 +11,8 @@ from ascii_colors import get_trace_exception, trace_exception
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
|
@ -11,6 +11,8 @@ from ascii_colors import get_trace_exception, trace_exception
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
|
@ -11,6 +11,8 @@ from ascii_colors import get_trace_exception, trace_exception
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
|
@ -23,10 +23,13 @@ import shutil
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
from lollms.utilities import discussion_path_2_url
|
||||
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
def execute_latex(code, discussion_id, message_id):
|
||||
def execute_latex(code, client:Client, message_id):
|
||||
def spawn_process(code):
|
||||
"""Executes Python code and returns the output as JSON."""
|
||||
|
||||
@ -34,7 +37,7 @@ def execute_latex(code, discussion_id, message_id):
|
||||
start_time = time.time()
|
||||
|
||||
# Create a temporary file.
|
||||
root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}"
|
||||
root_folder = client.discussion.discussion_folder
|
||||
root_folder.mkdir(parents=True,exist_ok=True)
|
||||
tmp_file = root_folder/f"latex_file_{message_id}.tex"
|
||||
with open(tmp_file,"w",encoding="utf8") as f:
|
||||
@ -70,11 +73,12 @@ def execute_latex(code, discussion_id, message_id):
|
||||
|
||||
# The child process was successful.
|
||||
pdf_file=str(pdf_file).replace("\\","/")
|
||||
if not "http" in lollmsElfServer.config.host:
|
||||
if not "http" in lollmsElfServer.config.host and not "https" in lollmsElfServer.config.host:
|
||||
host = "http://"+lollmsElfServer.config.host
|
||||
else:
|
||||
host = lollmsElfServer.config.host
|
||||
url = f"{host}:{lollmsElfServer.config.port}/{pdf_file[pdf_file.index('outputs'):]}"
|
||||
|
||||
url = f"{host}:{lollmsElfServer.config.port}/{discussion_path_2_url(pdf_file)}"
|
||||
output_json = {"output": f"Pdf file generated at: {pdf_file}\n<a href='{url}'>Click here to show</a>", "execution_time": execution_time}
|
||||
return output_json
|
||||
return spawn_process(code)
|
||||
|
@ -11,6 +11,8 @@ from ascii_colors import get_trace_exception, trace_exception
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
|
@ -12,10 +12,11 @@ from ascii_colors import get_trace_exception, trace_exception
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
def execute_python(code, discussion_id, message_id):
|
||||
def execute_python(code, client:Client, message_id):
|
||||
def spawn_process(code):
|
||||
"""Executes Python code and returns the output as JSON."""
|
||||
|
||||
@ -23,7 +24,7 @@ def execute_python(code, discussion_id, message_id):
|
||||
start_time = time.time()
|
||||
|
||||
# Create a temporary file.
|
||||
root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}"
|
||||
root_folder = client.discussion.discussion_folder
|
||||
root_folder.mkdir(parents=True,exist_ok=True)
|
||||
tmp_file = root_folder/f"ai_code_{message_id}.py"
|
||||
with open(tmp_file,"w",encoding="utf8") as f:
|
||||
|
@ -11,9 +11,11 @@ from ascii_colors import get_trace_exception, trace_exception
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
from lollms.client_session import Client
|
||||
|
||||
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
def execute_bash(code, discussion_id, message_id):
|
||||
def execute_bash(code, client:Client):
|
||||
def spawn_process(code):
|
||||
"""Executes Python code and returns the output as JSON."""
|
||||
|
||||
@ -21,7 +23,7 @@ def execute_bash(code, discussion_id, message_id):
|
||||
start_time = time.time()
|
||||
|
||||
# Create a temporary file.
|
||||
root_folder = lollmsElfServer.lollms_paths.personal_outputs_path/"discussions"/f"d_{discussion_id}"
|
||||
root_folder = client.discussion.discussion_folder
|
||||
root_folder.mkdir(parents=True,exist_ok=True)
|
||||
try:
|
||||
# Execute the Python code in a temporary file.
|
||||
|
File diff suppressed because one or more lines are too long
2
web/dist/index.html
vendored
2
web/dist/index.html
vendored
@ -6,7 +6,7 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LoLLMS WebUI - Welcome</title>
|
||||
<script type="module" crossorigin src="/assets/index-d102c559.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-36f2b02c.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-13bf9073.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -168,7 +168,12 @@ export default {
|
||||
});
|
||||
},
|
||||
openFolderVsCode(){
|
||||
const json = JSON.stringify({'client_id': this.client_id, 'code': this.code, 'discussion_id': this.discussion_id, 'message_id': this.message_id})
|
||||
const json = JSON.stringify({
|
||||
'client_id': this.client_id,
|
||||
'code': this.code,
|
||||
'discussion_id': this.discussion_id,
|
||||
'message_id': this.message_id
|
||||
})
|
||||
console.log(json)
|
||||
fetch(`${this.host}/open_code_in_vs_code`, {
|
||||
method: 'POST',
|
||||
@ -188,7 +193,12 @@ export default {
|
||||
});
|
||||
},
|
||||
openVsCode() {
|
||||
const json = JSON.stringify({ 'client_id': this.client_id, 'code': this.code, 'discussion_id': this.discussion_id, 'message_id': this.message_id})
|
||||
const json = JSON.stringify({
|
||||
'client_id': this.client_id,
|
||||
'discussion_id': this.discussion_id,
|
||||
'message_id': this.message_id,
|
||||
'code': this.code
|
||||
})
|
||||
console.log(json)
|
||||
fetch(`${this.host}/open_code_folder_in_vs_code`, {
|
||||
method: 'POST',
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 707b72d65845e00b40080d26108390e8aea03305
|
||||
Subproject commit 715f5c8dff08adaee16376ef19252eef79cec00e
|
@ -1 +1 @@
|
||||
Subproject commit b372f934da4c9cc5b261a9d8f36b5df6a7488b66
|
||||
Subproject commit c061fa1e213bc0114a117542408c6547e9a39a44
|
Loading…
Reference in New Issue
Block a user