Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add playground tools [WIP]
Tomáš Valentadd81bdc9214f
diff --git a/api-service/app.py b/api-service/app.pyindex 96389fad6..dfa2cb90d 100644--- a/api-service/app.py+++ b/api-service/app.py@@ -51,8 +51,9 @@ def generate():playground = NodeJSPlayground()final_prompt, js_code = generate_req_handler(- run_id=run_id,db=db,+ playground=playground,+ run_id=run_id,blocks=blocks,method=method,)diff --git a/api-service/codegen/base.py b/api-service/codegen/base.pyindex 66c9c240c..c6bc23649 100644--- a/api-service/codegen/base.py+++ b/api-service/codegen/base.py@@ -1,15 +1,16 @@from typing import List+from playground_client import NodeJSPlaygroundfrom langchain.llms.openai import OpenAIChat, OpenAI-from codegen.tools.javascript.tool import JavascriptEvalToolfrom codegen.tools.documentation.tool import ReadDocumentationfrom codegen.js_agent.base import create_js_agentfrom codegen.prompt import PREFIX, SUFFIXfrom codegen.db.base import Database-+from codegen.tools.playground import create_playground_toolsdef generate_req_handler(db: Database,+ playground: NodeJSPlayground,run_id: str,blocks: List[str],method: str,@@ -20,8 +21,10 @@ def generate_req_handler(llm=OpenAI(temperature=0, max_tokens=1000),# llm=OpenAI(temperature=0, model_name='code-davinci-002', max_tokens=1000),# llm=OpenAIChat(temperature=0, max_tokens=1000),- # tools=[JavascriptEvalTool(), ReadDocumentation()],- tools=[JavascriptEvalTool()],+ tools=[+ # ReadDocumentation()+ *create_playground_tools(playground)+ ],verbose=True,)diff --git a/api-service/codegen/tools/playground/__init__.py b/api-service/codegen/tools/playground/__init__.pyindex e49b15106..311af888a 100644--- a/api-service/codegen/tools/playground/__init__.py+++ b/api-service/codegen/tools/playground/__init__.py@@ -1 +1 @@-import\ No newline at end of file+from .main import create_playground_toolsdiff --git a/api-service/codegen/tools/playground/main.py b/api-service/codegen/tools/playground/main.pynew file mode 100644index 000000000..f30add333--- /dev/null+++ b/api-service/codegen/tools/playground/main.py@@ -0,0 +1,17 @@+from typing import List+from langchain.tools.base import BaseTool+from playground_client import NodeJSPlayground++from .tools.filesystem import PlaygroundFilesystemTool+from .tools.dependencies import PlaygroundDependenciesTool+from .tools.process import PlaygroundProcessTool+from .tools.code import PlaygroundJavaScriptTool, PlaygroundTypeScriptTool++def create_playground_tools(playground: NodeJSPlayground) -> List[BaseTool]:+ return [+ PlaygroundTypeScriptTool(playground),+ PlaygroundJavaScriptTool(playground),+ PlaygroundFilesystemTool(playground),+ PlaygroundDependenciesTool(playground),+ PlaygroundProcessTool(playground),+ ]diff --git a/api-service/codegen/tools/playground/tool.py b/api-service/codegen/tools/playground/tool.pydeleted file mode 100644index 0bd2258dc..000000000--- a/api-service/codegen/tools/playground/tool.py+++ /dev/null@@ -1,22 +0,0 @@-"""A tool for running code in eval() on remote endpoint"""--from langchain.tools.base import BaseTool-from codegen.tools.javascript.eval import eval as js_eval---class PlaygroundTool(BaseTool):- name = "JavaScriptCodeExecution"- description = (- "JavaScript eval() function that can execute code. Use this to execute and evaluate javascript code. "- "Input should be a valid javascript code. "- )-- def __init__(self) -> None:- super().__init__()-- def _run(self, query: str) -> str:- query = query.strip().strip("`")- return js_eval(query)-- async def _arun(self, query: str) -> str:- return NotImplementedError("JavascriptEval does not support async")diff --git a/api-service/codegen/tools/playground/tools/base.py b/api-service/codegen/tools/playground/tools/base.pynew file mode 100644index 000000000..1531f0e87--- /dev/null+++ b/api-service/codegen/tools/playground/tools/base.py@@ -0,0 +1,11 @@+from langchain.tools.base import BaseTool+from playground_client import NodeJSPlayground++class PlaygroundBaseTool(BaseTool):+ def __init__(self, playground: NodeJSPlayground) -> None:+ super().__init__()+ self.playground = playground++ @staticmethod+ def extract_escaped_query(query: str):+ raise NotImplementedError('Not implemented')diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.pynew file mode 100644index 000000000..df910c752--- /dev/null+++ b/api-service/codegen/tools/playground/tools/code.py@@ -0,0 +1,36 @@+from .base import PlaygroundBaseTool+from playground_client import NodeJSPlayground+++class PlaygroundJavaScriptTool(PlaygroundBaseTool):+ # name = "JavaScriptCodeExecution"+ # description = (+ # "JavaScript eval() function that can execute code. Use this to execute and evaluate javascript code. "+ # "Input should be a valid javascript code. "+ # )++ def __init__(self, playground: NodeJSPlayground) -> None:+ super().__init__(playground)++ def _run(self, command: str) -> str:+ self.playground.run_command(command)++ async def _arun(self, command: str) -> str:+ return NotImplementedError("JavascriptEval does not support async")+++class PlaygroundTypeScriptTool(PlaygroundBaseTool):+ # name = "JavaScriptCodeExecution"+ # description = (+ # "JavaScript eval() function that can execute code. Use this to execute and evaluate javascript code. "+ # "Input should be a valid javascript code. "+ # )++ def __init__(self, playground: NodeJSPlayground) -> None:+ super().__init__(playground)++ def _run(self, command: str) -> str:+ self.playground.run_command(command)++ async def _arun(self, command: str) -> str:+ return NotImplementedError("JavascriptEval does not support async")diff --git a/api-service/codegen/tools/playground/tools/dependencies.py b/api-service/codegen/tools/playground/tools/dependencies.pynew file mode 100644index 000000000..cb8e4d043--- /dev/null+++ b/api-service/codegen/tools/playground/tools/dependencies.py@@ -0,0 +1,19 @@+from .base import PlaygroundBaseTool+from playground_client import NodeJSPlayground+++class PlaygroundDependenciesTool(PlaygroundBaseTool):+ # name = "JavaScriptCodeExecution"+ # description = (+ # "JavaScript eval() function that can execute code. Use this to execute and evaluate javascript code. "+ # "Input should be a valid javascript code. "+ # )++ def __init__(self, playground: NodeJSPlayground) -> None:+ super().__init__(playground)++ def _run(self, command: str) -> str:+ self.playground.run_command(command)++ async def _arun(self, command: str) -> str:+ return NotImplementedError("JavascriptEval does not support async")diff --git a/api-service/codegen/tools/playground/tools/filesystem.py b/api-service/codegen/tools/playground/tools/filesystem.pynew file mode 100644index 000000000..93a441cb0--- /dev/null+++ b/api-service/codegen/tools/playground/tools/filesystem.py@@ -0,0 +1,19 @@+from .base import PlaygroundBaseTool+from playground_client import NodeJSPlayground+++class PlaygroundFilesystemTool(PlaygroundBaseTool):+ # name = "JavaScriptCodeExecution"+ # description = (+ # "JavaScript eval() function that can execute code. Use this to execute and evaluate javascript code. "+ # "Input should be a valid javascript code. "+ # )++ def __init__(self, playground: NodeJSPlayground) -> None:+ super().__init__(playground)++ def _run(self, command: str) -> str:+ self.playground.run_command(command)++ async def _arun(self, command: str) -> str:+ return NotImplementedError("JavascriptEval does not support async")diff --git a/api-service/codegen/tools/playground/tools/process.py b/api-service/codegen/tools/playground/tools/process.pynew file mode 100644index 000000000..eaecd0b2c--- /dev/null+++ b/api-service/codegen/tools/playground/tools/process.py@@ -0,0 +1,19 @@+from .base import PlaygroundBaseTool+from playground_client import NodeJSPlayground+++class PlaygroundProcessTool(PlaygroundBaseTool):+ # name = "JavaScriptCodeExecution"+ # description = (+ # "JavaScript eval() function that can execute code. Use this to execute and evaluate javascript code. "+ # "Input should be a valid javascript code. "+ # )++ def __init__(self, playground: NodeJSPlayground) -> None:+ super().__init__(playground)++ def _run(self, command: str) -> str:+ self.playground.run_command(command)++ async def _arun(self, command: str) -> str:+ return NotImplementedError("JavascriptEval does not support async")