Skip to content

armgit / E2B

Public Imported from GitHub
0

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

commit

Vasek Mlejnskyca39c5932a3a
diff --git a/api/generate.py b/api/generate.py
index 6ef628115..ae12e9991 100644
--- a/api/generate.py
+++ b/api/generate.py
@@ -3,7 +3,7 @@
import simplejson
from http.server import BaseHTTPRequestHandler
-from code_generator.base import generate
+from code_generator.base import generate_req_handler
class handler(BaseHTTPRequestHandler):
@@ -11,182 +11,26 @@ class handler(BaseHTTPRequestHandler):
# Extract 'prompt' from the json body
self.data_string = self.rfile.read(int(self.headers['Content-Length']))
- print(self.data_string)
- print('===========')
-
data = simplejson.loads(self.data_string)
- print(data)
- js_code = generate(data['prompt']).strip('`').strip()
- print('--------')
- print(js_code)
+ blocks = data['blocks']
+ method = data['method']
+ print('=== BLOCKS')
+ print(blocks)
+ print('=== METHOD')
+ print(method)
+
+ final_prompt, js_code = generate_req_handler(blocks, method)
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
self.wfile.write(
simplejson.dumps(
- {'code': js_code}
+ {
+ 'code': js_code.strip('`').strip(),
+ 'prompt': final_prompt,
+ }
).encode()
)
return
-
- def do_GET(self):
- js_code = generate(
- """Write a body of an Express server function that handles incoming requests.
- The server runs on the port 3001.
- First make sure the request is of type 'POST' and then extract the field 'email' from the request's JSON body and save it to a variable.
- If the request isn't POST, return an error message with the relevant status code.
- Then send back status 200 as a response, the extracted email, and the version of the Express package in a payload."""
- ).strip('`').strip()
- print('--------')
- print(js_code)
-
- self.send_response(200)
- self.send_header('Content-type', 'text/plain')
- self.end_headers()
- self.wfile.write(js_code.encode())
- return
-
-
-# import os
-# import yaml
-# from __future__ import annotations
-# from typing import Any, Optional, List
-# from langchain.agents.agent import AgentExecutor
-# from langchain.agents.agent_toolkits.base import BaseToolkit
-# from langchain.agents.agent_toolkits.json.base import create_json_agent
-# from langchain.agents.agent_toolkits.json.toolkit import JsonToolkit
-# from langchain.agents.agent_toolkits.openapi.prompt import DESCRIPTION
-# from langchain.agents.tools import Tool
-# from langchain.llms.base import BaseLLM
-# from langchain.requests import RequestsWrapper
-# from langchain.tools import BaseTool
-# from langchain.tools.json.tool import JsonSpec
-# from langchain.agents.mrkl.base import ZeroShotAgent
-# from langchain.callbacks.base import BaseCallbackManager
-# from langchain.chains.llm import LLMChain
-# from langchain.tools.python.tool import PythonREPLTool
-# from langchain.llms.openai import OpenAI
-# from langchain.agents.agent_toolkits.openapi.prompt import (
-# OPENAPI_PREFIX,
-# OPENAPI_SUFFIX,
-# )
-# from langchain.agents.agent_toolkits.openapi.toolkit import OpenAPIToolkit
-# from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS
-
-# os.environ["OPENAI_API_KEY"] =
-
-# PREFIX = """You are an agent designed to write code to answer questions.
-# You have access to a python REPL, which you can use to execute python code to make sure it's the correct code and runs without errors.
-# If you get an error, debug your code and try again.
-# The final asnwer must only the code that can directly run. Don't output any additional text.
-# You must return all code needed to get the answer, not just a single function call.
-# You might know the answer without running any code, but you should still run the code to get the answer.
-# If it does not seem like you can write code to answer the question, just return "I don't know" as the answer.
-# """
-
-# def create_python_agent(
-# llm: BaseLLM,
-# tool: PythonREPLTool,
-# callback_manager: Optional[BaseCallbackManager] = None,
-# verbose: bool = False,
-# prefix: str = PREFIX,
-# **kwargs: Any,
-# ) -> AgentExecutor:
-# """Construct a python agent from an LLM and tool."""
-# tools = [tool]
-# prompt = ZeroShotAgent.create_prompt(tools, prefix=prefix)
-# llm_chain = LLMChain(
-# llm=llm,
-# prompt=prompt,
-# callback_manager=callback_manager,
-# )
-# tool_names = [tool.name for tool in tools]
-# agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs)
-# return AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=verbose)
-
-
-# class OpenAPIToolkit(BaseToolkit):
-# """Toolkit for interacting with a OpenAPI api."""
-
-# json_agent: AgentExecutor
-# python_agent: AgentExecutor
-
-# def get_tools(self) -> List[BaseTool]:
-# """Get the tools in the toolkit."""
-# json_agent_tool = Tool(
-# name="json_explorer",
-# func=self.json_agent.run,
-# description=DESCRIPTION,
-# )
-# python_agent_tool = Tool(
-# name="python_generator",
-# func=self.python_agent.run,
-# description=""
-# )
-# # request_toolkit = RequestsToolkit(requests_wrapper=self.requests_wrapper)
-# return [python_agent_tool, json_agent_tool]
-
-# @classmethod
-# def from_llm(
-# cls,
-# llm: BaseLLM,
-# json_spec: JsonSpec,
-# **kwargs: Any,
-# ) -> OpenAPIToolkit:
-# """Create json agent from llm, then initialize."""
-# json_agent = create_json_agent(llm, JsonToolkit(spec=json_spec), **kwargs)
-# python_agent = create_python_agent(
-# llm=OpenAI(temperature=0, max_tokens=1000),
-# tool=PythonREPLTool(),
-# verbose=True
-# )
-# return cls(json_agent=json_agent, python_agent=python_agent)
-
-
-# def create_openapi_agent(
-# llm: BaseLLM,
-# toolkit: OpenAPIToolkit,
-# callback_manager: Optional[BaseCallbackManager] = None,
-# prefix: str = OPENAPI_PREFIX,
-# suffix: str = OPENAPI_SUFFIX,
-# format_instructions: str = FORMAT_INSTRUCTIONS,
-# input_variables: Optional[List[str]] = None,
-# verbose: bool = False,
-# **kwargs: Any,
-# ) -> AgentExecutor:
-# """Construct a json agent from an LLM and tools."""
-# tools = toolkit.get_tools()
-# prompt = ZeroShotAgent.create_prompt(
-# tools,
-# prefix=prefix,
-# suffix=suffix,
-# format_instructions=format_instructions,
-# input_variables=input_variables,
-# )
-# llm_chain = LLMChain(
-# llm=llm,
-# prompt=prompt,
-# callback_manager=callback_manager,
-# )
-# tool_names = [tool.name for tool in tools]
-# agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs)
-# return AgentExecutor.from_agent_and_tools(
-# agent=agent, tools=toolkit.get_tools(), verbose=verbose
-# )
-
-# with open("devbook_openapi.yml") as f:
-# data = yaml.load(f, Loader=yaml.FullLoader)
-# json_spec=JsonSpec(dict_=data, max_value_length=40000)
-# headers = {
-# "Authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}"
-# }
-# openapi_toolkit = OpenAPIToolkit.from_llm(OpenAI(temperature=0), json_spec, verbose=True)
-# openapi_agent_executor = create_openapi_agent(
-# llm=OpenAI(temperature=0),
-# toolkit=openapi_toolkit,
-# verbose=True
-# )
-
-# openapi_agent_executor.run("Write a python function that makes a post request to devbook /sessions/{sessionID}/refresh to every 5 seconds. The sessionID is '1234'.")
diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx
index 1cba378ea..c483aa63e 100644
--- a/components/Editor/index.tsx
+++ b/components/Editor/index.tsx
@@ -1,7 +1,6 @@
import { shallow } from 'zustand/shallow'
import useSWRMutation from 'swr/mutation'
import { Fragment, useState } from 'react'
-import { toast } from 'sonner'
import Hotkeys from 'react-hot-keys'
import { State, Block, methods, Method } from 'state/store'
@@ -32,13 +31,12 @@ async function handlePostGenerate(url: string, { arg }: {
method: Method,
}
}) {
- let prompt = ''
- for (const block of arg.blocks) {
- prompt += block.prompt
- }
return await fetch(url, {
method: 'POST',
- body: JSON.stringify({ prompt }),
+ body: JSON.stringify({
+ blocks: arg.blocks.map(b => b.prompt),
+ method: arg.method,
+ }),
headers: {
'Content-Type': 'application/json',
@@ -67,7 +65,7 @@ export default function Editor({ }: Props) {
blocks,
method,
})
- toast(response)
+ // toast(response)
console.log(response)
}
diff --git a/package.json b/package.json
index 2b0f41680..255af2883 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
"@supabase/supabase-js": "^2.10.0",
"@types/randomcolor": "^0.5.7",
"clsx": "^1.2.1",
+ "express": "^4.18.2",
"immer": "^9.0.19",
"lucide-react": "^0.122.0",
"nanoid": "^4.0.1",
diff --git a/state/store.ts b/state/store.ts
index adba66a14..7cd96d5c9 100644
--- a/state/store.ts
+++ b/state/store.ts
@@ -19,16 +19,16 @@ export interface Block {
}
export enum Method {
- POST = 'POST',
- GET = 'GET',
- PUT = 'PUT',
- DELETE = 'DELETE',
- PATCH = 'PATCH',
+ POST = 'post',
+ GET = 'get',
+ PUT = 'put',
+ DELETE = 'delete',
+ PATCH = 'patch',
}
export const methods = Object.keys(Method).filter((item) => {
return isNaN(Number(item))
-});
+})
export interface State {
blocks: Block[]
@@ -95,6 +95,6 @@ export function createStore(deployment?: api_deployments, client?: SupabaseClien
} : undefined,
})
- const useStore = create<State, [["zustand/persist", unknown], ["zustand/immer", never]]>(persistent)
+ const useStore = create<State, [['zustand/persist', unknown], ['zustand/immer', never]]>(persistent)
return useStore
}
diff --git a/yarn.lock b/yarn.lock
index 8984f8f5a..9019b43c7 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3924,7 +3924,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-2.2.1.tgz#007b2d92c6428eda2b76e7016a34351586934593"
integrity sha512-eNTPlAD67BmP31LDINZ3U7HSF8l57TxOY2PmBJ1shpCvpnxBF93mWCE8YHBnXs8qiUZJc9WDcWIeC3a2HIAMfw==
-express@^4.17.1:
+express@^4.17.1, express@^4.18.2:
version "4.18.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59"
integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==