Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -134,11 +134,20 @@ class DocumentQATool(BaseTool):
|
|
134 |
|
135 |
class PythonExecutionTool(BaseTool):
|
136 |
name: str = "python_execution"
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
def _run(self, code: str) -> str:
|
139 |
print(f"DEBUG: Executing python_execution with code: {code}")
|
140 |
try:
|
141 |
local_vars = {}
|
|
|
|
|
142 |
exec(code, globals(), local_vars)
|
143 |
if '_result_value' in local_vars:
|
144 |
return str(local_vars['_result_value'])
|
@@ -147,7 +156,7 @@ class PythonExecutionTool(BaseTool):
|
|
147 |
return f"[Python Error] {str(e)}"
|
148 |
async def _arun(self, query: str) -> str:
|
149 |
raise NotImplementedError("Asynchronous execution not supported for now.")
|
150 |
-
|
151 |
class VideoTranscriptionTool(BaseTool):
|
152 |
name: str = "transcript_video"
|
153 |
description: str = "Transcribes video content from a given YouTube URL or video ID."
|
|
|
134 |
|
135 |
class PythonExecutionTool(BaseTool):
|
136 |
name: str = "python_execution"
|
137 |
+
# Option 1: Single line string (preferred for brevity)
|
138 |
+
description: str = "Executes Python code for complex calculations, data manipulation, or logical operations. Always assign the final result to a variable named '_result_value'."
|
139 |
+
|
140 |
+
# Option 2: Multi-line string using triple quotes (also valid)
|
141 |
+
# description: str = """Executes Python code for complex calculations,
|
142 |
+
# data manipulation, or logical operations. Always assign the final result
|
143 |
+
# to a variable named '_result_value'."""
|
144 |
+
|
145 |
def _run(self, code: str) -> str:
|
146 |
print(f"DEBUG: Executing python_execution with code: {code}")
|
147 |
try:
|
148 |
local_vars = {}
|
149 |
+
# It's generally unsafe to use `exec` with arbitrary user input due to security risks.
|
150 |
+
# For a real application, consider a sandboxed environment or a more restricted approach.
|
151 |
exec(code, globals(), local_vars)
|
152 |
if '_result_value' in local_vars:
|
153 |
return str(local_vars['_result_value'])
|
|
|
156 |
return f"[Python Error] {str(e)}"
|
157 |
async def _arun(self, query: str) -> str:
|
158 |
raise NotImplementedError("Asynchronous execution not supported for now.")
|
159 |
+
|
160 |
class VideoTranscriptionTool(BaseTool):
|
161 |
name: str = "transcript_video"
|
162 |
description: str = "Transcribes video content from a given YouTube URL or video ID."
|