Skip to content

Commit fb18221

Browse files
authored
Adding pre-commit and CI for ruff and mypy (OpenHands#69)
* don't modify directories * oops typo * dev_config/python * add config to CI * bump CI python to 3.10 * 3.11? * del actions/ * add suggestions * delete unused code * missed some * oops missed another one * remove a file
1 parent 642e1b3 commit fb18221

17 files changed

Lines changed: 88 additions & 47 deletions

File tree

.github/workflows/lint.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Lint
33
on: [push, pull_request]
44

55
jobs:
6-
lint:
6+
lint-frontend:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
@@ -15,4 +15,20 @@ jobs:
1515
npm ci --legacy-peer-deps
1616
- run: |
1717
cd frontend
18-
npm run lint
18+
npm run lint
19+
20+
lint-python:
21+
name: Lint python
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Set up python
26+
uses: actions/setup-python@v2
27+
with:
28+
python-version: 3.11
29+
- name: Install dependencies
30+
run: pip install ruff mypy types-requests
31+
- name: Run ruff
32+
run: ruff check --config dev_config/python/ruff.toml opendevin/ server/ agenthub/
33+
- name: Run mypy
34+
run: mypy --config-file dev_config/python/mypy.ini opendevin/ server/ agenthub/

agenthub/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from . import langchains_agent
22
from . import codeact_agent
3+
4+
__all__ = ['langchains_agent', 'codeact_agent']

agenthub/codeact_agent/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
import re
3-
import argparse
43
from litellm import completion
54
from termcolor import colored
65
from typing import List, Dict
76

87
from opendevin.agent import Agent, Message, Role
8+
from opendevin.lib.event import Event
9+
from opendevin.lib.command_manager import CommandManager
910
from opendevin.sandbox.sandbox import DockerInteractive
1011

1112
assert (
@@ -93,12 +94,13 @@ def run(self) -> None:
9394
command = re.search(r"<execute>(.*)</execute>", action, re.DOTALL)
9495
if command is not None:
9596
# a command was found
96-
command = command.group(1)
97-
if command.strip() == "exit":
97+
command_group = command.group(1)
98+
if command_group.strip() == "exit":
9899
print(colored("Exit received. Exiting...", "red"))
99100
break
100101
# execute the code
101-
observation = self.env.execute(command)
102+
# TODO: does exit_code get loaded into Message?
103+
exit_code, observation = self.env.execute(command_group)
102104
self._history.append(Message(Role.ASSISTANT, observation))
103105
print(colored("===ENV OBSERVATION:===\n" + observation, "blue"))
104106
else:
@@ -120,5 +122,15 @@ def chat(self, message: str) -> None:
120122
"""
121123
raise NotImplementedError
122124

125+
# TODO: implement these abstract methods
126+
def add_event(self, event: Event) -> None:
127+
raise NotImplementedError("Implement this abstract method")
128+
129+
def step(self, cmd_mgr: CommandManager) -> Event:
130+
raise NotImplementedError("Implement this abstract method")
131+
132+
def search_memory(self, query: str) -> List[str]:
133+
raise NotImplementedError("Implement this abstract method")
134+
123135

124136
Agent.register("CodeActAgent", CodeActAgent)

agenthub/langchains_agent/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import os
2-
import argparse
3-
from typing import List, Dict, Type
1+
from typing import List
42

5-
from opendevin.agent import Agent, Message
3+
from opendevin.agent import Agent
64

75
from agenthub.langchains_agent.utils.agent import Agent as LangchainsAgentImpl
86
from opendevin.lib.event import Event

agenthub/langchains_agent/utils/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set_debug(True)
88

99
from typing import List
10-
from langchain_core.pydantic_v1 import BaseModel, Field
10+
from langchain_core.pydantic_v1 import BaseModel
1111

1212
from langchain.chains import LLMChain
1313
from langchain.prompts import PromptTemplate

agenthub/langchains_agent/utils/memory.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
import os
21
from . import json
32

43
import chromadb
54

65
from llama_index.core import Document
76
from llama_index.core.retrievers import VectorIndexRetriever
8-
from llama_index.core import VectorStoreIndex, StorageContext, load_index_from_storage
9-
from llama_index.core.storage.docstore import SimpleDocumentStore
10-
from llama_index.core.vector_stores import SimpleVectorStore
11-
7+
from llama_index.core import VectorStoreIndex
128
from llama_index.vector_stores.chroma import ChromaVectorStore
139

1410
class LongTermMemory:
1511
def __init__(self):
1612
db = chromadb.Client()
1713
self.collection = db.create_collection(name="memories")
1814
vector_store = ChromaVectorStore(chroma_collection=self.collection)
19-
storage_context = StorageContext.from_defaults(vector_store=vector_store)
2015
self.index = VectorStoreIndex.from_vector_store(vector_store)
2116
self.thought_idx = 0
2217

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.3.3
4+
hooks:
5+
- id: ruff
6+
entry: ruff check --config dev_config/python/ruff.toml opendevin/ server/ agenthub/
7+
always_run: true
8+
pass_filenames: false
9+
10+
- repo: https://github.com/pre-commit/mirrors-mypy
11+
rev: v1.9.0
12+
hooks:
13+
- id: mypy
14+
additional_dependencies: [types-requests, types-setuptools]
15+
entry: mypy --config-file dev_config/python/mypy.ini opendevin/ server/ agenthub/
16+
always_run: true
17+
pass_filenames: false

dev_config/python/mypy.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[mypy]
2+
warn_unused_configs = True
3+
ignore_missing_imports = True
4+
check_untyped_defs = True
5+
explicit_package_bases = True
6+
warn_unreachable = True
7+
warn_redundant_casts = True
8+
no_implicit_optional = True
9+
strict_optional = True
10+
11+
exclude = agenthub/langchains_agent/regression

dev_config/python/ruff.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exclude = [
2+
"agenthub/langchains_agent/regression/",
3+
]

opendevin/agent.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from .lib.event import Event
77
from .lib.command_manager import CommandManager
8-
from .controller import AgentController
98

109
class Role(Enum):
1110
SYSTEM = "system" # system message for LLM
@@ -79,7 +78,7 @@ def complete(self) -> bool:
7978
return self._complete
8079

8180
@property
82-
def history(self) -> List[str]:
81+
def history(self) -> List[Message]:
8382
"""
8483
Provides the history of interactions or state changes since the instruction was initiated.
8584
@@ -125,7 +124,7 @@ def reset(self) -> None:
125124
to prepare the agent for restarting the instruction or cleaning up before destruction.
126125
127126
"""
128-
self.instruction = None
127+
self.instruction = ''
129128
self._complete = False
130129
self._history = []
131130

0 commit comments

Comments
 (0)