new engines

This commit is contained in:
Saifeddine ALOUI 2024-02-05 23:50:40 +01:00
parent 6574384ac1
commit 152687337c
11 changed files with 310 additions and 17 deletions

View File

@ -27,6 +27,11 @@ import platform
from utilities.execution_engines.python_execution_engine import execute_python
from utilities.execution_engines.latex_execution_engine import execute_latex
from utilities.execution_engines.shell_execution_engine import execute_bash
from utilities.execution_engines.javascript_execution_engine import execute_javascript
from utilities.execution_engines.mermaid_execution_engine import execute_mermaid
from utilities.execution_engines.graphviz_execution_engine import execute_graphviz
# ----------------------- Defining router and main class ------------------------------
@ -50,15 +55,31 @@ async def execute_code(request: Request):
language = data.get("language","python")
ASCIIColors.info("Executing python code:")
ASCIIColors.yellow(code)
if language=="python":
ASCIIColors.info("Executing python code:")
ASCIIColors.yellow(code)
return execute_python(code, discussion_id, message_id)
if language=="javascript":
ASCIIColors.info("Executing javascript code:")
ASCIIColors.yellow(code)
return execute_javascript(code, discussion_id, message_id)
elif language=="latex":
ASCIIColors.info("Executing latex code:")
ASCIIColors.yellow(code)
return execute_latex(code, discussion_id, message_id)
elif language in ["bash","shell","cmd","powershell"]:
ASCIIColors.info("Executing shell code:")
ASCIIColors.yellow(code)
return execute_bash(code, discussion_id, message_id)
elif language in ["mermaid"]:
ASCIIColors.info("Executing mermaid code:")
ASCIIColors.yellow(code)
return execute_mermaid(code, discussion_id, message_id)
elif language in ["graphviz","dot"]:
ASCIIColors.info("Executing graphviz code:")
ASCIIColors.yellow(code)
return execute_graphviz(code, discussion_id, message_id)
return {"output": "Unsupported language", "execution_time": 0}
except Exception as ex:
trace_exception(ex)
@ -252,3 +273,4 @@ def stop_recording():
lollmsElfServer.info("Stopping audio capture")
text = lollmsElfServer.audio_cap.stop_recording()
return text

@ -1 +1 @@
Subproject commit d0975b0c6ad01b4385512755af32fa505c4f3bdb
Subproject commit 33ec48614462d8e3c3be21afe8dd7b70cec7c3f3

View File

@ -0,0 +1,66 @@
"""
project: lollms_webui
file: shell_execution_engine.py
author: ParisNeo
description:
This is a utility for executing python code
"""
from lollms_webui import LOLLMSWebUI
from ascii_colors import get_trace_exception, trace_exception
import time
import subprocess
import json
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
def build_graphviz_output(code, ifram_name="unnamed"):
"""
This function creates an HTML5 iframe with the given HTML content and iframe name.
Args:
html (str): The HTML content to be displayed in the iframe.
ifram_name (str, optional): The name of the iframe. Defaults to "unnamed".
Returns:
str: The HTML string for the iframe.
"""
# Start the timer.
start_time = time.time()
rendered = "\n".join([
'<div style="width: 100%; margin: 0 auto;">',
f'<iframe id="{ifram_name}" srcdoc=\'',
'<style>',
'.graph {',
'background-color: transparent;',
'padding: 20px;',
'border-radius: 10px;',
'display: flex;',
'justify-content: center;',
'align-items: center;',
'height: 100%;',
'}',
'</style>',
'<div id="graph" class="graph"></div>',
'<script src="https://github.com/mdaines/viz-js/releases/download/release-viz-3.2.4/viz-standalone.js"></script>',
'<script>',
'// Initialize the mermaid library and render our diagram',
'Viz.instance().then(function(viz) {',
'var svg = viz.renderSVGElement(`',
"\n".join([c.replace("'","\"") for c in code.split("\n") if c.strip()!=""]),
'`);',
'document.getElementById("graph").appendChild(svg);',
'});',
'</script>',
'<div style="text-align: center;">',
'</div>',
'\' style="width: 100%; height: 600px; border: none;"></iframe>',
'</div>'
]
)
execution_time = time.time() - start_time
return {"output": rendered, "execution_time": execution_time}
def execute_graphviz(code, discussion_id, message_id):
return build_graphviz_output(code)

View File

@ -0,0 +1,46 @@
"""
project: lollms_webui
file: shell_execution_engine.py
author: ParisNeo
description:
This is a utility for executing python code
"""
from lollms_webui import LOLLMSWebUI
from ascii_colors import get_trace_exception, trace_exception
import time
import subprocess
import json
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
def build_javascript_output(code, ifram_name="unnamed"):
"""
This function creates an HTML5 iframe with the given HTML content and iframe name.
Args:
html (str): The HTML content to be displayed in the iframe.
ifram_name (str, optional): The name of the iframe. Defaults to "unnamed".
Returns:
str: The HTML string for the iframe.
"""
# Start the timer.
start_time = time.time()
rendered = "\n".join([
'<div style="width: 100%; margin: 0 auto;">',
f'<iframe id="{ifram_name}" srcdoc="',
'<script>',
code,
'</script>',
'<div style=\'text-align: center;\'>',
'</div>,',
'" style="width: 100%; height: 600px; border: none;"></iframe>',
'</div>'
]
)
execution_time = time.time() - start_time
return {"output": rendered, "execution_time": execution_time}
def execute_javascript(code, discussion_id, message_id):
return build_javascript_output(code)

View File

@ -0,0 +1,63 @@
"""
project: lollms_webui
file: shell_execution_engine.py
author: ParisNeo
description:
This is a utility for executing python code
"""
from lollms_webui import LOLLMSWebUI
from ascii_colors import get_trace_exception, trace_exception
import time
import subprocess
import json
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
def build_mermaid_output(code, ifram_name="unnamed"):
"""
This function creates an HTML5 iframe with the given HTML content and iframe name.
Args:
html (str): The HTML content to be displayed in the iframe.
ifram_name (str, optional): The name of the iframe. Defaults to "unnamed".
Returns:
str: The HTML string for the iframe.
"""
# Start the timer.
start_time = time.time()
rendered = "\n".join([
'<div style="width: 100%; margin: 0 auto;">',
f'<iframe id="{ifram_name}" srcdoc="',
'<style>',
'.mermaid {',
'background-color: transparent;',
'padding: 20px;',
'border-radius: 10px;',
'display: flex;',
'justify-content: center;',
'align-items: center;',
'height: 100%;',
'}',
'</style>',
'<div class=\'mermaid\'>',
"\n".join([c for c in code.split("\n") if c.strip()!=""]),
'</div>',
'<script src=\'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js\'></script>',
'<script>',
'// Initialize the mermaid library and render our diagram',
'mermaid.initialize({ startOnLoad: true });',
'</script>',
'<div style=\'text-align: center;\'>',
'</div>',
'" style="width: 100%; height: 600px; border: none;"></iframe>',
'</div>'
]
)
execution_time = time.time() - start_time
return {"output": rendered, "execution_time": execution_time}
def execute_mermaid(code, discussion_id, message_id):
return build_mermaid_output(code)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 45 KiB

105
web/dist/assets/rec_on-f8235a7b.svg vendored Normal file
View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
xml:space="preserve"
inkscape:export-filename="bitmap.svg"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
sodipodi:docname="drawing.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="true"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="0.73139029"
inkscape:cx="396.50513"
inkscape:cy="561.25984"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer2" /><defs
id="defs1"><pattern
inkscape:collect="always"
xlink:href="#pattern6-7"
preserveAspectRatio="xMidYMid"
id="pattern20"
patternTransform="translate(190,350)" /><pattern
inkscape:collect="always"
xlink:href="#pattern6-7"
preserveAspectRatio="xMidYMid"
id="pattern19"
patternTransform="translate(190,350)" /><pattern
patternUnits="userSpaceOnUse"
width="29"
height="20"
patternTransform="translate(190,350)"
preserveAspectRatio="xMidYMid"
style="fill:#000000"
id="pattern6-7"
inkscape:label=""
inkscape:collect="always"
inkscape:isstock="true"><path
style="fill:none;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-dasharray:none;paint-order:stroke markers fill;stop-color:#000000"
d="M 0,5 C 19,5 10,15 29,15"
id="path4-2"
sodipodi:nodetypes="cc" /></pattern></defs><g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"><g
transform="matrix(0.02583208,0,0,-0.02538984,5.2493106,222.7147)"
fill="#000000"
stroke="none"
id="g8"><path
d="m 505,4469 c -43,-12 -102,-64 -128,-112 -21,-41 -22,-52 -25,-419 -3,-338 -1,-381 14,-413 33,-70 128,-88 186,-36 l 33,29 3,361 3,360 354,3 c 342,3 355,4 382,24 34,26 58,83 49,120 -4,15 -22,42 -41,61 l -33,33 -384,-1 c -210,0 -396,-5 -413,-10 z"
id="path1" /><path
d="m 6606,4449 c -45,-39 -55,-84 -30,-136 35,-71 44,-73 431,-73 h 342 l 3,-361 3,-361 33,-29 c 58,-52 153,-34 186,36 15,32 17,75 14,413 -3,367 -4,378 -25,419 -27,50 -86,100 -133,113 -20,6 -198,10 -412,10 h -377 z"
id="path2" /><path
d="m 1631,3719 c -278,-54 -497,-253 -582,-529 -31,-98 -34,-299 -6,-400 40,-149 130,-291 243,-384 132,-109 274,-164 444,-173 351,-18 654,194 760,532 34,107 39,276 11,385 -40,164 -133,312 -256,413 -77,64 -219,131 -317,151 -82,17 -225,19 -297,5 z"
id="path3" /><path
d="m 5921,3719 c -270,-53 -462,-246 -525,-529 -50,-221 -16,-475 85,-647 19,-32 66,-89 104,-128 125,-126 285,-185 502,-185 314,0 543,154 618,413 26,90 29,88 -146,85 l -151,-3 -19,-49 c -21,-56 -77,-119 -129,-146 -84,-43 -229,-50 -330,-15 -104,36 -187,128 -231,255 -19,54 -23,87 -23,200 -1,147 9,198 55,290 75,151 237,228 417,200 120,-20 202,-83 242,-188 l 18,-47 156,-3 c 175,-3 164,-9 141,78 -56,211 -221,365 -442,414 -78,17 -266,20 -342,5 z"
id="path4" /><path
d="m 2975,3698 c -3,-7 -4,-335 -3,-728 l 3,-715 143,-3 142,-3 v 281 280 h 98 98 l 131,-277 130,-278 161,-3 c 140,-2 162,0 162,13 0,8 -63,141 -140,295 -77,154 -140,283 -140,287 0,5 25,21 55,36 246,129 289,498 81,695 -67,63 -137,97 -241,117 -103,20 -673,22 -680,3 z m 650,-260 c 67,-36 105,-102 105,-183 0,-94 -39,-161 -115,-196 -33,-16 -66,-19 -197,-19 h -158 v 211 211 l 168,-4 c 130,-3 174,-7 197,-20 z"
id="path5" /><path
d="m 4245,3698 c -3,-7 -4,-335 -3,-728 l 3,-715 478,-3 477,-2 v 120 120 h -335 -335 v 190 190 l 303,2 302,3 v 115 115 l -302,3 -303,2 v 180 180 h 335 335 v 120 120 h -475 c -371,0 -477,-3 -480,-12 z"
id="path6" /><path
d="m 409,2485 c -15,-8 -34,-30 -43,-50 -15,-32 -17,-75 -14,-413 3,-367 4,-378 25,-419 27,-51 82,-96 132,-112 26,-7 162,-11 414,-11 h 376 l 35,31 c 45,39 55,84 30,136 -35,71 -44,73 -431,73 H 591 l -3,361 -3,361 -33,29 c -37,33 -97,39 -143,14 z"
id="path7" /><path
d="m 7388,2471 -33,-29 -3,-361 -3,-361 h -342 c -387,0 -396,-2 -431,-73 -25,-52 -15,-97 30,-136 l 35,-31 h 376 c 252,0 388,4 414,11 50,16 105,61 132,112 21,41 22,52 25,419 3,338 1,381 -14,413 -33,70 -128,88 -186,36 z"
id="path8" /></g><path
style="fill:#000000;stroke-width:1.36726"
d="m 178.42731,625.49092 c -27.25137,-5.46989 -49.08276,-26.05162 -56.06414,-52.85493 -9.49876,-36.46822 14.50171,-76.07706 52.01917,-85.84912 21.29289,-5.54609 47.02477,0.19022 64.92177,14.47277 8.0352,6.41242 18.34576,21.53181 22.10793,32.41906 4.30468,12.45716 4.28346,32.69217 -0.0468,44.67188 -3.76993,10.42943 -13.73585,25.09561 -21.14419,31.1165 -17.3789,14.12413 -40.88738,20.22015 -61.7937,16.02384 z"
id="path9"
transform="scale(0.26458333)" /></g><g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer 2"><path
style="fill:#ff0000;stroke-width:1.36726"
d="m 177.06005,625.37926 c -25.26183,-5.11902 -47.98402,-26.97088 -54.64772,-52.55453 -8.0771,-31.01008 8.01124,-65.64386 37.29985,-80.29635 12.66708,-6.33708 22.65747,-8.34652 37.17312,-7.47689 26.5606,1.59124 49.40113,16.59784 60.84478,39.97599 18.67442,38.14984 -0.47922,83.62556 -41.22311,97.8744 -9.3945,3.28542 -29.29247,4.53506 -39.44692,2.47738 z"
id="path10"
transform="scale(0.26458333)" /><path
style="fill:url(#pattern20);fill-opacity:1;stroke-width:1.36726"
d="m 313.44414,624.5561 -3.07633,-0.59253 v -68.08896 -68.08897 l 5.12722,-0.84747 c 7.62433,-1.26023 40.34287,-1.00795 53.86576,0.41532 14.51368,1.52756 23.62457,5.29292 30.974,12.80096 18.70532,19.10901 14.46385,52.41469 -8.1438,63.94825 -2.89117,1.47496 -5.25668,3.5983 -5.25668,4.71853 0,1.12022 5.86298,13.75039 13.02885,28.06704 7.16587,14.31665 12.66696,26.61584 12.22464,27.33151 -0.87782,1.42035 -19.53365,1.5034 -25.61688,0.11403 -3.3518,-0.76554 -5.20579,-3.85466 -16.31452,-27.18342 l -12.53298,-26.31973 h -10.00521 -10.00522 v 27.34518 27.34518 l -10.59626,-0.1862 c -5.82794,-0.1024 -11.98061,-0.45283 -13.67259,-0.77872 z m 60.79781,-76.5176 c 6.78546,-3.21991 9.94652,-9.05285 9.95273,-18.36524 0.006,-9.42731 -3.9787,-16.1715 -10.9803,-18.58302 -2.60594,-0.89754 -11.65981,-1.66663 -20.11973,-1.70907 l -15.38166,-0.0772 v 20.50888 20.50889 h 15.85866 c 11.98158,0 17.035,-0.55821 20.6703,-2.28327 z"
id="path11"
transform="scale(0.26458333)" /><path
style="fill:url(#pattern19);fill-opacity:1;stroke-width:1.36726"
d="m 313.44414,624.5561 -3.07633,-0.59253 v -68.08896 -68.08897 l 5.12722,-0.84747 c 7.62433,-1.26023 40.34287,-1.00795 53.86576,0.41532 14.51368,1.52756 23.62457,5.29292 30.974,12.80096 18.70532,19.10901 14.46385,52.41469 -8.1438,63.94825 -2.89117,1.47496 -5.25668,3.5983 -5.25668,4.71853 0,1.12022 5.86298,13.75039 13.02885,28.06704 7.16587,14.31665 12.66696,26.61584 12.22464,27.33151 -0.87782,1.42035 -19.53365,1.5034 -25.61688,0.11403 -3.3518,-0.76554 -5.20579,-3.85466 -16.31452,-27.18342 l -12.53298,-26.31973 h -10.00521 -10.00522 v 27.34518 27.34518 l -10.59626,-0.1862 c -5.82794,-0.1024 -11.98061,-0.45283 -13.67259,-0.77872 z m 60.79781,-76.5176 c 6.78546,-3.21991 9.94652,-9.05285 9.95273,-18.36524 0.006,-9.42731 -3.9787,-16.1715 -10.9803,-18.58302 -2.60594,-0.89754 -11.65981,-1.66663 -20.11973,-1.70907 l -15.38166,-0.0772 v 20.50888 20.50889 h 15.85866 c 11.98158,0 17.035,-0.55821 20.6703,-2.28327 z"
id="path12"
transform="scale(0.26458333)" /></g></svg>

After

Width:  |  Height:  |  Size: 8.0 KiB

2
web/dist/index.html vendored
View File

@ -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-14ee3a3f.js"></script>
<script type="module" crossorigin src="/assets/index-03f6cf4a.js"></script>
<link rel="stylesheet" href="/assets/index-d55ae77e.css">
</head>
<body>

View File

@ -7,7 +7,7 @@
class="px-2 py-1 ml-2 text-left p-2 text-sm font-medium rounded-lg hover:bg-primary dark:hover:bg-primary text-white text-xs transition-colors duration-200">
<i data-feather="copy"></i>
</button>
<button v-if="['python', 'sh', 'shell', 'bash', 'cmd', 'powershell', 'latex'].includes(language)" ref="btn_code_exec" @click="executeCode" title="execute"
<button v-if="['python', 'sh', 'shell', 'bash', 'cmd', 'powershell', 'latex', 'mermaid', 'graphviz', 'dot', 'javascript'].includes(language)" ref="btn_code_exec" @click="executeCode" title="execute"
class="px-2 py-1 ml-2 text-left p-2 text-sm font-medium bg-bg-dark-tone-panel dark:bg-bg-dark-tone rounded-lg hover:bg-primary dark:hover:bg-primary text-white text-xs transition-colors duration-200"
:class="isExecuting?'bg-green-500':''">
<i data-feather="play-circle"></i>

@ -1 +1 @@
Subproject commit d1c3a725c0e41f8f1169288112c4ef732dd945b2
Subproject commit 06c46eea3cb104d6158438f9f5f8fd65c40bad3e