Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix yield; Cleanup
Tomas Valenta1d73fe097948
diff --git a/api-service/codegen/tools/playground/main.py b/api-service/codegen/tools/playground/main.pyindex 56a3cfee2..347301ef1 100644--- a/api-service/codegen/tools/playground/main.py+++ b/api-service/codegen/tools/playground/main.py@@ -5,6 +5,7 @@ from .tools.filesystem import create_filesystem_toolsfrom .tools.process import create_process_toolsfrom .tools.code import create_code_tools+# TODO: Specify that the environmetn is persistent between tools' invocations?# TODO: Use ubuntu instead of alpine?def create_playground_tools() -> tuple[List[Any], Playground]:diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.pyindex 8363593f8..e2f4973d3 100644--- a/api-service/codegen/tools/playground/tools/code.py+++ b/api-service/codegen/tools/playground/tools/code.py@@ -8,21 +8,22 @@ def extract_code(code: str):return code.strip().strip("`").strip()def create_code_tools(playground: NodeJSPlayground):- # TODO: Escape command+ # Ensure that the function is a generator even if no tools are yielded+ yield from []+@tool("InstallNPMDependencies")def install_dependencies(dependencies: str) -> str:"""Install specified dependecies with NPM and return errors.The input should be a list of Node.js dependencies separated by spaces.- If there are no errors the returned result will be an empty string.If you are using this tool to handle missing dependency error try to run the code again after the installation."""output = playground.install_dependencies(extract_code(dependencies))- return encode_command_output(output, only_errors=True)+ result = encode_command_output(output, only_errors=True)+ return result if len(result) > 0 else "All dependencies installed"yield install_dependencies- # # TODO: Escape code@tool("RunTypeScriptCode")def run_typescript_code(code: str) -> str:"""@@ -31,33 +32,32 @@ def create_code_tools(playground: NodeJSPlayground):The returned result will be the output and errors returned when executing the code."""output = playground.run_typescript_code(extract_code(code))- return encode_command_output(output)+ result = encode_command_output(output)++ return result if len(result) > 0 else "Code execution finished without error"yield run_typescript_code- # TODO: Escape code@tool("CheckTypeScriptCodeTypes")def check_typescript_code_types(code: str) -> str:"""Check TypeScript types in the specified code and return errors.- If there are no errors the returned result will be an empty string."""output = playground.check_typescript_code(extract_code(code))- return encode_command_output(output, only_errors=True)+ result = encode_command_output(output, only_errors=True)++ return result if len(result) > 0 else "Typechecking finished without error"yield check_typescript_code_types- # TODO: Escape code@tool("RunJavaScriptCode")def run_javascript_code(code: str) -> str:"""Run the specified JavaScript code and return errors and output."""-- print('CODE')- print(extract_code(code))output = playground.run_javascript_code(extract_code(code))- return encode_command_output(output)+ result = encode_command_output(output)+ return result if len(result) > 0 else "Code execution finished without error"yield run_javascript_codediff --git a/api-service/codegen/tools/playground/tools/filesystem.py b/api-service/codegen/tools/playground/tools/filesystem.pyindex bf030b0c5..0bd1b8f64 100644--- a/api-service/codegen/tools/playground/tools/filesystem.py+++ b/api-service/codegen/tools/playground/tools/filesystem.py@@ -10,6 +10,9 @@ def encode_directory_listing(entries: List[EntryInfo]) -> str:def create_filesystem_tools(playground: NodeJSPlayground):+ # Ensure that the function is a generator even if no tools are yielded+ yield from []+@tool("ReadFile")def read_file(path: str) -> str:"""Read content of the file from filesystem."""@@ -18,23 +21,23 @@ def create_filesystem_tools(playground: NodeJSPlayground):yield read_file# TODO: Escape file content?- @tool("WriteFile")- def write_file(input: str) -> str:- """Write content to a file in the filesystem.+ @tool("SaveFile")+ def save_file(input: str) -> str:+ """Save content to a file in the filesystem.The input should be a path to a file followed by the content of the file.Separate the path and content by a newline character."""path, content = input.split("\n", 1)playground.write_file(path, content)- return ""+ return "File saved"- yield write_file+ yield save_file@tool("DeleteFile")def delete_file(path: str) -> str:"""Delete the file."""playground.delete_file(path)- return ""+ return "File deleted"yield delete_file@@ -50,6 +53,6 @@ def create_filesystem_tools(playground: NodeJSPlayground):def delete_directory(path: str) -> str:"""Delete the directory."""playground.delete_dir(path)- return ""+ return "Directory deleted"yield delete_directorydiff --git a/api-service/codegen/tools/playground/tools/process.py b/api-service/codegen/tools/playground/tools/process.pyindex 1b0ed243a..18cb8d771 100644--- a/api-service/codegen/tools/playground/tools/process.py+++ b/api-service/codegen/tools/playground/tools/process.py@@ -26,17 +26,20 @@ def encode_command_output(response: RunProcessResponse, only_errors: bool = Falsdef create_process_tools(playground: NodeJSPlayground):- # TODO: Escape command+ # Ensure that the function is a generator even if no tools are yielded+ yield from []++ # TODO: Escape command?@tool("RunTerminalCommand")def run_terminal_command(command: str) -> str:"""Run specified command in the terminal and return output and errors.The input should be a a valid terminal command.- The environment where the command runs is Alpine Linux.- It has access to the internet and to basic utility tools like `curl`.The returned result will be the output and errors returned when running the command."""output = playground.run_command(command)- return encode_command_output(output)+ result = encode_command_output(output)++ return result if len(result) > 0 else "Process finished without error"- yield run_terminal_command+ # yield run_terminal_commsand