Skip to content

armgit / E2B

Public Imported from GitHub
0

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

commit

Vasek Mlejnsky9c6f083b2b39
diff --git a/api-service/app.py b/api-service/app.py
index 00f83fa22..0e8237149 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -77,7 +77,7 @@ def generate():
)
db.update_state(run_id=run_id, state=DeploymentState.Deploying)
- url = playground.deploy(project_id, envs)
+ # url = playground.deploy(project_id, envs)
db.finish_deployment(run_id=run_id, url=url)
return {}
diff --git a/api-service/codegen/agent/base.py b/api-service/codegen/agent/base.py
index d3a0f358c..d338968f5 100644
--- a/api-service/codegen/agent/base.py
+++ b/api-service/codegen/agent/base.py
@@ -28,6 +28,18 @@ def xml_escape(text: str) -> str:
def parse_action_string(action_string: str):
+ lines = action_string.strip().splitlines()
+
+ if len(lines) == 0:
+ # TODO: What to do here?
+ pass
+
+ if len(lines) == 1:
+ # Possible format: <action tool="">content</action><action tool="">content</action>
+ line = lines[0]
+ # TODO
+ pass
+
# The action is in the XML format, we need to try to a XML escape
# the body of an XML element. We'll use a bit of heuristics here.
# We assume the action looks like this:
@@ -48,7 +60,6 @@ def parse_action_string(action_string: str):
# <action or with </action.
# Split the action into a list of lines.
- lines = action_string.strip().splitlines()
# Escape all but the lines the start or end the XML element.
for idx, line in enumerate(lines):
if line.startswith("<action") or line.startswith("</action"):
@@ -122,14 +133,6 @@ class CodegenAgent(ChatAgent):
MALFORMED_ANSWER,
f"Wrong format! Follow the format! Reminder to ALWAYS use the exact the action `Final Answer` when you know the final answer. I just tried to parse your last reponse with `xml.etree.ElementTree.fromstring()` and received this error:\n{e}Reminder, that you should follow the format I told you!",
)
- print(f"====== Got exception '{str(e)}'\n text:\n{text}")
- # input = response["action_input"]
- return (
- f"[{text[:50]}...]",
- "",
- # f"You are not following the response format as I told you. I just ran your response via json.loads and received this error\n{str(e)}\nPlease try again and change your response.",
- )
- # raise ValueError(f"Could not parse LLM output: {text}")
class CodegenAgentExecutor(AgentExecutor):
diff --git a/api-service/codegen/callbacks/logs.py b/api-service/codegen/callbacks/logs.py
index 02759854e..2e7be716a 100644
--- a/api-service/codegen/callbacks/logs.py
+++ b/api-service/codegen/callbacks/logs.py
@@ -1,6 +1,7 @@
from typing import Dict, Any, List, Union, Optional
import datetime
import uuid
+from pprint import pprint
from pydantic import PrivateAttr
from langchain.callbacks.base import BaseCallbackHandler
@@ -97,6 +98,31 @@ class LogsCallbackHandler(BaseCallbackHandler):
def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
"""Run on agent action."""
+
+ # First parse the thought
+ # The `action.log` should look like this:
+ #
+ # Thought: Lorem ipsum ...
+ # Action:
+ # ```
+ # <action tool="$TOOL_NAME">
+ # $INPUT
+ # </action>
+ # ```
+ thought, _ = action.log.split("Action:")
+ thought = thought.removeprefix("Thought:")
+ thought = thought.strip()
+ self._logs.append(
+ {
+ "id": str(uuid.uuid4()),
+ "type": "thought",
+ "content": thought,
+ "created_at": str(datetime.datetime.now()),
+ }
+ )
+
+ # We save the UUID for this action so we can later
+ # update this action with its output.
self._current_action_id = str(uuid.uuid4())
self._logs.append(
{
@@ -109,6 +135,7 @@ class LogsCallbackHandler(BaseCallbackHandler):
"output": "",
}
)
+
self._database.push_logs(
run_id=self._run_id,
logs=self._logs,
diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.py
index aaa53a96b..4ada33732 100644
--- a/api-service/codegen/prompt.py
+++ b/api-service/codegen/prompt.py
@@ -43,16 +43,16 @@ HUMAN_INSTRUCTIONS_PREFIX = [
{
"variables": ["method"],
"content": """Use this starting template:
- ```
- import express from 'express';
- const app = express();
- const port = 3000;
- app.use(express.json())
- // TODO: Implement the {0} handlers here
- app.listen(port, () => {{
- console.log(`Server listening on port ${{port}}`)
- }})
- ```""",
+```
+import express from 'express';
+const app = express();
+const port = 3000;
+app.use(express.json())
+// TODO: Implement the {0} handlers here
+app.listen(port, () => {{
+ console.log(`Server listening on port ${{port}}`)
+}})
+```""",
},
{
"variables": ["method"],