diff --git a/utils.py b/utils.py index cbcf4a18ea48f9573d34632911d209c146150c7c..691b3bd0dad3d57cf9571721f6abadc0b0c39a03 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,7 @@ import inspect import json import logging +import os import re from functools import wraps from pathlib import Path @@ -32,17 +33,18 @@ Create a random name that sounds german or dutch The parts should be separated by underscores and contain only lowercase. Only return the name without any text before or after.""".strip() +RUNS_DIR = current_directory / "runs" def initialize_run_directory(model: OpenAI | Llama2): response, usage = model(None, run_name_prompt, chat=True) model.usage -= usage run_name_match = re.search(r"^\w+$", response, re.MULTILINE) - if run_name_match is None: + existing_dirs = os.listdir(RUNS_DIR) + if run_name_match is None or run_name_match.group(0) in existing_dirs: run_name = uuid4().hex else: run_name = run_name_match.group(0) - run_directory = current_directory / f"runs/{run_name}" - # TODO what if name exists? + run_directory = RUNS_DIR / run_name run_directory.mkdir(parents=True, exist_ok=False) # create file handler and set level to debug file_handler = logging.FileHandler(run_directory / "output.log")