Skip to content

armgit / E2B

Public Imported from GitHub
0

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

make it work

Vasek Mlejnsky90519f64eb26
diff --git a/api-service/app.py b/api-service/app.py
index 080639383..e5679c5bf 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -32,7 +32,7 @@ def get_request_body_template(blocks: List[dict[str, str]]):
block for block in blocks if block.get("type") == "RequestBody"
]
request_body_template = (
- request_body_blocks[0]["prompt"] if len(request_body_blocks) > 0 else None
+ request_body_blocks[0]["content"] if len(request_body_blocks) > 0 else None
)
return request_body_template
@@ -54,8 +54,9 @@ async def generate():
method = body["method"]
route = body["route"]
+ pprint("+++ Blocks:")
pprint(blocks)
- return {}
+ pprint("--- Blocks:")
await db.create_deployment(run_id=run_id, project_id=project_id, route_id=route_id)
playground = None
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index 704512f53..335a6e59d 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -143,16 +143,33 @@ class Codegen(BaseModel):
)
)
+ # Retrieve the description block.
+ description_block: Dict[str, str] = next(
+ b for b in blocks if b.get("type") == "Description"
+ )
+
+ # Retrueve the block describing the incoming request payload.
+ incoming_request_block: Dict[str, str] = next(
+ b for b in blocks if b.get("type") == "RequestBody"
+ )
+
+ # Retrieve the instructions block.
+ instructions_block: Dict[str, str] = next(
+ b for b in blocks if b.get("type") == "Instructions"
+ )
+
input_vars = {
+ "description": description_block["content"],
+ "request_body": f"{{\n{incoming_request_block['content']}\n}}",
"route": route,
"method": method,
}
instructions = "Here are the instructions:"
- inst_idx = 0
+ # inst_idx = 0
# Append the premade prefix instructions.
for instruction in HUMAN_INSTRUCTIONS_PREFIX:
- inst_idx += 1
+ # inst_idx += 1
values = []
# Extract the correct values from `input_vars` based on the keys.
@@ -162,25 +179,37 @@ class Codegen(BaseModel):
# Use the values to format the instruction string.
inst = instruction["content"].format(*values)
- instructions = instructions + "\n" + f"{inst_idx}. {inst}"
-
- print("+++ BLOCKS")
- print(blocks)
- print("--- BLOCKS")
- for block in blocks:
- if block.get("type") == "Basic":
- inst_idx += 1
- instructions = instructions + "\n" + f"{inst_idx}. " + block["prompt"]
-
- # Append the premade suffix instructions.
- for inst in HUMAN_INSTRUCTIONS_SUFFIX:
- inst_idx += 1
- instructions = instructions + "\n" + f"{inst_idx}. {inst}"
-
- # instructions += "\nThought: Here is the plan of how I will go about solving this based on the instructions I got:\n1."
- # instructions += "\nThought:"
+ # instructions = instructions + "\n" + f"{inst_idx}. {inst}"
+ instructions = instructions + "\n" + f"- {inst}"
+
+ # Append the use instructions
+ instructions = (
+ instructions
+ + "\nHere are the required implementation instructions:\n"
+ + instructions_block["content"]
+ )
+
print("Instructions:\n", instructions)
+ ######## +++++ OLD
+ # print("+++ BLOCKS")
+ # print(blocks)
+ # print("--- BLOCKS")
+ # for block in blocks:
+ # if block.get("type") == "Basic":
+ # inst_idx += 1
+ # instructions = instructions + "\n" + f"{inst_idx}. " + block["prompt"]
+
+ # # Append the premade suffix instructions.
+ # for inst in HUMAN_INSTRUCTIONS_SUFFIX:
+ # inst_idx += 1
+ # instructions = instructions + "\n" + f"{inst_idx}. {inst}"
+
+ # # instructions += "\nThought: Here is the plan of how I will go about solving this based on the instructions I got:\n1."
+ # # instructions += "\nThought:"
+ # print("Instructions:\n", instructions)
+ ######## ----- OLD
+
print("Running executor...")
await self._agent_executor.arun(
agent_scratchpad="",
diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.py
index 43179985f..8b36d231e 100644
--- a/api-service/codegen/prompt.py
+++ b/api-service/codegen/prompt.py
@@ -1,7 +1,6 @@
# - ALWAYS use `import` to import packages.
# - Make sure any code you generate is JSON escaped.
SYSTEM_PREFIX = """You are an AI JavaScript developer assistant.
-- DO NOT BE STUPID
- NEVER deploy code before you run it and are sure it is working.
- NEVER perform unsecure operations like disabling SSL certificates and similar.
- You are building an Express server that handles REST API.
@@ -35,13 +34,21 @@ Final Answer: the final answer"""
SYSTEM_SUFFIX = """Begin! Reminder to NEVER use tools you don't have access. Reminder to ALWAYS use the exact the action `Final Answer` when you know the final answer."""
HUMAN_INSTRUCTIONS_PREFIX = [
- # {
- # "variables": [],
- # "content": "You are building a slack bot that sends a message to channel every time it gets a new request. You have access to the folling environment variables: `SLACK_BOT_ACCESS_TOKEN`",
- # },
+ {
+ "variables": ["description"],
+ "content": """The handler you are building should do the following: {0}""",
+ },
+ {
+ "variables": [],
+ "content": """Do not try to come up with solutions and code if you do not know. Instead, use the tool `AskHuman` to ask for help.""",
+ },
{
"variables": [],
- "content": "Do not try to come up with solutions and code if you do not know. Instead, use the tool `AskHuman` to ask for help.",
+ "content": """If you think there might be multiple paths forward, use the tool `LetHumanChoose` to choose from them.""",
+ },
+ {
+ "variables": ["request_body"],
+ "content": """The incoming request body is JSON that looks like this:\n{0}""",
},
{
"variables": ["method"],
@@ -67,6 +74,18 @@ app.listen(port, async () => {{
"variables": ["route"],
"content": """The request handler MUST be on the route `{0}`""",
},
+ {
+ "variables": [],
+ "content": """Do not forget to use async and await""",
+ },
+ {
+ "variables": [],
+ "content": """ALWAYS test that the generated server works as required by making mock `curl` requests to the server""",
+ },
+ {
+ "variables": [],
+ "content": """Generate the full required server code and and make sure it runs without any errors""",
+ },
]
HUMAN_INSTRUCTIONS_SUFFIX = [