Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions evals/elsuite/hr_ml_agent_bench/high_level_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def edit_script(
# TODO: handle long file editing
try:
content = read_file(script_name, work_dir=work_dir, **kwargs)
except:
except Exception:
write_file(script_name, "", work_dir=work_dir, **kwargs)
content = ""

Expand Down Expand Up @@ -135,12 +135,12 @@ def edit_script_lines(
try:
start_line_number = int(start_line_number)
end_line_number = int(end_line_number)
except:
except Exception:
raise EnvException("start_line_number and end_line_number must be integers")

try:
orig_content = read_file(script_name, work_dir=work_dir, **kwargs)
except:
except Exception:
write_file(script_name, "", work_dir=work_dir, **kwargs)
orig_content = ""
lines = orig_content.split("\n")
Expand Down Expand Up @@ -197,14 +197,14 @@ def inspect_script_lines(script_name, start_line_number, end_line_number, work_d
try:
start_line_number = int(start_line_number)
end_line_number = int(end_line_number)
except:
except Exception:
raise EnvException("start_line_number and end_line_number must be integers")
if end_line_number - start_line_number > 100:
raise EnvException("the number of lines to display is limited to 100 lines")
try:
# lines = open(os.path.join(work_dir,script_name)).readlines()
lines = read_file(script_name, work_dir=work_dir, **kwargs).split("\n")
except:
except Exception:
raise EnvException(f"cannot find script {script_name}")

content = "\n".join(lines[max(int(start_line_number) - 1, 0) : int(end_line_number)])
Expand Down
12 changes: 6 additions & 6 deletions evals/elsuite/hr_ml_agent_bench/low_level_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def list_files(dir_path, work_dir=".", **kwargs):
["ls", "-F", os.path.join(work_dir, dir_path)]
).decode("utf-8")
return observation
except:
except Exception:
raise EnvException(f"Cannot list file in the {dir_path} directory")


Expand All @@ -129,7 +129,7 @@ def read_file(file_name, work_dir=".", **kwargs):
try:
observation = open(os.path.join(work_dir, file_name)).read()
return observation
except:
except Exception:
raise EnvException(f"cannot read file {file_name}")


Expand All @@ -142,7 +142,7 @@ def write_file(file_name, content, work_dir=".", **kwargs):
f.write(content)
observation = f"File {file_name} written successfully."
return observation
except:
except Exception:
raise EnvException(f"cannot write file {file_name}")


Expand All @@ -155,7 +155,7 @@ def append_file(file_name, content, work_dir=".", **kwargs):
f.write(content)
observation = f"File {file_name} appended successfully."
return observation
except:
except Exception:
raise EnvException(f"cannot append file {file_name}")


Expand All @@ -167,7 +167,7 @@ def copy_file(source, destination, work_dir=".", **kwargs):
shutil.copyfile(os.path.join(work_dir, source), os.path.join(work_dir, destination))
observation = f"File {source} copied to {destination}"
return observation
except:
except Exception:
raise EnvException(
f"File {source} copy to {destination} failed. Check whether the source and destinations are valid."
)
Expand All @@ -189,7 +189,7 @@ def undo_edit_script(script_name, work_dir=".", **kwargs):
new_content = open(os.path.join(work_dir, script_name)).read()
observation = f"Content of {script_name} after undo the most recent edit:\n" + new_content
return observation
except:
except Exception:
raise EnvException(
f"Cannot undo the edit of file name {script_name}. Check the file name again."
)
Expand Down