Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Let model use env vars

Vasek Mlejnskyfb97e93b0c28
diff --git a/api-service/app.py b/api-service/app.py
index d76c46a0e..0cea11760 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -48,7 +48,6 @@ def generate():
method = body["method"]
route = body["route"]
envs = body["envs"]
- print(envs)
db.create_deployment(run_id=run_id, project_id=project_id, route_id=route_id)
@@ -57,6 +56,7 @@ def generate():
db=db,
blocks=blocks,
method=method,
+ envs=envs,
)
db.update_state(run_id=run_id, state=DeploymentState.Deploying)
@@ -78,14 +78,13 @@ def generate():
# KEY_2 = VALUE_2
envs_str = ""
for env in envs:
- print(env)
if env["key"]:
envs_str += f'{env["key"]} = "{env["value"]}"\n'
# TODO: Update name in cf-worker-template/wrangler.template.toml
replace_file_content(
wrangler_template_path,
wrangler_path,
- {"<NAME>": f'"{project_id}2"', "<VARS>": envs_str},
+ {"<NAME>": f'"{project_id}"', "<VARS>": envs_str},
)
# TODO: Call npm run deploy
diff --git a/api-service/cf-worker-template/index.js b/api-service/cf-worker-template/index.js
index 2903bfa33..d89fcd338 100644
--- a/api-service/cf-worker-template/index.js
+++ b/api-service/cf-worker-template/index.js
@@ -1 +1,23 @@
-The code above satisfies the prompt.
\ No newline at end of file
+import { Router } from 'itty-router'
+
+const router = Router()
+
+async function handlegetRequest(request, env) {
+ const responseBody = {
+ API_KEY: env.API_KEY,
+ ANOTHER_KEY: env.ANOTHER_KEY
+ }
+
+ return new Response(JSON.stringify(responseBody), {
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ })
+}
+
+router.get('/', handlegetRequest)
+router.get('*', () => new Response('Not found', { status: 404 }))
+
+export default {
+ fetch: router.handle
+}
\ No newline at end of file
diff --git a/api-service/cf-worker-template/wrangler.toml b/api-service/cf-worker-template/wrangler.toml
index 1473c12ba..7dce32b15 100644
--- a/api-service/cf-worker-template/wrangler.toml
+++ b/api-service/cf-worker-template/wrangler.toml
@@ -1,6 +1,6 @@
# This wrangler file will be injected withl values during runtime and saved as wrangler.toml
-name = "meteo2"
+name = "meteo"
main = "./index.js"
# route = ''
compatibility_date = "2022-05-03"
@@ -8,4 +8,5 @@ send_metrics = false
[vars]
API_KEY = "1234"
+ANOTHER_KEY = "ABCD"
diff --git a/api-service/codegen/base.py b/api-service/codegen/base.py
index 66c9c240c..ea7350934 100644
--- a/api-service/codegen/base.py
+++ b/api-service/codegen/base.py
@@ -1,4 +1,4 @@
-from typing import List
+from typing import List, Dict
from langchain.llms.openai import OpenAIChat, OpenAI
from codegen.tools.javascript.tool import JavascriptEvalTool
@@ -13,6 +13,7 @@ def generate_req_handler(
run_id: str,
blocks: List[str],
method: str,
+ envs: List[Dict[str, str]],
) -> str:
executor = create_js_agent(
db=db,
@@ -25,7 +26,10 @@ def generate_req_handler(
verbose=True,
)
- prompt = PREFIX.format(method=method)
+ envs_str = ""
+ for env in envs:
+ envs_str += f'- `{env["key"]}`\n'
+ prompt = PREFIX.format(method=method, envs=envs_str)
for idx, block in enumerate(blocks):
prompt = prompt + "\n" + "{}. ".format(idx + 1) + block + "\n"
diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.py
index d6ebba0d9..7f54c4dc0 100644
--- a/api-service/codegen/prompt.py
+++ b/api-service/codegen/prompt.py
@@ -11,16 +11,19 @@
# """
PREFIX = """You are a skilled programmer that knows nodejs and javascript.
-You are building a serverless API with Cloudflare Workers using the 'itty-router' package (code and docs is here https://github.com/kwhitley/itty-router).
-You need to complete the `handle{method}Request` function that handles the incoming {method} requests.
+You are building a serverless API with Cloudflare Workers using the `itty-router` package.
+You need to complete the `handle{method}Request` function that handles the incoming {method} requests and return the whole completed code.
-Here is some already written code that handles the initialization. The function that you need to complete is marked with a TODO comment:
+You can access environment variables through the `env` parameter. You have access to the following environment variables:
+{envs}
+
+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(request) {{
+async function handle{method}Request(request, env) {{
// TODO
}}