Update tests.py
Browse files
tests.py
CHANGED
|
@@ -221,20 +221,22 @@ def run_code(language:str,packages:str,filename: str, code: str,start_cmd:str,fo
|
|
| 221 |
"""
|
| 222 |
Execute code in a controlled environment with package installation and file handling.
|
| 223 |
Args:
|
| 224 |
-
language:Programming language of the code (
|
| 225 |
packages: Space-separated list of packages to install (e.g., "numpy matplotlib").
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
filename:
|
| 229 |
-
code:
|
| 230 |
-
start_cmd:
|
| 231 |
-
|
| 232 |
-
|
|
|
|
| 233 |
Notes:
|
| 234 |
- All user-uploaded files are in /app/code_interpreter/.
|
| 235 |
- After execution, embed a download link (or display images/gifs/videos directly in markdown format) in your response.
|
| 236 |
- bash/apk packages cannot be installed.
|
| 237 |
- When editing and subsequently re-executing the server with the forever_cmd='true' setting, the previous server instance will be automatically terminated, and the updated server will commence operation. This functionality negates the requirement for manual process termination commands such as pkill node.
|
|
|
|
| 238 |
|
| 239 |
"""
|
| 240 |
global destination_dir
|
|
@@ -253,7 +255,10 @@ def run_code(language:str,packages:str,filename: str, code: str,start_cmd:str,fo
|
|
| 253 |
f.write(code)
|
| 254 |
f.close()
|
| 255 |
global files_list
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
| 257 |
onlyfiles = glob.glob("/app/code_interpreter/*")
|
| 258 |
onlyfiles=list(set(onlyfiles)-set(files_list))
|
| 259 |
uploaded_filenames=[]
|
|
|
|
| 221 |
"""
|
| 222 |
Execute code in a controlled environment with package installation and file handling.
|
| 223 |
Args:
|
| 224 |
+
language:Programming language of the code (eg:"python", "nodejs", "bash","html",etc).
|
| 225 |
packages: Space-separated list of packages to install (e.g., "numpy matplotlib").
|
| 226 |
+
Preinstalled python packages: gradio, XlsxWriter, openpyxl , mpxj , jpype1.
|
| 227 |
+
Preinstalled npm packages: express, ejs, chart.js.
|
| 228 |
+
filename:Name of the file to create (stored in /app/code_interpreter/).
|
| 229 |
+
code:Full code to write to the file.
|
| 230 |
+
start_cmd:Command to execute the file (e.g., "python /app/code_interpreter/app.py"
|
| 231 |
+
or "bash /app/code_interpreter/app.py").
|
| 232 |
+
Leave blank ('') if only file creation is needed / start_cmd not required.
|
| 233 |
+
forever_cmd:If 'true', the command will run indefinitely.Set to 'true', when runnig a website/server.Run all servers/website on port 1337. If 'false', the command will time out after 300 second and the result will be returned.
|
| 234 |
Notes:
|
| 235 |
- All user-uploaded files are in /app/code_interpreter/.
|
| 236 |
- After execution, embed a download link (or display images/gifs/videos directly in markdown format) in your response.
|
| 237 |
- bash/apk packages cannot be installed.
|
| 238 |
- When editing and subsequently re-executing the server with the forever_cmd='true' setting, the previous server instance will be automatically terminated, and the updated server will commence operation. This functionality negates the requirement for manual process termination commands such as pkill node.
|
| 239 |
+
- The opened ports can be externally accessed at https://suitable-liked-ibex.ngrok-free.app/ (ONLY if the website is running successfully)
|
| 240 |
|
| 241 |
"""
|
| 242 |
global destination_dir
|
|
|
|
| 255 |
f.write(code)
|
| 256 |
f.close()
|
| 257 |
global files_list
|
| 258 |
+
if start_cmd != "" or start_cmd != " ":
|
| 259 |
+
stdot=run(start_cmd, 300,forever_cmd)
|
| 260 |
+
else:
|
| 261 |
+
stdot="File created successfully."
|
| 262 |
onlyfiles = glob.glob("/app/code_interpreter/*")
|
| 263 |
onlyfiles=list(set(onlyfiles)-set(files_list))
|
| 264 |
uploaded_filenames=[]
|