Преглед на файлове

Server: load environment variables from .env and document environment variables (#137)

Server: load environment variables from .env and document environment variables
Jim Su преди 1 година
родител
ревизия
430527680f
променени са 4 файла, в които са добавени 42 реда и са изтрити 13 реда
  1. 6 2
      agenthub/__init__.py
  2. 2 1
      agenthub/codeact_agent/__init__.py
  3. 29 5
      opendevin/server/README.md
  4. 5 5
      opendevin/server/session.py

+ 6 - 2
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']

+ 2 - 1
agenthub/codeact_agent/__init__.py

@@ -1,8 +1,9 @@
 import os
 import re
-from termcolor import colored
 from typing import List, Mapping
 
+from termcolor import colored
+
 from opendevin.agent import Agent
 from opendevin.state import State
 from opendevin.action import (

+ 29 - 5
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/activate
 python -m pip install -r requirements.txt
+```
+
+## Start the Server
+
+```sh
 uvicorn opendevin.server.listen:app --reload --port 3000
 ```
 
 ## Test the Server
+
 You can use `websocat` to test the server: https://github.com/vi/websocat
 
-```
+```sh
 websocat 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
+```

+ 5 - 5
opendevin/server/session.py

@@ -4,10 +4,6 @@ from typing import Optional, Dict, Type
 
 from 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 LLM
 from 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_NAME
         if start_event and "model" in start_event.args:
             model = start_event.args["model"]
         if not os.path.exists(directory):