Update Modules/Agent_Terminal.py
Browse files- Modules/Agent_Terminal.py +4 -19
Modules/Agent_Terminal.py
CHANGED
|
@@ -4,7 +4,7 @@ import os
|
|
| 4 |
import sys
|
| 5 |
import ast
|
| 6 |
from io import StringIO
|
| 7 |
-
from typing import Annotated
|
| 8 |
import importlib.metadata
|
| 9 |
|
| 10 |
import gradio as gr
|
|
@@ -92,18 +92,7 @@ TOOL_SUMMARY = (
|
|
| 92 |
"Available tools: `Web_Fetch`, `Web_Search`, `Code_Interpreter`, `Shell_Command`, `File_System`, `Obsidian_Vault`, `Memory_Manager`, `Generate_Speech`, `Generate_Image`, `Generate_Video`, `Deep_Research`."
|
| 93 |
)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
if isinstance(val, str) and os.path.exists(val) and os.path.isfile(val):
|
| 97 |
-
try:
|
| 98 |
-
abs_path = os.path.abspath(val)
|
| 99 |
-
# Normalize slashes
|
| 100 |
-
normalized_path = abs_path.replace('\\', '/')
|
| 101 |
-
return f"/file={normalized_path}"
|
| 102 |
-
except Exception:
|
| 103 |
-
return val
|
| 104 |
-
elif isinstance(val, (list, tuple)):
|
| 105 |
-
return type(val)(_convert_to_url_if_path(v) for v in val)
|
| 106 |
-
return val
|
| 107 |
|
| 108 |
@autodoc(
|
| 109 |
summary=TOOL_SUMMARY,
|
|
@@ -125,10 +114,6 @@ def Agent_Terminal(code: Annotated[str, (
|
|
| 125 |
old_cwd = os.getcwd()
|
| 126 |
redirected_output = sys.stdout = StringIO()
|
| 127 |
|
| 128 |
-
def custom_print(*args, **kwargs):
|
| 129 |
-
new_args = [_convert_to_url_if_path(arg) for arg in args]
|
| 130 |
-
print(*new_args, **kwargs)
|
| 131 |
-
|
| 132 |
# Prepare the execution environment with all tools
|
| 133 |
tools_env = {
|
| 134 |
"Web_Fetch": Web_Fetch,
|
|
@@ -147,7 +132,7 @@ def Agent_Terminal(code: Annotated[str, (
|
|
| 147 |
"search_tools": search_tools,
|
| 148 |
"usage": usage,
|
| 149 |
"search_packages": search_packages,
|
| 150 |
-
"print":
|
| 151 |
"__builtins__": __builtins__,
|
| 152 |
}
|
| 153 |
|
|
@@ -167,7 +152,7 @@ def Agent_Terminal(code: Annotated[str, (
|
|
| 167 |
expr = compile(ast.Expression(last_node.value), filename="<string>", mode="eval")
|
| 168 |
result_val = eval(expr, tools_env)
|
| 169 |
if result_val is not None:
|
| 170 |
-
|
| 171 |
else:
|
| 172 |
exec(code, tools_env)
|
| 173 |
|
|
|
|
| 4 |
import sys
|
| 5 |
import ast
|
| 6 |
from io import StringIO
|
| 7 |
+
from typing import Annotated
|
| 8 |
import importlib.metadata
|
| 9 |
|
| 10 |
import gradio as gr
|
|
|
|
| 92 |
"Available tools: `Web_Fetch`, `Web_Search`, `Code_Interpreter`, `Shell_Command`, `File_System`, `Obsidian_Vault`, `Memory_Manager`, `Generate_Speech`, `Generate_Image`, `Generate_Video`, `Deep_Research`."
|
| 93 |
)
|
| 94 |
|
| 95 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
@autodoc(
|
| 98 |
summary=TOOL_SUMMARY,
|
|
|
|
| 114 |
old_cwd = os.getcwd()
|
| 115 |
redirected_output = sys.stdout = StringIO()
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Prepare the execution environment with all tools
|
| 118 |
tools_env = {
|
| 119 |
"Web_Fetch": Web_Fetch,
|
|
|
|
| 132 |
"search_tools": search_tools,
|
| 133 |
"usage": usage,
|
| 134 |
"search_packages": search_packages,
|
| 135 |
+
"print": print, # Ensure print is available
|
| 136 |
"__builtins__": __builtins__,
|
| 137 |
}
|
| 138 |
|
|
|
|
| 152 |
expr = compile(ast.Expression(last_node.value), filename="<string>", mode="eval")
|
| 153 |
result_val = eval(expr, tools_env)
|
| 154 |
if result_val is not None:
|
| 155 |
+
print(result_val)
|
| 156 |
else:
|
| 157 |
exec(code, tools_env)
|
| 158 |
|