mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Add ruff for shared mutable defaults (B) (#1938)
* Add ruff for shared mutable defaults (B) * Apply B006, B008 on current files, except fast API * Update agenthub/SWE_agent/prompts.py Co-authored-by: Graham Neubig <neubig@gmail.com> * fix unintended behavior change * this is correct, tell Ruff to leave it alone --------- Co-authored-by: Graham Neubig <neubig@gmail.com> Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk>
This commit is contained in:
parent
9a2591d0f6
commit
b9a5be2569
@ -171,8 +171,9 @@ Begin with your thought about the next step and then come up with an action to p
|
||||
""".strip()
|
||||
|
||||
|
||||
def unpack_dict(data: dict, restrict: list[str] = []):
|
||||
def unpack_dict(data: dict, restrict: list[str] | None = None):
|
||||
lines = []
|
||||
restrict = [] if restrict is None else restrict
|
||||
for key, value in data.items():
|
||||
if key in restrict:
|
||||
continue
|
||||
|
||||
@ -13,8 +13,7 @@ for dir in os.listdir(os.path.dirname(__file__)):
|
||||
promptFile = base + '/prompt.md'
|
||||
agentFile = base + '/agent.yaml'
|
||||
if not os.path.isfile(promptFile) or not os.path.isfile(agentFile):
|
||||
raise Exception(
|
||||
f'Missing prompt or agent file in {base}. Please create them.')
|
||||
raise Exception(f'Missing prompt or agent file in {base}. Please create them.')
|
||||
with open(promptFile, 'r') as f:
|
||||
prompt = f.read()
|
||||
with open(agentFile, 'r') as f:
|
||||
|
||||
@ -108,7 +108,7 @@ def get_summarize_monologue_prompt(thoughts: list[dict]):
|
||||
def get_request_action_prompt(
|
||||
task: str,
|
||||
thoughts: list[dict],
|
||||
background_commands_obs: list[CmdOutputObservation] = [],
|
||||
background_commands_obs: list[CmdOutputObservation] | None = None,
|
||||
):
|
||||
"""
|
||||
Gets the action prompt formatted with appropriate values.
|
||||
@ -122,6 +122,9 @@ def get_request_action_prompt(
|
||||
- str: Formatted prompt string with hint, task, monologue, and background included
|
||||
"""
|
||||
|
||||
if background_commands_obs is None:
|
||||
background_commands_obs = []
|
||||
|
||||
hint = ''
|
||||
if len(thoughts) > 0:
|
||||
latest_thought = thoughts[-1]
|
||||
|
||||
@ -9,10 +9,17 @@ select = [
|
||||
"F",
|
||||
"I",
|
||||
"Q",
|
||||
"B",
|
||||
]
|
||||
|
||||
ignore = [
|
||||
"E501",
|
||||
"B003",
|
||||
"B007",
|
||||
"B009",
|
||||
"B010",
|
||||
"B904",
|
||||
"B018",
|
||||
]
|
||||
|
||||
[lint.flake8-quotes]
|
||||
|
||||
@ -29,7 +29,7 @@ class Task:
|
||||
parent: 'Task',
|
||||
goal: str,
|
||||
state: str = OPEN_STATE,
|
||||
subtasks: list = [],
|
||||
subtasks: list = [], # noqa: B006
|
||||
):
|
||||
"""Initializes a new instance of the Task class.
|
||||
|
||||
@ -45,6 +45,7 @@ class Task:
|
||||
self.id = str(len(parent.subtasks))
|
||||
self.parent = parent
|
||||
self.goal = goal
|
||||
logger.debug('Creating task {self.id} with parent={parent.id}, goal={goal}')
|
||||
self.subtasks = []
|
||||
for subtask in subtasks or []:
|
||||
if isinstance(subtask, Task):
|
||||
@ -53,6 +54,7 @@ class Task:
|
||||
goal = subtask.get('goal')
|
||||
state = subtask.get('state')
|
||||
subtasks = subtask.get('subtasks')
|
||||
logger.debug('Reading: {goal}, {state}, {subtasks}')
|
||||
self.subtasks.append(Task(self, goal, state, subtasks))
|
||||
|
||||
self.state = OPEN_STATE
|
||||
@ -190,7 +192,7 @@ class RootTask(Task):
|
||||
task = task.subtasks[part]
|
||||
return task
|
||||
|
||||
def add_subtask(self, parent_id: str, goal: str, subtasks: list = []):
|
||||
def add_subtask(self, parent_id: str, goal: str, subtasks: list | None = None):
|
||||
"""Adds a subtask to a parent task.
|
||||
|
||||
Args:
|
||||
@ -198,6 +200,7 @@ class RootTask(Task):
|
||||
goal: The goal of the subtask.
|
||||
subtasks: A list of subtasks associated with the new subtask.
|
||||
"""
|
||||
subtasks = subtasks or []
|
||||
parent = self.get_task_by_id(parent_id)
|
||||
child = Task(parent=parent, goal=goal, subtasks=subtasks)
|
||||
parent.subtasks.append(child)
|
||||
@ -210,6 +213,7 @@ class RootTask(Task):
|
||||
state: The new state of the subtask.
|
||||
"""
|
||||
task = self.get_task_by_id(id)
|
||||
logger.debug('Setting task {task.id} from state {task.state} to {state}')
|
||||
task.set_state(state)
|
||||
unfinished_tasks = [
|
||||
t
|
||||
|
||||
@ -114,10 +114,11 @@ def get_console_handler():
|
||||
return console_handler
|
||||
|
||||
|
||||
def get_file_handler(log_dir=os.path.join(os.getcwd(), 'logs')):
|
||||
def get_file_handler(log_dir=None):
|
||||
"""
|
||||
Returns a file handler for logging.
|
||||
"""
|
||||
log_dir = os.path.join(os.getcwd(), 'logs') if log_dir is None else log_dir
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d')
|
||||
file_name = f'opendevin_{timestamp}.log'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user