π OpenHands: AI-Driven Development
Server: load environment variables from .env and document environment variables (#137)
Jim Su430527680f3d
diff --git a/agenthub/__init__.py b/agenthub/__init__.pyindex 4678f96538..a976927218 100644--- a/agenthub/__init__.py+++ b/agenthub/__init__.py@@ -1,4 +1,8 @@-from . import langchains_agent-from . import codeact_agent+from dotenv import load_dotenv+load_dotenv()++# Import agents after environment variables are loaded+from . import langchains_agent # noqa: E402+from . import codeact_agent # noqa: E402__all__ = ['langchains_agent', 'codeact_agent']diff --git a/agenthub/codeact_agent/__init__.py b/agenthub/codeact_agent/__init__.pyindex aa5a2e4d0e..a0c393b188 100644--- a/agenthub/codeact_agent/__init__.py+++ b/agenthub/codeact_agent/__init__.py@@ -1,8 +1,9 @@import osimport re-from termcolor import coloredfrom typing import List, Mapping+from termcolor import colored+from opendevin.agent import Agentfrom opendevin.state import Statefrom opendevin.action import (diff --git a/opendevin/server/README.md b/opendevin/server/README.mdindex 21e7fe9b74..134f7ac3c9 100644--- a/opendevin/server/README.md+++ b/opendevin/server/README.md@@ -1,18 +1,42 @@-# OpenDevin server-This is currently just a POC that starts an echo websocket inside docker, and-forwards messages between the client and the docker container.+# OpenDevin Server-## Start the Server+This is a WebSocket server that executes tasks using an agent.++## Install++Create a `.env` file with the contents++```sh+OPENAI_API_KEY=<YOUR OPENAI API KEY>```++Install requirements:++```sh+python3.12 -m venv venv+source venv/bin/activatepython -m pip install -r requirements.txt+```++## Start the Server++```shuvicorn opendevin.server.listen:app --reload --port 3000```## Test the Server+You can use `websocat` to test the server: https://github.com/vi/websocat-```+```shwebsocat ws://127.0.0.1:3000/ws{"action": "start", "args": {"task": "write a bash script that prints hello"}}```+## Supported Environment Variables++```sh+OPENAI_API_KEY=sk-... # Your OpenAI API Key+MODEL_NAME=gpt-4-0125-preview # Default model for the agent to use+WORKSPACE_DIR=/path/to/your/workspace # Default path to model's workspace+```diff --git a/opendevin/server/session.py b/opendevin/server/session.pyindex 49465b4ec0..bbe44b8a5a 100644--- a/opendevin/server/session.py+++ b/opendevin/server/session.py@@ -4,10 +4,6 @@ from typing import Optional, Dict, Typefrom fastapi import WebSocketDisconnect-from opendevin.agent import Agent-from opendevin.controller import AgentController-from opendevin.llm.llm import LLM-from opendevin.action import (Action,CmdRunAction,@@ -19,6 +15,9 @@ from opendevin.action import (AgentThinkAction,AgentFinishAction,)+from opendevin.agent import Agent+from opendevin.controller import AgentController+from opendevin.llm.llm import LLMfrom opendevin.observation import (Observation,UserMessageObservation@@ -38,6 +37,7 @@ ACTION_TYPE_TO_CLASS: Dict[str, Type[Action]] = {DEFAULT_WORKSPACE_DIR = os.getenv("WORKSPACE_DIR", os.path.join(os.getcwd(), "workspace"))+MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4-0125-preview")def parse_event(data):if "action" not in data:@@ -119,7 +119,7 @@ class Session:agent_cls = "LangchainsAgent"if start_event and "agent_cls" in start_event.args:agent_cls = start_event.args["agent_cls"]- model = "gpt-4-0125-preview"+ model = MODEL_NAMEif start_event and "model" in start_event.args:model = start_event.args["model"]if not os.path.exists(directory):