Skip to content

Commit 1154444

Browse files
committed
format: lint
Signed-off-by: Roni Friedman-Melamed <[email protected]>
1 parent 9ca436c commit 1154444

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/instructlab/eval/unitxt.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ def __init__(
4343
model_path,
4444
unitxt_recipe: str,
4545
):
46-
task = self.assign_task_name()
47-
tasks_dir = self.assign_tasks_dir(task)
46+
unitxt_task = self.assign_task_name()
47+
tasks_dir = self.assign_tasks_dir(unitxt_task)
4848
super().__init__(
49-
model_path=model_path, tasks_dir=tasks_dir, tasks=[task], few_shots=0
49+
model_path=model_path, tasks_dir=tasks_dir, tasks=[unitxt_task], few_shots=0
5050
)
5151
self.unitxt_recipe = unitxt_recipe
5252

53-
def assign_tasks_dir(self, task):
54-
return f"{TEMP_DIR_PREFIX}_{task}"
53+
def assign_tasks_dir(self, task_name):
54+
return f"{TEMP_DIR_PREFIX}_{task_name}"
5555

5656
def assign_task_name(self):
5757
return str(uuid4())
5858

59-
def prepare_unitxt_files(self) -> tuple:
60-
task = self.tasks[0]
61-
yaml_file = os.path.join(self.tasks_dir, f"{task}.yaml")
59+
def prepare_unitxt_files(self) -> None:
60+
taskname = self.tasks[0]
61+
yaml_file = os.path.join(str(self.tasks_dir), f"{taskname}.yaml")
6262
create_unitxt_pointer(self.tasks_dir)
6363
create_unitxt_yaml(
64-
yaml_file=yaml_file, unitxt_recipe=self.unitxt_recipe, task_name=task
64+
yaml_file=yaml_file, unitxt_recipe=self.unitxt_recipe, task_name=taskname
6565
)
6666

6767
def remove_unitxt_files(self):
@@ -71,7 +71,7 @@ def remove_unitxt_files(self):
7171
shutil.rmtree(self.tasks_dir)
7272
else:
7373
logger.warning(
74-
f"unitxt tasks dir did not start with '{TEMP_DIR_PREFIX}' and therefor was not deleted"
74+
"unitxt tasks dir did not start with '%s' and therefor was not deleted", TEMP_DIR_PREFIX
7575
)
7676

7777
def run(self, server_url: str | None = None) -> tuple:
@@ -101,7 +101,7 @@ def run(self, server_url: str | None = None) -> tuple:
101101
for metric in metrics:
102102
scores[metric] = instance[metric][0]
103103
instance_scores[i] = scores
104-
except Exception as e:
104+
except KeyError as e:
105105
logger.error("Error in extracting single instance scores")
106106
logger.error(e)
107107
logger.error(e.__traceback__)
@@ -112,15 +112,15 @@ def run(self, server_url: str | None = None) -> tuple:
112112

113113
def create_unitxt_yaml(yaml_file, unitxt_recipe, task_name):
114114
data = {"task": f"{task_name}", "include": "unitxt", "recipe": f"{unitxt_recipe}"}
115-
with open(yaml_file, "w") as file:
115+
with open(yaml_file, "w", encoding="utf-8") as file:
116116
yaml.dump(data, file, default_flow_style=False)
117-
logger.debug(f"task {task} unitxt recipe written to {yaml_file}")
117+
logger.debug("task %s unitxt recipe written to %s",task_name,yaml_file)
118118

119119

120120
def create_unitxt_pointer(tasks_dir):
121121
class_line = "class: !function " + task.__file__.replace("task.py", "task.Unitxt")
122122
output_file = os.path.join(tasks_dir, "unitxt")
123123
os.makedirs(os.path.dirname(output_file), exist_ok=True)
124-
with open(output_file, "w") as f:
124+
with open(output_file, "w", encoding="utf-8") as f:
125125
f.write(class_line)
126-
logger.debug(f"Unitxt task pointer written to {output_file}")
126+
logger.debug("Unitxt task pointer written to %s", output_file)

0 commit comments

Comments
 (0)