Skip to content

Commit

Permalink
fix output code error in docker image (All-Hands-AI#2862)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufansong committed Jul 9, 2024
1 parent f0bc231 commit 9198ea3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions opendevin/runtime/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pexpect
import json
import shutil
import re
from typing import Any
from websockets.exceptions import ConnectionClosed
from opendevin.events.serialization import event_to_dict, event_from_dict
Expand Down Expand Up @@ -77,13 +78,23 @@ def _run_command(self, command: str) -> Observation:
)
except UnicodeDecodeError:
return ErrorObservation('Command output could not be decoded as utf-8')


def clean_up(self,input_text):
# Remove escape sequences
cleaned_text = re.sub(r'\x1b\[[0-9;?]*[a-zA-Z]', '', input_text)
# Remove carriage returns and other control characters
cleaned_text = re.sub(r'[\r\n\t]', '', cleaned_text)
return cleaned_text

def execute(self, command):
print(f"Received command: {command}")
self.shell.sendline(command)
self.shell.expect(r'[$#] ')
output = self.shell.before.strip().split('\r\n', 1)[1].strip()
exit_code = output[-1].strip()
# Get the exit code
self.shell.sendline('echo $?')
self.shell.expect(r'[$#] ')
exit_code = self.clean_up(self.shell.before.strip().split('\r\n')[1].strip())
return output, exit_code

def run_ipython(self, action: IPythonRunCellAction) -> Observation:
Expand Down Expand Up @@ -193,6 +204,9 @@ def test_run_commond():
command = CmdRunAction(command="ls -l")
obs = client.run_action(command)
print(obs)
command = CmdRunAction(command="pwd")
obs = client.run_action(command)
print(obs)


def test_shell(message):
Expand All @@ -207,8 +221,8 @@ def test_shell(message):

if __name__ == "__main__":
# print(test_shell("ls -l"))
client = RuntimeClient()
# test_run_commond()
# client = RuntimeClient()
test_run_commond()
# client.init_sandbox_plugins([AgentSkillsRequirement,JupyterRequirement])
# print(test_shell("whoami"))

Expand Down

0 comments on commit 9198ea3

Please sign in to comment.