You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: open-webui/tools/run_code.py
+26-16Lines changed: 26 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -126,13 +126,21 @@ async def run_bash_command(
126
126
127
127
:param bash_command: Bash command or script to run.
128
128
129
-
:return: A JSON object with the following fields: `status`, `output`. In most cases, when `status` is "OK", the user is interested in the content of the `output` field. Otherwise, report the `status` field first.
129
+
:return: A JSON object with the following fields: `bash_command`, `status`, `output`. In most cases, when `status` is "OK", the user is interested in the content of the `output` field. Otherwise, report the `status` field first.
130
130
"""
131
-
returnawaitself._run_code(
131
+
result=awaitself._run_code(
132
132
language=Sandbox.LANGUAGE_BASH,
133
133
code=bash_command,
134
134
event_emitter=__event_emitter__,
135
135
)
136
+
returnjson.dumps(
137
+
{
138
+
"bash_command": bash_command,
139
+
"status": result["status"],
140
+
"output": result["output"],
141
+
},
142
+
ensure_ascii=False,
143
+
)
136
144
137
145
asyncdefrun_python_code(
138
146
self,
@@ -144,13 +152,21 @@ async def run_python_code(
144
152
145
153
:param python_code: Python code to run.
146
154
147
-
:return: A JSON object with the following fields: `status`, `output`. In most cases, when `status` is "OK", the user is interested in the content of the `output` field. Otherwise, report the `status` field first.
155
+
:return: A JSON object with the following fields: `python_code`, `status`, `output`. In most cases, when `status` is "OK", the user is interested in the content of the `output` field. Otherwise, report the `status` field first.
148
156
"""
149
-
returnawaitself._run_code(
157
+
result=awaitself._run_code(
150
158
language=Sandbox.LANGUAGE_PYTHON,
151
159
code=python_code,
152
160
event_emitter=__event_emitter__,
153
161
)
162
+
returnjson.dumps(
163
+
{
164
+
"python_code": python_code,
165
+
"status": result["status"],
166
+
"output": result["output"],
167
+
},
168
+
ensure_ascii=False,
169
+
)
154
170
155
171
class_EventEmitter:
156
172
"""
@@ -251,7 +267,7 @@ async def _run_code(
251
267
:param code: The code to run.
252
268
:param event_emitter: Event emitter to send status updates to.
253
269
254
-
:return: A JSON object with the following fields: `status`, `output`. In most cases, when `status` is "OK", the user is interested in the content of the `output` field. Otherwise, report the `status` field first.
270
+
:return: A dictionary with the following fields: `status`, `output`.
0 commit comments