Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Allow prompt customization [WIP]

Tomas Valenta0b1b339d978a
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 53acec25a..0e03adf42 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -1,7 +1,12 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
- "ghcr.io/devcontainers-contrib/features/poetry:2": {}
+ "ghcr.io/devcontainers-contrib/features/poetry:2": {
+ "version": "latest"
+ },
+ "ghcr.io/shinepukur/devcontainer-features/vale:1": {
+ "version": "latest"
+ }
},
"customizations": {
"vscode": {
@@ -10,7 +15,8 @@
"ms-python.black-formatter",
"ms-python.python",
"ms-python.vscode-pylance",
- "bradlc.vscode-tailwindcss"
+ "bradlc.vscode-tailwindcss",
+ "ChrisChinchilla.vale-vscode"
]
}
}
diff --git a/.gitignore b/.gitignore
index e01093886..5ed4f0fcd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
+
+vale-styles
diff --git a/.vale.ini b/.vale.ini
new file mode 100644
index 000000000..f06b749d9
--- /dev/null
+++ b/.vale.ini
@@ -0,0 +1,8 @@
+StylesPath = vale-styles
+
+MinAlertLevel = suggestion
+
+Packages = Microsoft, proselint, write-good, alex, Readability, Joblint
+
+[*.md]
+BasedOnStyles = Vale, Microsoft, proselint, write-good, alex, Readability, Joblint
\ No newline at end of file
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index e568f278b..37ca5488f 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -4,6 +4,7 @@
"dbaeumer.vscode-eslint",
"ms-python.vscode-pylance",
"ms-python.python",
- "bradlc.vscode-tailwindcss"
+ "bradlc.vscode-tailwindcss",
+ "ChrisChinchilla.vale-vscode"
]
}
\ No newline at end of file
diff --git a/.vscode/recommendations.json b/.vscode/recommendations.json
index e568f278b..37ca5488f 100644
--- a/.vscode/recommendations.json
+++ b/.vscode/recommendations.json
@@ -4,6 +4,7 @@
"dbaeumer.vscode-eslint",
"ms-python.vscode-pylance",
"ms-python.python",
- "bradlc.vscode-tailwindcss"
+ "bradlc.vscode-tailwindcss",
+ "ChrisChinchilla.vale-vscode"
]
}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 000000000..eb7fd539e
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,4 @@
+{
+ "version": "2.0.0",
+ "tasks": []
+}
\ No newline at end of file
diff --git a/api-service/app.py b/api-service/app.py
index 2847afc4a..8e73721f8 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -3,15 +3,15 @@ import uuid
from pprint import pprint
from typing import List
+from codegen.tools.base import create_tools
from dotenv import load_dotenv
from playground_client.exceptions import NotFoundException
from quart import Quart, request
from quart_cors import cors
from codegen import Codegen
-from codegen.tools.playground import create_playground_tools
-from codegen.tools.human.tools import create_human_tools
from database import Database, DeploymentState
+from session.playground.nodejs import NodeJSPlayground
load_dotenv()
@@ -54,8 +54,8 @@ async def generate():
blocks = body["blocks"]
method = body["method"]
route = body["route"]
-
model_config = body["modelConfig"]
+ prompt = body["prompt"]
pprint("+++ Blocks:")
pprint(blocks)
@@ -66,19 +66,18 @@ async def generate():
try:
# Create playground for the LLM
- playground_tools, playground = create_playground_tools(
- get_envs=lambda: db.get_env_vars(project_id),
- )
+ playground = NodeJSPlayground(get_envs=lambda: db.get_env_vars(project_id))
- human_tools = create_human_tools(run_id=run_id, playground=playground)
+ # Create tools
+ tools = create_tools(
+ run_id=run_id,
+ playground=playground,
+ )
# Create a new instance of code generator
cg = Codegen.from_tools_and_database(
# The order in which we pass tools HAS an effect on the LLM behaviour.
- custom_tools=[
- *playground_tools,
- *human_tools,
- ],
+ tools=list(tools),
model_config=model_config,
database=db,
)
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index 009afec90..32ebfa248 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -4,8 +4,9 @@ from typing import (
Any,
Dict,
ClassVar,
+ Sequence,
)
-
+from codegen.callbacks.logs import LogsCallbackHandler
from langchain.agents import AgentExecutor, Agent
from langchain.schema import BaseLanguageModel
from pydantic import BaseModel, PrivateAttr
@@ -19,7 +20,6 @@ from langchain.tools import BaseTool
from models import get_model, ModelConfig
from database import Database
from codegen.agent import CodegenAgent, CodegenAgentExecutor
-from codegen.callbacks.logs import LogsCallbackHandler
from codegen.prompt import (
SYSTEM_PREFIX,
SYSTEM_SUFFIX,
@@ -33,7 +33,7 @@ class Codegen(BaseModel):
input_variables: ClassVar[List[str]] = ["input", "agent_scratchpad", "method"]
_agent: Agent = PrivateAttr()
_agent_executor: AgentExecutor = PrivateAttr()
- _tools: List[BaseTool] = PrivateAttr()
+ _tools: Sequence[BaseTool] = PrivateAttr()
_llm: BaseLanguageModel = PrivateAttr()
_database: Database = PrivateAttr()
_callback_manager: BaseCallbackManager = PrivateAttr()
@@ -42,7 +42,7 @@ class Codegen(BaseModel):
self,
database: Database,
callback_manager: BaseCallbackManager,
- tools: List[BaseTool],
+ tools: Sequence[BaseTool],
llm: BaseLanguageModel,
agent: Agent,
**kwargs: Any,
@@ -67,7 +67,7 @@ class Codegen(BaseModel):
@classmethod
def from_tools_and_database(
cls,
- custom_tools: List[BaseTool],
+ tools: Sequence[BaseTool],
model_config: ModelConfig,
database: Database,
):
@@ -78,7 +78,7 @@ class Codegen(BaseModel):
)
# Assign custom callback manager to custom tools
- for tool in custom_tools:
+ for tool in tools:
tool.callback_manager = callback_manager
# Create the LLM
@@ -91,7 +91,7 @@ class Codegen(BaseModel):
# Create CodegenAgent
agent = CodegenAgent.from_llm_and_tools(
llm=llm,
- tools=custom_tools,
+ tools=tools,
prefix=SYSTEM_PREFIX,
suffix=SYSTEM_SUFFIX,
format_instructions=SYSTEM_FORMAT_INSTRUCTIONS,
@@ -102,7 +102,7 @@ class Codegen(BaseModel):
return cls(
database=database,
callback_manager=callback_manager,
- tools=custom_tools,
+ tools=tools,
llm=llm,
agent=agent,
)
@@ -116,7 +116,9 @@ class Codegen(BaseModel):
):
self._callback_manager.add_handler(
LogsCallbackHandler(
- database=self._database, run_id=run_id, tool_names=self.tool_names()
+ database=self._database,
+ run_id=run_id,
+ tool_names=self.tool_names(),
)
)
@@ -145,58 +147,33 @@ class Codegen(BaseModel):
"route": route,
"method": method,
}
+
instructions = "Here are the instructions:"
- # inst_idx = 0
# Append the premade prefix instructions.
for instruction in get_human_instructions_prefix(
has_request_body=bool(incoming_request_block)
):
- # inst_idx += 1
-
- values = []
- # Extract the correct values from `input_vars` based on the keys.
- for k, v in input_vars.items():
- if k in instruction["variables"]:
- values.append(v)
-
- # Use the values to format the instruction string.
- inst = instruction["content"].format(*values)
- # instructions = instructions + "\n" + f"{inst_idx}. {inst}"
- instructions = instructions + "\n" + f"- {inst}"
+ instructions += "\n" + f"\n- {instruction['content']}"
# Append the use instructions
if instructions_block:
- instructions = (
- instructions
+ instructions += (
+ "\nHere are the required implementation instructions:\n"
+ instructions_block["content"]
)
- print("Instructions:\n", instructions)
+ # Use the values to format the instruction string.
+ instructions = instructions.format(**input_vars)
- ######## +++++ 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"]
+ print("Instructions:\n", instructions)
# Append the premade suffix instructions.
for inst in HUMAN_INSTRUCTIONS_SUFFIX:
- instructions = instructions + f"\n{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
+ instructions += f"\n{inst}"
print("Running executor...")
await self._agent_executor.arun(
agent_scratchpad="",
- # input=testing_instructions
input=instructions,
- method=method,
)
diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.py
index 7c88074ae..d37cdb996 100644
--- a/api-service/codegen/prompt.py
+++ b/api-service/codegen/prompt.py
@@ -35,28 +35,23 @@ SYSTEM_SUFFIX = ""
def get_human_instructions_prefix(has_request_body: bool = False):
yield from [
{
- "variables": ["description"],
- "content": """The handler you are building should do the following: {0}""",
+ "content": """The handler you are building should do the following: {description}""",
},
# {
- # "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": """If you think there might be multiple paths forward, use the tool `LetHumanChoose` to choose from them.""",
# },
]
if has_request_body:
yield {
- "variables": ["request_body"],
- "content": """The incoming request body is JSON that looks like this:\n{0}""",
+ "content": """The incoming request body is JSON that looks like this:\n{request_body}""",
}
yield from [
{
- "variables": ["method"],
"content": """Use this starting template:
```
import express from 'express';
@@ -64,7 +59,7 @@ const app = express();
const port = 3000;
app.use(express.json())
-// TODO: Implement the {0} handler here
+// TODO: Implement the {method} handler here
app.listen(port, async () => {{
console.log(`Server listening on port ${{port}}`)
@@ -72,23 +67,18 @@ app.listen(port, async () => {{
```""",
},
{
- "variables": ["method"],
- "content": """The HTTP request handler is of type {0}""",
+ "content": """The HTTP request handler is of type {method}""",
},
{
- "variables": ["route"],
- "content": """The request handler MUST be on the route `{0}`""",
+ "content": """The request handler MUST be on the route `{route}`""",
},
{
- "variables": [],
"content": """Do not forget to use async and await""",
},
{
- "variables": [],
"content": """Always test that the generated server works without bugs and errors as required by running the code and making mock `curl` requests to the server""",
},
{
- "variables": [],
"content": """Generate the full required server code""",
},
]
diff --git a/api-service/codegen/tools/__init__.py b/api-service/codegen/tools/__init__.py
index e69de29bb..1776c5916 100644
--- a/api-service/codegen/tools/__init__.py
+++ b/api-service/codegen/tools/__init__.py
@@ -0,0 +1,2 @@
+from .base import create_tools
+from .async_tool import async_tool
diff --git a/api-service/codegen/tools/base.py b/api-service/codegen/tools/base.py
new file mode 100644
index 000000000..b72bbc596
--- /dev/null
+++ b/api-service/codegen/tools/base.py
@@ -0,0 +1,32 @@
+from typing import Generator, Any
+from langchain.tools import BaseTool
+
+from session.playground.nodejs import NodeJSPlayground
+
+from .human.tools import create_human_tools
+from .playground.tools.code import create_code_tools
+
+
+def create_tools(
+ run_id: str,
+ playground: NodeJSPlayground,
+) -> Generator[BaseTool, None, None]:
+ # Ensure that the function is a generator even if no tools are yielded
+ yield from ()
+
+ playground_tools: Generator[Any, None, None] = (
+ tool
+ for tools in (
+ tool_factory(playground=playground)
+ for tool_factory in [
+ # create_filesystem_tools,
+ # create_process_tools,
+ create_code_tools,
+ ]
+ )
+ for tool in tools
+ )
+ yield from playground_tools
+
+ human_tools = create_human_tools(run_id, playground)
+ yield from human_tools
diff --git a/api-service/codegen/tools/documentation/__init__.py b/api-service/codegen/tools/documentation/__init__.py
deleted file mode 100644
index dfd0aa7bf..000000000
--- a/api-service/codegen/tools/documentation/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from .tool import ReadDocumentation
diff --git a/api-service/codegen/tools/documentation/readme.md b/api-service/codegen/tools/documentation/readme.md
deleted file mode 100644
index 86bb9a1b7..000000000
--- a/api-service/codegen/tools/documentation/readme.md
+++ /dev/null
@@ -1,117 +0,0 @@
-# [![Itty Router](https://user-images.githubusercontent.com/865416/146679767-16be95b4-5dd7-4bcf-aed7-b8aa8c828f48.png)](https://itty-router.dev)
-
-## Usage
-### 1. Create a Router
-```js
-import { Router } from 'itty-router'
-
-const router = Router() // no "new", as this is not a real class
-```
-
-### 2. Register Route(s)
-##### `router.{method}(route: string, handler1: function, handler2: function, ...)`
-```js
-// register a route on the "GET" method
-router.get('/todos/:user/:item?', (req) => {
- const { params, query } = req
-
- console.log({ params, query })
-})
-```
-
-### 3. Handle Incoming Request(s)
-##### `async router.handle(request.proxy: Proxy || request: Request, ...anything else) => Promise<any>`
-Requests (doesn't have to be a real Request class) should have both a **method** and full **url**.
-The `handle` method will then return a Promise, resolving with the first matching route handler that returns something (or nothing at all if no match).
-
-```js
-router.handle({
- method: 'GET', // required
- url: 'https://example.com/todos/jane/13', // required
-})
-```
-
-#### A few notes about this:
-- **Error Handling:** By default, there is no error handling built in to itty. However, the handle function is async, allowing you to add a `.catch(error)` like this:
-
- ```js
- import { Router } from 'itty-router'
-
- // a generic error handler
- const errorHandler = error =>
- new Response(error.message || 'Server Error', { status: error.status || 500 })
-
- // add some routes (will both safely trigger errorHandler)
- router
- .get('/accidental', request => request.that.will.throw)
- .get('/intentional', () => {
- throw new Error('Bad Request')
- })
-
- // attach the router "handle" to the event handler
- addEventListener('fetch', event =>
- event.respondWith(
- router
- .handle(event.request)
- .catch(errorHandler)
- )
- )
- ```
-- **Extra Variables:** The router handle expects only the request itself, but passes along any additional params to the handlers/middleware. For example, to access the `event` itself within a handler (e.g. for `event.waitUntil()`), you could simply do this:
-
- ```js
- const router = Router()
-
- router.get('/long-task', (request, event) => {
- event.waitUntil(longAsyncTaskPromise)
-
- return new Response('Task is still running in the background!')
- })
-
- addEventListener('fetch', event =>
- event.respondWith(router.handle(event.request, event))
- )
- ```
-- **Proxies:** To allow for some pretty incredible middleware hijacks, we pass `request.proxy` (if it exists) or `request` (if not) to the handler. This allows middleware to set `request.proxy = new Proxy(request.proxy || request, {})` and effectively take control of reads/writes to the request object itself. As an example, the `withParams` middleware in `itty-router-extras` uses this to control future reads from the request. It intercepts "get" on the Proxy, first checking the requested attribute within the `request.params` then falling back to the `request` itself.
-
-## Examples
-
-### File format support
-```js
-// GET item with optional format/extension
-router.get('/todos/:id.:format?', request => {
- const { id, format = 'csv' } = request.params
-
- return new Response(`Getting todo #${id} in ${format} format.`)
-})
-```
-
-### Cloudflare ES6 Module Syntax (required for Durable Objects) <a id="cf-es6-module-syntax"></a>
-See https://developers.cloudflare.com/workers/runtime-apis/fetch-event#syntax-module-worker
-```js
-import { Router } from 'itty-router'
-
-const router = Router()
-
-router.get('/', (request, env, context) => {
- // now have access to the env (where CF bindings like durables, KV, etc now are)
-})
-
-export default {
- fetch: router.handle // yep, it's this easy.
-}
-
-// alternative advanced/manual approach for downstream control
-export default {
- fetch: (request, env, context) => router
- .handle(request, env, context)
- .then(response => {
- // can modify response here before final return, e.g. CORS headers
-
- return response
- })
- .catch(err => {
- // and do something with the errors here, like logging, error status, etc
- })
-}
-```
diff --git a/api-service/codegen/tools/documentation/tool.py b/api-service/codegen/tools/documentation/tool.py
deleted file mode 100644
index ff73f5933..000000000
--- a/api-service/codegen/tools/documentation/tool.py
+++ /dev/null
@@ -1,20 +0,0 @@
-from langchain.tools.base import BaseTool
-
-
-class ReadDocumentation(BaseTool):
- name = "Read Documentation"
- description = (
- "Read quickstart documentation of a third party library or package."
- "The library or package must be hosted on GitHub and publicly accessible."
- "Input must be a link to a public GitHub repository where the library or the package is hosted."
- )
-
- def _run(self, query: str) -> str:
- f = open(
- "/Users/vasekmlejnsky/Developer/ai-api/api-service/codegen/tools/documentation/readme.md",
- "r",
- )
- return f.read()
-
- async def _arun(self, query: str) -> str:
- raise NotImplementedError("ReadDocumentation does not support async")
diff --git a/api-service/codegen/tools/playground/__init__.py b/api-service/codegen/tools/playground/__init__.py
index 311af888a..e69de29bb 100644
--- a/api-service/codegen/tools/playground/__init__.py
+++ b/api-service/codegen/tools/playground/__init__.py
@@ -1 +0,0 @@
-from .main import create_playground_tools
diff --git a/api-service/codegen/tools/playground/main.py b/api-service/codegen/tools/playground/main.py
deleted file mode 100644
index 7a7e4db1a..000000000
--- a/api-service/codegen/tools/playground/main.py
+++ /dev/null
@@ -1,27 +0,0 @@
-from typing import Generator, Tuple, Any
-from langchain.tools import BaseTool
-
-from session.playground.nodejs import NodeJSPlayground
-from session.session import GetEnvs
-
-from .tools.code import create_code_tools
-
-
-def create_playground_tools(
- get_envs: GetEnvs,
-) -> Tuple[Generator[BaseTool, None, None], NodeJSPlayground]:
- playground = NodeJSPlayground(get_envs)
-
- subtools: Generator[Any, None, None] = (
- tool
- for tools in (
- tool_factory(playground=playground)
- for tool_factory in [
- # create_filesystem_tools,
- # create_process_tools,
- create_code_tools,
- ]
- )
- for tool in tools
- )
- return subtools, playground
diff --git a/api-service/poetry.lock b/api-service/poetry.lock
index 440962ae2..ca6a29875 100644
--- a/api-service/poetry.lock
+++ b/api-service/poetry.lock
@@ -536,14 +536,14 @@ files = [
[[package]]
name = "gptcache"
-version = "0.1.10"
+version = "0.1.11"
description = "GPTCache, a powerful caching library that can be used to speed up and lower the cost of chat applications that rely on the LLM service. GPTCache works as a memcache for AIGC applications, similar to how Redis works for traditional applications."
category = "main"
optional = false
python-versions = ">=3.8.1"
files = [
- {file = "gptcache-0.1.10-py3-none-any.whl", hash = "sha256:6d5baaed83784164d1cad29423c4e3433a7ae3a8794f7f4785d44ee27691dc19"},
- {file = "gptcache-0.1.10.tar.gz", hash = "sha256:75f63b181e5ce40aff1859711fe9496bd7569e3b2afcac3ec46cd98a8a0ce974"},
+ {file = "gptcache-0.1.11-py3-none-any.whl", hash = "sha256:114afdfbce429734c11ef50cca7669942a5ab39180b372b187cff5ffb3438c94"},
+ {file = "gptcache-0.1.11.tar.gz", hash = "sha256:d4a18a7587e45916fb406c2e949f2d225cdf1f8fecd0f68ee3de2e7a9cfe30c2"},
]
[package.dependencies]
@@ -910,14 +910,14 @@ i18n = ["Babel (>=2.7)"]
[[package]]
name = "langchain"
-version = "0.0.139"
+version = "0.0.141"
description = "Building applications with LLMs through composability"
category = "main"
optional = false
python-versions = ">=3.8.1,<4.0"
files = [
- {file = "langchain-0.0.139-py3-none-any.whl", hash = "sha256:2ea43780e1f788333f2b741b119d9870640a92c6f5f2d177d1ca0c98463bd097"},
- {file = "langchain-0.0.139.tar.gz", hash = "sha256:4ea86ad6192f45c65cbbdc24ff1a56aaac4bee8c038be982981369ca553590df"},
+ {file = "langchain-0.0.141-py3-none-any.whl", hash = "sha256:6bbabf6ad5743bad41809b76138ddd110db69e7b78919b2f9cb5b3bac6bcf63c"},
+ {file = "langchain-0.0.141.tar.gz", hash = "sha256:245888ff3d4439c0242f3a36669fb83917d39ece4fa6c316d4c34f1de63f532d"},
]
[package.dependencies]
@@ -934,9 +934,9 @@ SQLAlchemy = ">=1,<2"
tenacity = ">=8.1.0,<9.0.0"
[package.extras]
-all = ["aleph-alpha-client (>=2.15.0,<3.0.0)", "anthropic (>=0.2.4,<0.3.0)", "beautifulsoup4 (>=4,<5)", "cohere (>=3,<4)", "deeplake (>=3.2.21,<4.0.0)", "elasticsearch (>=8,<9)", "faiss-cpu (>=1,<2)", "google-api-python-client (==2.70.0)", "google-search-results (>=2,<3)", "huggingface_hub (>=0,<1)", "jina (>=3.14,<4.0)", "jinja2 (>=3,<4)", "manifest-ml (>=0.0.1,<0.0.2)", "networkx (>=2.6.3,<3.0.0)", "nlpcloud (>=1,<2)", "nltk (>=3,<4)", "nomic (>=1.0.43,<2.0.0)", "openai (>=0,<1)", "opensearch-py (>=2.0.0,<3.0.0)", "pgvector (>=0.1.6,<0.2.0)", "pinecone-client (>=2,<3)", "pinecone-text (>=0.4.2,<0.5.0)", "psycopg2-binary (>=2.9.5,<3.0.0)", "pyowm (>=3.3.0,<4.0.0)", "pypdf (>=3.4.0,<4.0.0)", "qdrant-client (>=1.1.2,<2.0.0)", "redis (>=4,<5)", "sentence-transformers (>=2,<3)", "spacy (>=3,<4)", "tensorflow-text (>=2.11.0,<3.0.0)", "tiktoken (>=0.3.2,<0.4.0)", "torch (>=1,<2)", "transformers (>=4,<5)", "weaviate-client (>=3,<4)", "wikipedia (>=1,<2)", "wolframalpha (==5.0.0)"]
+all = ["aleph-alpha-client (>=2.15.0,<3.0.0)", "anthropic (>=0.2.6,<0.3.0)", "beautifulsoup4 (>=4,<5)", "cohere (>=3,<4)", "deeplake (>=3.2.21,<4.0.0)", "elasticsearch (>=8,<9)", "faiss-cpu (>=1,<2)", "google-api-python-client (==2.70.0)", "google-search-results (>=2,<3)", "huggingface_hub (>=0,<1)", "jina (>=3.14,<4.0)", "jinja2 (>=3,<4)", "manifest-ml (>=0.0.1,<0.0.2)", "networkx (>=2.6.3,<3.0.0)", "nlpcloud (>=1,<2)", "nltk (>=3,<4)", "nomic (>=1.0.43,<2.0.0)", "openai (>=0,<1)", "opensearch-py (>=2.0.0,<3.0.0)", "pgvector (>=0.1.6,<0.2.0)", "pinecone-client (>=2,<3)", "pinecone-text (>=0.4.2,<0.5.0)", "psycopg2-binary (>=2.9.5,<3.0.0)", "pyowm (>=3.3.0,<4.0.0)", "pypdf (>=3.4.0,<4.0.0)", "qdrant-client (>=1.1.2,<2.0.0)", "redis (>=4,<5)", "sentence-transformers (>=2,<3)", "spacy (>=3,<4)", "tensorflow-text (>=2.11.0,<3.0.0)", "tiktoken (>=0.3.2,<0.4.0)", "torch (>=1,<3)", "transformers (>=4,<5)", "weaviate-client (>=3,<4)", "wikipedia (>=1,<2)", "wolframalpha (==5.0.0)"]
cohere = ["cohere (>=3,<4)"]
-llms = ["anthropic (>=0.2.4,<0.3.0)", "cohere (>=3,<4)", "huggingface_hub (>=0,<1)", "manifest-ml (>=0.0.1,<0.0.2)", "nlpcloud (>=1,<2)", "openai (>=0,<1)", "torch (>=1,<2)", "transformers (>=4,<5)"]
+llms = ["anthropic (>=0.2.6,<0.3.0)", "cohere (>=3,<4)", "huggingface_hub (>=0,<1)", "manifest-ml (>=0.0.1,<0.0.2)", "nlpcloud (>=1,<2)", "openai (>=0,<1)", "torch (>=1,<3)", "transformers (>=4,<5)"]
openai = ["openai (>=0,<1)"]
qdrant = ["qdrant-client (>=1.1.2,<2.0.0)"]
@@ -2218,4 +2218,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = ">=3.10,<4.0"
-content-hash = "14d477f3b43f15d34b894740b6abaef868f46ec3edbf522f862a987d1eb22b2f"
+content-hash = "b51558c89c58aa0ec8f414f63a75e547f35d0c6ab49a3b1ee935262c60da93ef"
diff --git a/api-service/pyproject.toml b/api-service/pyproject.toml
index 868b4f6ae..240c2e6fb 100644
--- a/api-service/pyproject.toml
+++ b/api-service/pyproject.toml
@@ -18,8 +18,8 @@ quart-cors = "^0.6.0"
quart = "^0.18.4"
replicate = "^0.8.1"
huggingface-hub = "^0.13.4"
-langchain = "^0.0.139"
anthropic = "^0.2.6"
+langchain = "^0.0.141"
[tool.poetry.group.dev]
optional = true
diff --git a/package-lock.json b/package-lock.json
index 5b85b7eed..9fb3d43c0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10,7 +10,7 @@
"hasInstallScript": true,
"dependencies": {
"@devbookhq/splitter": "^1.4.0",
- "@prisma/client": "^4.11.0",
+ "@prisma/client": "^4.12.0",
"@supabase/auth-helpers-nextjs": "^0.5.5",
"@supabase/auth-helpers-react": "^0.3.1",
"@supabase/supabase-js": "^2.10.0",
@@ -25,6 +25,7 @@
"@tiptap/starter-kit": "^2.0.0-beta.220",
"clsx": "^1.2.1",
"fuse.js": "^6.6.2",
+ "handlebars": "^4.7.7",
"http-proxy-middleware": "^3.0.0-beta.1",
"human-id": "^4.0.0",
"immer": "^9.0.19",
@@ -61,7 +62,7 @@
"eslint-plugin-unused-imports": "^2.0.0",
"postcss": "^8.4.21",
"postcss-import": "^15.1.0",
- "prisma": "^4.11.0",
+ "prisma": "^4.12.0",
"supabase": "^1.46.5",
"tailwindcss": "^3.2.7",
"typescript": "^4.9.5"
@@ -430,12 +431,12 @@
}
},
"node_modules/@prisma/client": {
- "version": "4.11.0",
- "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.11.0.tgz",
- "integrity": "sha512-0INHYkQIqgAjrt7NzhYpeDQi8x3Nvylc2uDngKyFDDj1tTRQ4uV1HnVmd1sQEraeVAN63SOK0dgCKQHlvjL0KA==",
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.12.0.tgz",
+ "integrity": "sha512-j9/ighfWwux97J2dS15nqhl60tYoH8V0IuSsgZDb6bCFcQD3fXbXmxjYC8GHhIgOk3lB7Pq+8CwElz2MiDpsSg==",
"hasInstallScript": true,
"dependencies": {
- "@prisma/engines-version": "4.11.0-57.8fde8fef4033376662cad983758335009d522acb"
+ "@prisma/engines-version": "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7"
},
"engines": {
"node": ">=14.17"
@@ -450,16 +451,16 @@
}
},
"node_modules/@prisma/engines": {
- "version": "4.11.0",
- "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.11.0.tgz",
- "integrity": "sha512-0AEBi2HXGV02cf6ASsBPhfsVIbVSDC9nbQed4iiY5eHttW9ZtMxHThuKZE1pnESbr8HRdgmFSa/Kn4OSNYuibg==",
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.12.0.tgz",
+ "integrity": "sha512-0alKtnxhNB5hYU+ymESBlGI4b9XrGGSdv7Ud+8TE/fBNOEhIud0XQsAR+TrvUZgS4na5czubiMsODw0TUrgkIA==",
"devOptional": true,
"hasInstallScript": true
},
"node_modules/@prisma/engines-version": {
- "version": "4.11.0-57.8fde8fef4033376662cad983758335009d522acb",
- "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.11.0-57.8fde8fef4033376662cad983758335009d522acb.tgz",
- "integrity": "sha512-3Vd8Qq06d5xD8Ch5WauWcUUrsVPdMC6Ge8ILji8RFfyhUpqon6qSyGM0apvr1O8n8qH8cKkEFqRPsYjuz5r83g=="
+ "version": "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7",
+ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7.tgz",
+ "integrity": "sha512-JIHNj5jlXb9mcaJwakM0vpgRYJIAurxTUqM0iX0tfEQA5XLZ9ONkIckkhuAKdAzocZ+80GYg7QSsfpjg7OxbOA=="
},
"node_modules/@remirror/core-constants": {
"version": "2.0.0",
@@ -3620,6 +3621,26 @@
"integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==",
"dev": true
},
+ "node_modules/handlebars": {
+ "version": "4.7.7",
+ "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz",
+ "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==",
+ "dependencies": {
+ "minimist": "^1.2.5",
+ "neo-async": "^2.6.0",
+ "source-map": "^0.6.1",
+ "wordwrap": "^1.0.0"
+ },
+ "bin": {
+ "handlebars": "bin/handlebars"
+ },
+ "engines": {
+ "node": ">=0.4.7"
+ },
+ "optionalDependencies": {
+ "uglify-js": "^3.1.4"
+ }
+ },
"node_modules/has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
@@ -5158,6 +5179,11 @@
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
"dev": true
},
+ "node_modules/neo-async": {
+ "version": "2.6.2",
+ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
+ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
+ },
"node_modules/next": {
"version": "13.2.3",
"resolved": "https://registry.npmjs.org/next/-/next-13.2.3.tgz",
@@ -6243,13 +6269,13 @@
}
},
"node_modules/prisma": {
- "version": "4.11.0",
- "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.11.0.tgz",
- "integrity": "sha512-4zZmBXssPUEiX+GeL0MUq/Yyie4ltiKmGu7jCJFnYMamNrrulTBc+D+QwAQSJ01tyzeGHlD13kOnqPwRipnlNw==",
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.12.0.tgz",
+ "integrity": "sha512-xqVper4mbwl32BWzLpdznHAYvYDWQQWK2tBfXjdUD397XaveRyAP7SkBZ6kFlIg8kKayF4hvuaVtYwXd9BodAg==",
"devOptional": true,
"hasInstallScript": true,
"dependencies": {
- "@prisma/engines": "4.11.0"
+ "@prisma/engines": "4.12.0"
},
"bin": {
"prisma": "build/index.js",
@@ -7021,7 +7047,6 @@
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
- "dev": true,
"engines": {
"node": ">=0.10.0"
}
@@ -7694,6 +7719,18 @@
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
"integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
},
+ "node_modules/uglify-js": {
+ "version": "3.17.4",
+ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz",
+ "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
+ "optional": true,
+ "bin": {
+ "uglifyjs": "bin/uglifyjs"
+ },
+ "engines": {
+ "node": ">=0.8.0"
+ }
+ },
"node_modules/unbox-primitive": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz",
@@ -8086,6 +8123,11 @@
"node": ">=0.10.0"
}
},
+ "node_modules/wordwrap": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
+ "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q=="
+ },
"node_modules/wrap-ansi": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
diff --git a/package.json b/package.json
index 9d19b56d3..248e3623f 100644
--- a/package.json
+++ b/package.json
@@ -23,11 +23,12 @@
"supabase:generate": "supabase gen types typescript --project-id \"ntjfcwpzsxugrykskdgi\" --schema public > db/supabase.ts",
"postinstall": "npm run db:generate",
"db:start": "npx --yes supabase start -x imgproxy,storage-api,studio,inbucket,edge-runtime,logflare,postgres-meta,deno-relay,pgadmin-schema-diff,vector,migra",
- "db:stop": "npx --yes supabase stop"
+ "db:stop": "npx --yes supabase stop",
+ "vale:sync": "vale sync"
},
"dependencies": {
"@devbookhq/splitter": "^1.4.0",
- "@prisma/client": "^4.11.0",
+ "@prisma/client": "^4.12.0",
"@supabase/auth-helpers-nextjs": "^0.5.5",
"@supabase/auth-helpers-react": "^0.3.1",
"@supabase/supabase-js": "^2.10.0",
@@ -42,6 +43,7 @@
"@tiptap/starter-kit": "^2.0.0-beta.220",
"clsx": "^1.2.1",
"fuse.js": "^6.6.2",
+ "handlebars": "^4.7.7",
"http-proxy-middleware": "^3.0.0-beta.1",
"human-id": "^4.0.0",
"immer": "^9.0.19",
@@ -78,9 +80,9 @@
"eslint-plugin-unused-imports": "^2.0.0",
"postcss": "^8.4.21",
"postcss-import": "^15.1.0",
- "prisma": "^4.11.0",
+ "prisma": "^4.12.0",
"supabase": "^1.46.5",
"tailwindcss": "^3.2.7",
"typescript": "^4.9.5"
}
-}
\ No newline at end of file
+}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 3a9225245..e49f92722 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -1,6 +1,7 @@
generator js {
provider = "prisma-client-js"
previewFeatures = ["multiSchema", "views"]
+ engineType = "binary"
}
datasource db {
diff --git a/prompt/prompt.ts b/prompt/prompt.ts
new file mode 100644
index 000000000..eb3f5b46e
--- /dev/null
+++ b/prompt/prompt.ts
@@ -0,0 +1,86 @@
+
+
+const systemPrefix = `
+You are an AI JavaScript developer assistant.
+- You are building an Express server that handles REST API.
+- The \`express\` package is already installed.
+- Follow the user's instructions carefully & to the letter.
+- Minimize any other prose.
+- You have access to the following tools:
+`
+
+
+const systemFormatInstructions = `
+The way you use the tools is by specifying a XML snippet.
+The XML snippet MUST have a \`<action tool="$TOOL_NAME">$INPUT</action>\` element with the name of the tool in the \`tool\` attribute and input for the tool inside the XML tag.
+
+Here is an example of a valid XML snippet:
+<action tool="$TOOL_NAME">
+$INPUT
+</action>
+
+ALWAYS use the following format:
+
+
+Thought: you should always think about what to do
+Action:
+<action tool="$TOOL_NAME">
+$INPUT
+</action>
+Observation: the result of the action
+... (this Thought/Action/Observation can repeat N times)
+Thought: I now know the final server code and can show it.
+Final Answer: the final answer
+`
+
+const systemSuffix = ''
+
+
+const humanInstructionsPrefix = `
+The handler you are building should do the following: {{description}}
+Do not try to come up with solutions and code if you do not know. Instead, use the tool \`AskHuman\` to ask for help.
+If you think there might be multiple paths forward, use the tool \`LetHumanChoose\` to choose from them.
+{{#if request_body}}
+The incoming request body is JSON that looks like this:
+{{request_body}}
+{{/if}}
+Use this starting template:
+\`\`\`
+import express from 'express';
+const app = express();
+const port = 3000;
+app.use(express.json())
+
+// TODO: Implement the {method} handler here
+
+app.listen(port, async () => {{
+ console.log(\`Server listening on port \${port}\`)
+}})
+\`\`\`
+The HTTP request handler is of type {{method}}
+The request handler MUST be on the route \`{{route}}\`
+Do not forget to use async and await
+Always test that the generated server works without bugs and errors as required by running the code and making mock \`curl\` requests to the server
+Generate the full required server code
+`
+
+const humanInstructionsSuffic = `
+Thought: Here is the plan of how I will go about solving this:\n
+`
+
+
+
+export function getPromptTemplate(templateID: string) {
+
+
+
+
+}
+
+
+
+
+
+export function getPrompt() {
+
+}