Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Improve contributing guide
Tomas Valenta2815887ba35a
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex ac5b23034..8b79d0f94 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -1,101 +1,44 @@# ContributingIf you want to contribute open a PR, issue, or start a discussion on our [Discord](https://discord.gg/dSBY3ms2Qr).-## Adding new models or new model hosting providers-If you want to add a new model (like OpenAI's GPT-4) or a new model hosting provider (like HuggingFace where you can host your models) complete the following steps and create a PR.--1. Add model on **frontend**- - Add a model name to `enum ModelProvider` in [state/model.ts](state/model.ts)- - Add model template to `const modelTemplates` in [state/model.ts](state/model.ts)- > `creds` and `args` defined in the `modelTemplates` are accessible on backend in `get_model` under their exact names in `config["args"]` object.- - Add the model's PNG icon image to `public/`- - Add a new model icon path to `const iconPaths` in [components/icons/ProviderIcon.tsx](components/icons/ProviderIcon.tsx)--2. Add model on **backend** in [api-service/models/base.py](api-service/models/base.py)- - Add model name to enum `ModelProvider`- - Add model integration (implementing langchain's `BaseLanguageModel`) to `def get_model`. You can often use the [langchain's](https://python.langchain.com/en/latest/modules/models/llms/integrations.html) integrations.- > Sometimes we need to modify integrations provided by langchain (to ignore env vars, etc.). If you modify the integrations add them like [this](api-service/models/wrappers/replicate.py).--3. Test if the new model works by starting the app, configuring the model, and trying to "Run" it. Add a screenshot of the results to the PR if you can.--### Example of adding a new model/model hosting provider-#### **Frontend**-[state/model.ts](state/model.ts)-```ts-export enum ModelProvider {- ...- NewModel = 'NewModel',- ...-}--export const modelTemplates: {- [provider in keyof typeof ModelProvider]?: ProviderTemplate-} = {- ...- [ModelProvider.NewModel]: {- creds: {- new_model_api_token: { // <----- this will be accessible as `config["args"]["new_model_api_token"]` on backend- label: 'New Model API Key',- type: 'string',- },- },- models: [- {- name: '<Model name>',- args: {- temperature: { // <----- this will be accessible as `config["args"]["temperature"]` on backend- label: 'Temperature',- editable: true,- type: 'number',- value: 0.4,- min: 0.01,- max: 1,- step: 0.01,- },- },- },- ],- },- ...-}-```+# π€ Adding a new model provider+If you want to add a new model provider (like OpenAI or HuggingFace) complete the following steps and create a PR.-[components/icons/ProviderIcon.tsx](components/icons/ProviderIcon.tsx)-```ts-const iconPaths: {- [provider in keyof typeof ModelProvider]: string-} = {- ...- [ModelProvider.NewModel]: '/new-model.png',- ...-}-```+When you add a provider you can also add a specific models (like OpenAI's GPT-4) under that provider.++Here is an [example code for adding a new provider](./NEW_PROVIDER_EXAMPLE.md).++## βοΈ 1. Add provider to **frontend**+- Add provider name to `ModelProvider` enum in [state/model.ts](state/model.ts)+- Add provider and models template to `modelTemplates` object in [state/model.ts](state/model.ts)+ - `creds` and `args` defined in the `modelTemplates` are accessible on backend in `get_model` under their exact names in `config["args"]` object.+- Add provider's PNG icon image to `public/`+- Add provider's icon path to `iconPaths` object in [components/icons/ProviderIcon.tsx](components/icons/ProviderIcon.tsx)++## βοΈ 2. Add provider to **backend** ([api-service/models/base.py](api-service/models/base.py))+- Add provider name to `ModelProvider` enum+- Add provider integration (implementing langchain's `BaseLanguageModel`) to `get_model` function. You can either use an existing integration from langchain or crate a new integration from scratch.++### **Provider integration with existing [langchain](https://python.langchain.com/en/latest/modules/models/llms/integrations.html) integrations**+You can often use existing langchain integrations to add new model providers to e2b with just a few modifications.++[Here](api-service/models/wrappers/replicate.py) is an example of modified [Replicate](https://replicate.com/) integration. We had to add `_acall` method to support async execution and override `validate_environment` to prevent checking if the Replicate API key env var is set up because we pass the env var via a normal parameter.++If you are modifying existing langchain integration add it to `api-service/models/providers/<provider>.py`.++### **Provider integration from scratch**+You can follow the [langchain's guide](https://python.langchain.com/en/latest/modules/models/llms/examples/custom_llm.html) to implement the `LLM` class (it inherits from `BaseLanguageModel`). Here is an [example of provider integration](./NEW_PROVIDER_EXAMPLE.md#custom-provider-integration-api-servicemodelsprovidersnew_model_providerpy-with-streaming). You really only need to implement the `_acall` method.++If you are creating new provider integration add it to `api-service/models/providers/<provider>.py`.+++## βοΈ 3. Test+Test if the provider works by starting the app, selecting the provider and model in the "Model" sidebar menu and trying to "Run" it.++Add a screenshot of the results to the PR if you can.-#### **Backend**-[api-service/models/base.py](api-service/models/base.py)-```py-class ModelProvider(Enum):- ...- NewModel = "NewModel"- ...--def get_model(- config: ModelConfig,- callback_manager: BaseCallbackManager,-) -> BaseLanguageModel:- match config["provider"]:- ...- case ModelProvider.NewModel.value:- return NewModelIntegration( # <----- class implementing `BaseLanguageModel`- **config["args"], # <----- args passed from frontend (`new_model_api_token`, `temperature`)- verbose=True,- streaming=True,- callback_manager=callback_manager,- )- ...-```-## π» Development setup+# π» Development setupFor developing with hot reloading and contributing to the project you may want to run the app locally without Docker Compose (`npm start` command). Here are the steps for how to do it.You will need:@@ -106,19 +49,19 @@ You will need:- Poetry *1.3.2+*- Free ports 3000, 49155, 49160, 54321, 54322-### 1. Install dependencies+## 1. Install dependencies```npm run install:all```-### 2. Start local Supabase+## 2. Start local Supabase```npm run db:start```> Local Supabase runs in the background - to stop it you have to run `npm run db:stop`.-### 3. Add env vars+## 3. Add env varsCreate `.env` file by copying the [`.env.example`](.env.example)```cp .env.example .env@@ -127,7 +70,7 @@ and fill in the following variables:- `SUPABASE_SERVICE_ROLE_KEY` - Supabase service role key you got in the previous step as `service_role key: eyJh......`- `NEXT_PUBLIC_SUPABASE_ANON_KEY` - Supabase anonymous key you got in the previous step as `anon key: eyJh......`-### 4. Start the app+## 4. Start the app```npm run dev```diff --git a/NEW_PROVIDER_EXAMPLE.md b/NEW_PROVIDER_EXAMPLE.mdnew file mode 100644index 000000000..bccf5e245--- /dev/null+++ b/NEW_PROVIDER_EXAMPLE.md@@ -0,0 +1,142 @@+# Example of adding a new provider++## Add on **frontend**+[state/model.ts](state/model.ts)+```ts+export enum ModelProvider {+ ...+ NewProvider = 'NewProvider',+ ...+}++export const modelTemplates: {+ [provider in keyof typeof ModelProvider]?: ProviderTemplate+} = {+ ...+ [ModelProvider.NewProvider]: {+ creds: { // If the provider requires any keys specify them here+ new_provider_api_token: { // This will be accessible as `config["args"]["new_provider_api_token"]` on backend+ label: 'New Provider API Key',+ type: 'string',+ },+ },+ models: [ // You define specific models for this provider+ {+ name: 'New provider\'s model',+ args: {+ temperature: { // This will be accessible as `config["args"]["temperature"]` on backend+ label: 'Temperature',+ editable: true, // make this arg editable by user+ type: 'number',+ value: 0.4,+ min: 0.01,+ max: 1,+ step: 0.01,+ },+ },+ },+ ],+ },+ ...+}+```++[components/icons/ProviderIcon.tsx](components/icons/ProviderIcon.tsx)+```ts+const iconPaths: {+ [provider in keyof typeof ModelProvider]: string+} = {+ ...+ [ModelProvider.NewProvider]: '/new-provider.png',+ ...+}+```++## Add on **backend**+[api-service/models/base.py](api-service/models/base.py)+```py+class ModelProvider(Enum):+ ...+ NewProvider = "NewProvider"+ ...++def get_model(+ config: ModelConfig,+ callback_manager: BaseCallbackManager,+) -> BaseLanguageModel:+ match config["provider"]:+ ...+ case ModelProvider.NewProvider.value:+ return NewModelProviderIntegration( # Class implementing `BaseLanguageModel`+ **config["args"], # Args passed from frontend (`new_model_api_token`, `temperature`)+ verbose=True,+ streaming=True,+ callback_manager=callback_manager,+ )+ ...+```++## Custom provider integration (`api-service/models/providers/new_model_provider.py`) with streaming+```py+from typing import List, Optional+from langchain.llms.base import LLM++class NewModelProviderWithStreaming(LLM):+ temperature: str+ new_provider_api_token: str++ # You only need to implement the `_acall` method+ async def _acall(self, prompt: str, stop: Optional[List[str]] = None) -> str:+ # Call the model and get outputs+ # You can use `temperature` and `new_provider_api_token` args++ text = ""+ for token in outputs:+ text += token+ if self.callback_manager.is_async:+ await self.callback_manager.on_llm_new_token(+ token,+ verbose=self.verbose,+ # We explicitly flush the logs in log queue because the calls to this model are not actually async so they block.+ flush=True,+ )+ else:+ self.callback_manager.on_llm_new_token(+ token,+ verbose=self.verbose,+ )++ return text++```++## Custom provider integration (`api-service/models/providers/new_model_provider.py`) without streaming+```py+from typing import List, Optional+from langchain.llms.base import LLM++class NewModelProviderWithoutStreaming(LLM):+ temperature: str+ new_provider_api_token: str++ # You only need to implement the `_acall` method+ async def _acall(self, prompt: str, stop: Optional[List[str]] = None) -> str:+ # Call the model and get output+ # You can use `temperature` and `new_provider_api_token` args++ if self.callback_manager.is_async:+ await self.callback_manager.on_llm_new_token(+ output,+ verbose=self.verbose,+ # We explicitly flush the logs in log queue because the calls to this model are not actually async so they block.+ flush=True,+ )+ else:+ self.callback_manager.on_llm_new_token(+ output,+ verbose=self.verbose,+ )++ return output++```diff --git a/README.md b/README.mdindex 4e80d2e08..91daefdbe 100644--- a/README.md+++ b/README.md@@ -23,7 +23,11 @@*Example of AI agent building Stripe checkout. Left - technical specification written by human. Right - steps that the AI agent took and tools that it used to build the server route required by the specification.*-[e2b](https://e2b.dev) or etob (*english2bits*) is a new kind of development environment powered by AI. The main idea is that developers have access to AI agents that can use tools. The developer writes a short documentation or a technical spec in plain English and then lets the AI agent do the actual work. The AI agents have access to tools like writing to a file, running code, running commands, installing dependencies, deploying, etc. Agents operate in a secure sandboxed cloud environment that's powered by [Firecracker](https://github.com/firecracker-microvm/firecracker/). This way, you for example describe what a server route should do and the agent codes it for you. Like [this example](https://twitter.com/mlejva/status/1641072535163875330) of an AI agent coding Stripe customer checkout based on a technical spec.+[e2b](https://e2b.dev) or etob (*english2bits*) is a new kind of development environment powered by AI. The main idea is that developers have access to AI agents that can use tools.++The developer writes a short documentation or a technical spec in plain English and then lets the AI agent do the actual work. The AI agents have access to tools like writing to a file, running code, running commands, installing dependencies, deploying, etc.++Agents operate in a secure sandboxed cloud environment that's powered by [Firecracker](https://github.com/firecracker-microvm/firecracker/). This way, you for example describe what a server route should do and the agent codes it for you. Like [this example](https://twitter.com/mlejva/status/1641072535163875330) of an AI agent coding Stripe customer checkout based on a technical spec.e2b currently supports building only REST servers in Node.js. Specifically using the [Express](https://expressjs.com/) framework. We'll support more languages and frameworks with time. The goal for e2b is to eventually be able to handle any use-case.@@ -46,7 +50,7 @@ Then open the page on [http://localhost:3000](http://localhost:3000).> `npm start` starts local Supabase in the background - to stop it you have to run `npm run stop`.-> If you want to run the project without using containers use the [steps here](./CONTRIBUTING.md#π»-development-setup). This is useful if you want to leverage hot reloading and develop the project.+> If you want to run non-containerize version of e2b use the [development setup here](CONTRIBUTING.md#π»-development-setup). This is useful if you want to leverage hot reloading and develop the project.# Features@@ -59,7 +63,7 @@ While e2b will offer the "batteries-included" solution, our goal is to let usersWe think the AI-powered IDE for the future should be open-sourced and allow anybody to bring their models, customize the prompts, and develop custom tools for the agents. But we also plan to offer a cloud version with some features behind subscription though.-## π€ Supported models and hosting providers+## π€ Supported models and model hosting providers- [x] [OpenAI](https://openai.com/)- [x] GPT-4- [x] GTP-3.5@@ -69,11 +73,11 @@ We think the AI-powered IDE for the future should be open-sourced and allow anyb- [ ] Claude v1.3- [ ] Claude Instant v1-### **Model you like isn't supported?**+### **Model or provider you like isn't supported?**π Please open the ["New model request" issue](https://github.com/e2b-dev/e2b/issues/new?assignees=&labels=new+model+request&template=new-model-request.md&title=) π-π Or open a PR and [start contributing](./CONTRIBUTING.md#adding-new-models-or-new-model-hosting-providers) π+π Or open a PR and [start contributing](./CONTRIBUTING.md#π€-adding-a-new-model-provider) π## π Early demos- [AI Agent using coding tools](https://twitter.com/mlejva/status/1636103084802822151)diff --git a/api-service/models/base.py b/api-service/models/base.pyindex 9b204d8b9..29b3b4ce0 100644--- a/api-service/models/base.py+++ b/api-service/models/base.py@@ -5,7 +5,7 @@ from langchain.llms import HuggingFaceHub, Anthropicfrom langchain.schema import BaseLanguageModelfrom langchain.callbacks.base import BaseCallbackManager-from .wrappers.replicate import ReplicateFix+from .providers.replicate import ReplicateFixclass ModelProvider(Enum):diff --git a/api-service/models/wrappers/__init__.py b/api-service/models/providers/__init__.pysimilarity index 100%rename from api-service/models/wrappers/__init__.pyrename to api-service/models/providers/__init__.pydiff --git a/api-service/models/wrappers/huggingface_endpoint.py b/api-service/models/providers/huggingface_endpoint.pysimilarity index 100%rename from api-service/models/wrappers/huggingface_endpoint.pyrename to api-service/models/providers/huggingface_endpoint.pydiff --git a/api-service/models/wrappers/replicate.py b/api-service/models/providers/replicate.pysimilarity index 100%rename from api-service/models/wrappers/replicate.pyrename to api-service/models/providers/replicate.py