Skip to content

Commit

Permalink
last_code and last_command
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartManoj committed Sep 22, 2024
1 parent 68c5bcf commit 6fdd4f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 20 additions & 10 deletions openhands/runtime/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
ErrorObservation,
FileReadObservation,
FileWriteObservation,
IPythonRunCellObservation,
Observation,
)
from openhands.events.serialization import event_from_dict, event_to_dict
Expand Down Expand Up @@ -88,6 +87,9 @@ def __init__(
self.lock = asyncio.Lock()
self.plugins: dict[str, Plugin] = {}
self.browser = BrowserEnv(browsergym_eval_env)
self.last_command = ''
self.last_code = ''
self.is_last_code_error = False

@property
def initial_pwd(self):
Expand Down Expand Up @@ -441,11 +443,11 @@ async def run(self, action: CmdRunAction) -> CmdOutputObservation:
commands = split_bash_commands(action.command)
all_output = ''
for command in commands:
# suggest alternative for vim/nano

output = None
exit_code = 0
if command.startswith('cd'):
if command == self.last_command and command in ['ls -l', 'ls -la']:
output = "[Why are you executing the same command twice? What's wrong with you? Please focus 🙏]"
elif command.startswith('cd'):
path = command[3:].strip()
if self.pwd == path:
output = '[You are already in this directory.]'
Expand Down Expand Up @@ -475,6 +477,7 @@ async def run(self, action: CmdRunAction) -> CmdOutputObservation:
keep_prompt=action.keep_prompt,
kill_on_timeout=False if not action.blocking else True,
)
self.last_command = command
if command.startswith('pip install'):
output = await self.parse_pip_output(command, output)
if all_output:
Expand Down Expand Up @@ -571,12 +574,19 @@ async def run_ipython(self, action: IPythonRunCellAction) -> Observation:
# current working directory in Bash
if self.pwd != getattr(self, '_jupyter_pwd', None):
await self.chdir()

action.code = action.code.replace('!pip', '%pip')
obs: IPythonRunCellObservation = await _jupyter_plugin.run(action)
if 'pip install' in action.code:
obs.content = await self.parse_pip_output(action.code, obs.content)
obs.content = obs.content.rstrip()
if action.code == self.last_code and self.is_last_code_error:
obs: Observation = ErrorObservation(
'[You are trying to run the same code cell twice. '
'Please focus and run a correct code cell.]'
)
else:
action.code = action.code.replace('!pip', '%pip')
obs = await _jupyter_plugin.run(action)
if 'pip install' in action.code:
obs.content = await self.parse_pip_output(action.code, obs.content)
obs.content = obs.content.rstrip()
self.last_code = action.code
self.is_last_code_error = 'error' in obs.content
# obs.content += f'\n[Jupyter current working directory: {self.pwd}]'
# obs.content += f'\n[Jupyter Python interpreter: {_jupyter_plugin.python_interpreter_path}]'
return obs
Expand Down
2 changes: 1 addition & 1 deletion upd_persistent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import docker

full_file_name = r'openhands/runtime/client/client.py'
full_file_name = 'openhands/runtime/plugins/agent_skills/file_ops/file_ops.py'
full_file_name = r'openhands/runtime/client/client.py'
client = docker.from_env()
for c in client.containers.list():
if 'persisted' in c.name:
Expand Down

0 comments on commit 6fdd4f6

Please sign in to comment.