forked from All-Hands-AI/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address conflicts; Merge commit '0322693ec2183cbb340d570c475d67bd44f5…
…7f19' into print-with-color
- Loading branch information
Showing
160 changed files
with
2,828 additions
and
41,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Build and publish multi-arch container images | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: 'Why manual trigger?' | ||
required: false | ||
default: '' | ||
|
||
jobs: | ||
ghcr_build_and_push: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log-in to ghcr.io | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Build and push multi-arch container images | ||
run: | | ||
# set env for fork repo | ||
DOCKER_BUILD_ORG=$(echo "${{ github.repository }}" | tr '[A-Z]' '[a-z]' | cut -d '/' -f 1) | ||
# Find directories containing Dockerfile but not containing .dockerfileignore | ||
while IFS= read -r dockerfile_dir; do | ||
# Check if .dockerfileignore exists in the directory | ||
if [ ! -f "$dockerfile_dir/.dockerfileignore" ]; then | ||
# Change directory and execute 'make all' | ||
pushd "$dockerfile_dir" > /dev/null | ||
make all DOCKER_BUILD_ORG=$DOCKER_BUILD_ORG | ||
popd > /dev/null | ||
fi | ||
done < <(find . -type f -name Dockerfile -exec dirname {} \; | sort -u) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,4 @@ yarn-error.log* | |
# agent | ||
.envrc | ||
/workspace | ||
/debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,4 @@ | ||
import os | ||
import re | ||
from typing import List, Mapping | ||
|
||
from opendevin.agent import Agent | ||
from opendevin.state import State | ||
from opendevin.action import ( | ||
Action, | ||
CmdRunAction, | ||
AgentEchoAction, | ||
AgentFinishAction, | ||
) | ||
from opendevin.observation import ( | ||
CmdOutputObservation, | ||
AgentMessageObservation, | ||
) | ||
|
||
from opendevin.llm.llm import LLM | ||
|
||
assert ( | ||
"OPENAI_API_KEY" in os.environ | ||
), "Please set the OPENAI_API_KEY environment variable." | ||
|
||
|
||
|
||
SYSTEM_MESSAGE = """You are a helpful assistant. You will be provided access (as root) to a bash shell to complete user-provided tasks. | ||
You will be able to execute commands in the bash shell, interact with the file system, install packages, and receive the output of your commands. | ||
DO NOT provide code in ```triple backticks```. Instead, you should execute bash command on behalf of the user by wrapping them with <execute> and </execute>. | ||
For example: | ||
You can list the files in the current directory by executing the following command: | ||
<execute>ls</execute> | ||
You can also install packages using pip: | ||
<execute> pip install numpy </execute> | ||
You can also write a block of code to a file: | ||
<execute> | ||
echo "import math | ||
print(math.pi)" > math.py | ||
</execute> | ||
When you are done, execute "exit" to close the shell and end the conversation. | ||
""" | ||
|
||
INVALID_INPUT_MESSAGE = ( | ||
"I don't understand your input. \n" | ||
"If you want to execute command, please use <execute> YOUR_COMMAND_HERE </execute>.\n" | ||
"If you already completed the task, please exit the shell by generating: <execute> exit </execute>." | ||
) | ||
|
||
|
||
def parse_response(response) -> str: | ||
action = response.choices[0].message.content | ||
if "<execute>" in action and "</execute>" not in action: | ||
action += "</execute>" | ||
return action | ||
|
||
|
||
class CodeActAgent(Agent): | ||
def __init__( | ||
self, | ||
llm: LLM, | ||
) -> None: | ||
""" | ||
Initializes a new instance of the CodeActAgent class. | ||
Parameters: | ||
- instruction (str): The instruction for the agent to execute. | ||
- max_steps (int): The maximum number of steps to run the agent. | ||
""" | ||
super().__init__(llm) | ||
self.messages: List[Mapping[str, str]] = [] | ||
self.instruction: str = "" | ||
|
||
def step(self, state: State) -> Action: | ||
if len(self.messages) == 0: | ||
assert self.instruction, "Expecting instruction to be set" | ||
self.messages = [ | ||
{"role": "system", "content": SYSTEM_MESSAGE}, | ||
{"role": "user", "content": self.instruction}, | ||
] | ||
updated_info = state.updated_info | ||
if updated_info: | ||
for prev_action, obs in updated_info: | ||
assert isinstance(prev_action, (CmdRunAction, AgentEchoAction)), "Expecting CmdRunAction or AgentEchoAction for Action" | ||
if isinstance(obs, AgentMessageObservation): # warning message from itself | ||
self.messages.append({"role": "user", "content": obs.content}) | ||
elif isinstance(obs, CmdOutputObservation): | ||
content = "OBSERVATION:\n" + obs.content | ||
content += f"\n[Command {obs.command_id} finished with exit code {obs.exit_code}]]" | ||
self.messages.append({"role": "user", "content": content}) | ||
else: | ||
raise NotImplementedError(f"Unknown observation type: {obs.__class__}") | ||
response = self.llm.completion( | ||
messages=self.messages, | ||
stop=["</execute>"], | ||
temperature=0.0, | ||
seed=42, | ||
) | ||
action_str: str = parse_response(response) | ||
self.messages.append({"role": "assistant", "content": action_str}) | ||
|
||
command = re.search(r"<execute>(.*)</execute>", action_str, re.DOTALL) | ||
if command is not None: | ||
# a command was found | ||
command_group = command.group(1) | ||
if command_group.strip() == "exit": | ||
return AgentFinishAction() | ||
return CmdRunAction(command = command_group) | ||
# # execute the code | ||
# # TODO: does exit_code get loaded into Message? | ||
# exit_code, observation = self.env.execute(command_group) | ||
# self._history.append(Message(Role.ASSISTANT, observation)) | ||
else: | ||
# we could provide a error message for the model to continue similar to | ||
# https://github.com/xingyaoww/mint-bench/blob/main/mint/envs/general_env.py#L18-L23 | ||
# observation = INVALID_INPUT_MESSAGE | ||
# self._history.append(Message(Role.ASSISTANT, observation)) | ||
return AgentEchoAction(content=INVALID_INPUT_MESSAGE) # warning message to itself | ||
|
||
|
||
def search_memory(self, query: str) -> List[str]: | ||
raise NotImplementedError("Implement this abstract method") | ||
|
||
from .codeact_agent import CodeActAgent | ||
|
||
Agent.register("CodeActAgent", CodeActAgent) |
Oops, something went wrong.