Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Handle empty request body block

Tomas Valentaeb45316e191c
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index 1766aac4e..a3b992951 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -18,10 +18,10 @@ def generate_req_handler(
route: str,
envs: List[EnvVar],
):
- request_body_template = next(
- block for block in blocks if block["type"] == "RequestBody"
- )["prompt"]
-
+ request_body_blocks = [
+ 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
playground_tools, playground = create_playground_tools(
envs=envs,
route=route,
@@ -53,7 +53,7 @@ def generate_req_handler(
)
for idx, block in enumerate(blocks):
- if block["type"] == "Basic":
+ if block.get("type") == "Basic":
prompt = prompt + "\n" + "{}. ".format(idx + 1) + block["prompt"] + "\n"
prompt = prompt + "\n" + SUFFIX.format(method=method)
diff --git a/api-service/codegen/tools/playground/main.py b/api-service/codegen/tools/playground/main.py
index 7b6b7eb7e..b59afd66f 100644
--- a/api-service/codegen/tools/playground/main.py
+++ b/api-service/codegen/tools/playground/main.py
@@ -13,7 +13,7 @@ def create_playground_tools(
envs: List[EnvVar],
method: str,
route: str,
- request_body_template: str,
+ request_body_template: str | None,
) -> tuple[List[Any], Playground]:
playground = NodeJSPlayground(envs)
mock = MockRequestFactory(
diff --git a/api-service/codegen/tools/playground/mock/request.py b/api-service/codegen/tools/playground/mock/request.py
index ea19d857a..dc16428a4 100644
--- a/api-service/codegen/tools/playground/mock/request.py
+++ b/api-service/codegen/tools/playground/mock/request.py
@@ -10,7 +10,7 @@ class MockRequestFactory:
self,
method: str,
route: str,
- body_template: str,
+ body_template: str | None,
playground: Playground,
hostname: str = "http://localhost:3000",
) -> None:
@@ -26,10 +26,14 @@ class MockRequestFactory:
return f"curl -X {self.method} {self.hostname}{route_separator}{self.route} -H 'Content-Type: application/json' -d {json.dumps(body)}"
def generate_body_data(self):
+ if self.body_template is None:
+ return '{}'
+
body_interface_name = "RequestBody"
request_body_template = f"""interface {body_interface_name} {{
{self.body_template}
}}
"""
+
body = json.loads(self.playground.mock_body_data(request_body_template, body_interface_name))[body_interface_name]
return json.dumps(body)