Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Cleanup

Tomas Valenta855d92abf6f2
diff --git a/api-service/app.py b/api-service/app.py
index 4d4b0247f..2eb8dfefb 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -2,8 +2,8 @@ import os
import uuid
from pprint import pprint
-from dotenv import load_dotenv
from typing import List
+from dotenv import load_dotenv
from playground_client.exceptions import NotFoundException
from quart import Quart, request, abort
from quart_cors import cors
@@ -106,15 +106,15 @@ async def generate():
print('Error while generating code:', e)
raise e
- url: str | None = None
+ deploy_url: str | None = None
# Disable deployment if there AWS creds are not present
if os.environ.get("AWS_ACCESS_KEY_ID") and os.environ.get(
"AWS_SECRET_ACCESS_KEY"
):
await db.update_state(run_id=run_id, state=DeploymentState.Deploying)
- url = await playground.deploy(project_id)
+ deploy_url = await playground.deploy(project_id)
- await db.finish_deployment(run_id=run_id, url=url)
+ await db.finish_deployment(run_id=run_id, url=deploy_url)
return {}
except:
await db.update_state(run_id=run_id, state=DeploymentState.Error)
diff --git a/api-service/codegen/prompt_old.py b/api-service/codegen/prompt_old.py
deleted file mode 100644
index aa1fcc31d..000000000
--- a/api-service/codegen/prompt_old.py
+++ /dev/null
@@ -1,199 +0,0 @@
-# PREFIX = """Complete a body of nodejs function that handles incoming {method} requests inside an Express server.
-
-# You must follow these rules:
-# - Don't write anything else but the body of function. Once you have the body function written, you should finish and output the code you have so far.
-# - You have access to the following environment variables and you can use them if needed: SUPABASE_URL, SUPABASE_KEY.
-
-# If you cannot follow any of the rules above, finish with the last code you wrote. Don't try in any way to go around the rules or come up with other solutions.
-
-
-# The code must perform following logic:
-# """
-
-PREFIX = """You are a skilled programmer that knows nodejs and javascript.
-USE ONLY TOOLS THAT YOU HAVE ACCESS TO!
-You are building a serverless API with Cloudflare Workers using the `itty-router` package. The javascript code is in the form of ES modules.
-You need to complete the `handle{method}Request` function that handles the incoming {method} requests and return the whole completed code.
-
-You can install any package that you might need.
-
-The incoming request payload looks like this:
-```
-{request_body}
-```
-
-Here is the starting code that handles the initialization. The function that you need to complete is marked with a TODO comment:
-```
-import {{ Router }} from 'itty-router'
-
-const router = Router()
-
-async function handle{method}Request(req, env) {{
- // DO NOT USE `process.env` TO ACCES ENVIRONMENT VARIABLES. Instead, you access environment variables through the `env` parameter like this: `const myEnv = env.MY_ENV`.
- // You have access to the following environment variables:
- {envs}
-
- // The incoming request content-type is application/json. Make sure to correctly retrieve it.
- const requestBody = await req.json()
- // TODO
-}}
-
-router.{method}('/', handle{method}Request)
-router.get('*', () => new Response('Not found', {{ status: 404 }}))
-
-export default {{
- fetch: router.handle
-}}
-```
-
-The code must perform the following logic:
-"""
-
-# SUFFIX = """
-# Here's the code that must be completed:
-# ```
-# const express = require('express');
-# const app = express();
-
-# app.use(express.json());
-
-# app.{method}(/, function(req, res) {{
-# // TODO: Implement body of this function based on the required logic
-# }})
-
-# app.listen(8080, () => console.log('Listening on port 8080'));
-# ```
-# """
-
-# SUFFIX = """Here is already written code that handles the initialization. You don't need to rewrite that.
-# The part that you need to complete is marked with a TODO comment:
-# ```
-# import {{ Router }} from 'itty-router'
-
-# const router = Router()
-
-# function handleRequest(request) {{
-# router
-# .get('/', async function(req) {{
-# // TODO
-# })
-# .get('*', () => new Response("Not found", {{ status: 404 }}))
-# router.handle(request)
-# }
-
-# addEventListener('fetch', (event) => {{
-# event.respondWith(handleRequest(event.request))
-# }})
-# ```
-# """
-
-SUFFIX = ""
-
-################## NEW FOR CHAT GPT
-
-PREFIX = """You are a senior JavaScript developer and you have access to the following tools: {tool_names}.
-You've been tasked to build the `handle{method}Request` function that handles incoming {method} requests for your REST API.
-The incoming {method} request payload ALWAYS looks like this:
-```
-{{{{
- {request_body}
-}}}}
-```
-
-The function `handle{method}Request` MUST do the following logic: {steps}"""
-
-FORMAT_INSTRUCTIONS = """The way you use the tools is by specifying a json blob.
-Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).
-The only values that should be in the "action" field are: {tool_names}
-The $JSON_BLOB should only contain a SINGLE action, do NOT return a list of multiple actions. Here is an example of a valid $JSON_BLOB:
-```
-{{{{
- "action": $TOOL_NAME,
- "action_input": $INPUT
-}}}}
-```
-ALWAYS use the following format:
-Requirement: the required logic from the code
-Thought: you should always think about what to do
-Action:
-```
-$JSON_BLOB
-```
-Observation: the result of the action
-... (this Thought/Action/Observation can repeat N times)
-Thought: I now know the final answer
-Final Answer: the final answer to the original input question"""
-
-##########################
-
-PREFIX = """You are a senior JavaScript developer and you have access to the following tools: {tool_names}.
-You're buildiing a serverless API with Cloudflare Workers using the `itty-router` package. You've been tasked to build the `handlepostRequest` function that handles incoming POST requests for your REST API.
-The incoming POST request payload ALWAYS looks like this:
-```
-{{
- email: string,
- userID: string,
- pricingType: string,
- pricingCost: number
-}}
-```
-
-The code MUST do the following logic:
-1. Use the following starting template. The part that must be completed is marked with the TODO comment
-```
-import {{ Router }} from 'itty-router'
-
-const router = Router()
-
-async function handlepostRequest(req, env) {{
- // DO NOT USE `process.env` TO ACCES ENVIRONMENT VARIABLES. Instead, you access environment variables through the `env` parameter like this: `const myEnv = env.MY_ENV`.
- // You have access to the following environment variables:
- // - env.SLACK_BOT_ACCESS_TOKEN
-
- // The incoming request content-type is application/json. Make sure to correctly retrieve it.
- const requestBody = await req.json()
- // TODO
-}}
-
-router.post('/', handlepostRequest)
-router.get('*', () => new Response('Not found', {{ status: 404 }}))
-
-export default {{
- fetch: router.handle
-}}
-```
-
-2. Use the `@sagi.io/workers-slack` package to send a message to channel 'general' in the format: `User '<email>' selected pricing '<type>' for $<cost>''` based on the incoming request data. This is an example of how to send a Slack message using the `@sagi.io/workers-slack` message to channel 'general':
-```
-const botAccessToken = env.SLACK_BOT_ACCESS_TOKEN;
-const SlackREST = require('@sagi.io/workers-slack')
-const SlackAPI = new SlackREST({{ botAccessToken }})
-
-const data = {{ channel: 'general', text: 'hello world' }}
-const result = await SlackAPI.chat.postMessage(data)
-```
-
-3. Respond back with the message "Ok" if there wasn't any error
-"""
-
-FORMAT_INSTRUCTIONS = """The way you use the tools is by specifying a json blob.
-Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).
-The only values that should be in the "action" field are: {tool_names}
-The $JSON_BLOB should only contain a SINGLE action, do NOT return a list of multiple actions. Here is an example of a valid $JSON_BLOB:
-```
-{{
- "action": $TOOL_NAME,
- "action_input": $INPUT
-}}
-```
-ALWAYS use the following format:
-Requirement: the required logic from the code
-Thought: you should always think about what to do
-Action:
-```
-$JSON_BLOB
-```
-Observation: the result of the action
-... (this Thought/Action/Observation can repeat N times)
-Thought: I now know the final answer
-Final Answer: the final answer to the original input question"""
diff --git a/api-service/could-not-parse-llm-output.txt b/api-service/could-not-parse-llm-output.txt
deleted file mode 100644
index 72bdb7895..000000000
--- a/api-service/could-not-parse-llm-output.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-Thought: We need to check if the incoming request is a POST request and retrieve the email from the request payload. We can use the `req.method` property to check if the request is a POST request and `req.body` to retrieve the email from the request payload. We can use a regular expression to check if the email is valid.
-
-Action:
-```
-{
- "action": "RunJavaScriptCode",
- "action_input": "import express from 'express';\nconst app = express();\n\n// All incoming requests have payload in the JSON format.\napp.use(express.json());\n\nfunction handlepostRequest(req, res) {\n if (req.method !== 'POST') {\n res.status(400).send('Bad Request: Only POST requests are allowed.');\n } else {\n const email = req.body.email;\n const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;\n if (emailRegex.test(email)) {\n res.send('Ok');\n } else {\n res.status(400).send('Bad Request: Invalid email.');\n }\n }\n}\n\napp.post('/', handlepostRequest);\n\n// Start the server\napp.listen(3000, () => console.log('Listening on port 3000'));"
-}
-```
-
-Traceback (most recent call last):
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/agents/chat/base.py", line 51, in _extract_tool_and_input
- response = json.loads(action.strip())
- File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 346, in loads
- return _default_decoder.decode(s)
- File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 337, in decode
- obj, end = self.raw_decode(s, idx=_w(s, 0).end())
- File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 353, in raw_decode
- obj, end = self.scan_once(s, idx)
-json.decoder.JSONDecodeError: Invalid \escape: line 3 column 416 (char 450)
-
-During handling of the above exception, another exception occurred:
-
-Traceback (most recent call last):
- File "/Users/vasekmlejnsky/Developer/ai-api/api-service/test.py", line 133, in <module>
- ae.run(
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 216, in run
- return self(kwargs)[self.output_keys[0]]
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 116, in __call__
- raise e
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 113, in __call__
- outputs = self._call(inputs)
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 499, in _call
- next_step_output = self._take_next_step(
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 409, in _take_next_step
- output = self.agent.plan(intermediate_steps, **inputs)
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 105, in plan
- action = self._get_next_action(full_inputs)
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 67, in _get_next_action
- parsed_output = self._extract_tool_and_input(full_output)
- File "/Users/vasekmlejnsky/Library/Caches/pypoetry/virtualenvs/codegen-FZjZZaFx-py3.10/lib/python3.10/site-packages/langchain/agents/chat/base.py", line 55, in _extract_tool_and_input
- raise ValueError(f"Could not parse LLM output: {text}")
-ValueError: Could not parse LLM output: Thought: We need to check if the incoming request is a POST request and retrieve the email from the request payload. We can use the `req.method` property to check if the request is a POST request and `req.body` to retrieve the email from the request payload. We can use a regular expression to check if the email is valid.
-
-Action:
-```
-{
- "action": "RunJavaScriptCode",
- "action_input": "import express from 'express';\nconst app = express();\n\n// All incoming requests have payload in the JSON format.\napp.use(express.json());\n\nfunction handlepostRequest(req, res) {\n if (req.method !== 'POST') {\n res.status(400).send('Bad Request: Only POST requests are allowed.');\n } else {\n const email = req.body.email;\n const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;\n if (emailRegex.test(email)) {\n res.send('Ok');\n } else {\n res.status(400).send('Bad Request: Invalid email.');\n }\n }\n}\n\napp.post('/', handlepostRequest);\n\n// Start the server\napp.listen(3000, () => console.log('Listening on port 3000'));"
-}
-```
\ No newline at end of file
diff --git a/api-service/database/client.py b/api-service/database/client.py
index 661f71c8a..f7148452d 100644
--- a/api-service/database/client.py
+++ b/api-service/database/client.py
@@ -7,7 +7,6 @@ from postgrest._async.request_builder import (
AsyncRequestBuilder,
)
-
class Client(BaseModel):
_supabase_url: str = PrivateAttr()
_supabase_key: str = PrivateAttr()
diff --git a/api-service/database/database.py b/api-service/database/database.py
index a3427015a..eeb3d19d2 100644
--- a/api-service/database/database.py
+++ b/api-service/database/database.py
@@ -13,8 +13,8 @@ class DeploymentState(Enum):
Error = "error"
-tableDeployments = "deployments"
-tableProjects = "projects"
+TABLE_DEPLOYMENTS = "deployments"
+TABLE_PROJECTS = "projects"
class Database:
def __init__(self, supabase_url: str, supabase_key: str) -> None:
@@ -23,7 +23,7 @@ class Database:
async def create_deployment(
self, run_id: str, project_id: str, route_id: str
) -> None:
- await self.client.table(tableDeployments).insert(
+ await self.client.table(TABLE_DEPLOYMENTS).insert(
{
"id": run_id,
"project_id": project_id,
@@ -34,7 +34,7 @@ class Database:
async def push_logs(self, run_id: str, logs: list[ToolLog | ThoughtLog]) -> None:
if len(logs) > 0:
- await self.client.table(tableDeployments).update(
+ await self.client.table(TABLE_DEPLOYMENTS).update(
{
"logs": logs,
}
@@ -42,14 +42,14 @@ class Database:
async def push_raw_logs(self, run_id: str, logs_raw: str) -> None:
if logs_raw:
- await self.client.table(tableDeployments).update(
+ await self.client.table(TABLE_DEPLOYMENTS).update(
{
"logs_raw": logs_raw,
}
).eq("id", run_id).execute()
async def update_state(self, run_id: str, state: DeploymentState) -> None:
- await self.client.table(tableDeployments).update(
+ await self.client.table(TABLE_DEPLOYMENTS).update(
{
"state": state.value,
}
@@ -64,7 +64,7 @@ class Database:
if url is not None:
update["url"] = url
- await self.client.table(tableDeployments).update(update).eq(
+ await self.client.table(TABLE_DEPLOYMENTS).update(update).eq(
"id", run_id
).execute()
@@ -86,7 +86,7 @@ class Database:
]
"""
result = (
- await self.client.table(tableProjects)
+ await self.client.table(TABLE_PROJECTS)
.select("data")
.eq("id", project_id)
.execute()