From ff3495bf50e8939cb76d5c3649df050449b39f80 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 19 Jun 2023 06:45:30 +0000 Subject: [PATCH 1/2] 'Refactored by Sourcery' --- gpt_engineer/ai.py | 4 ++-- gpt_engineer/db.py | 7 +++---- gpt_engineer/main.py | 4 ++-- scripts/benchmark.py | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gpt_engineer/ai.py b/gpt_engineer/ai.py index 593cf36011..120be7c3fe 100644 --- a/gpt_engineer/ai.py +++ b/gpt_engineer/ai.py @@ -39,7 +39,7 @@ def fassistant(self, msg): def next(self, messages: list[dict[str, str]], prompt=None): if prompt: - messages = messages + [{"role": "user", "content": prompt}] + messages += [{"role": "user", "content": prompt}] logger.debug(f"Creating a new chat completion: {messages}") response = openai.ChatCompletion.create( @@ -56,6 +56,6 @@ def next(self, messages: list[dict[str, str]], prompt=None): print(msg, end="") chat.append(msg) print() - messages = messages + [{"role": "assistant", "content": "".join(chat)}] + messages += [{"role": "assistant", "content": "".join(chat)}] logger.debug(f"Chat completion finished: {messages}") return messages diff --git a/gpt_engineer/db.py b/gpt_engineer/db.py index 3c6c12802d..13eef83c45 100644 --- a/gpt_engineer/db.py +++ b/gpt_engineer/db.py @@ -14,11 +14,10 @@ def __init__(self, path): def __getitem__(self, key): full_path = self.path / key - if full_path.is_file(): - with full_path.open("r", encoding="utf-8") as f: - return f.read() - else: + if not full_path.is_file(): raise KeyError(key) + with full_path.open("r", encoding="utf-8") as f: + return f.read() def __setitem__(self, key, val): full_path = self.path / key diff --git a/gpt_engineer/main.py b/gpt_engineer/main.py index 9df1f07072..34f0525c1d 100644 --- a/gpt_engineer/main.py +++ b/gpt_engineer/main.py @@ -33,8 +33,8 @@ def main( logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) input_path = Path(project_path).absolute() - memory_path = input_path / (run_prefix + "memory") - workspace_path = input_path / (run_prefix + "workspace") + memory_path = input_path / f"{run_prefix}memory" + workspace_path = input_path / f"{run_prefix}workspace" if delete_existing: # Delete files and subdirectories in paths diff --git a/scripts/benchmark.py b/scripts/benchmark.py index 2644af6c33..a909c95fca 100644 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -23,7 +23,7 @@ def main( benchmarks = [] for bench_folder in folders: if os.path.isdir(bench_folder): - print("Running benchmark for {}".format(bench_folder)) + print(f"Running benchmark for {bench_folder}") log_path = bench_folder / "log.txt" log_file = open(log_path, "w") @@ -44,7 +44,7 @@ def main( benchmarks.append((bench_folder, process, log_file)) print("You can stream the log file by running:") - print("tail -f {}".format(log_path)) + print(f"tail -f {log_path}") print() for bench_folder, process, file in benchmarks: From 120d0e34fd00154ba1f5f15111180654fac8c544 Mon Sep 17 00:00:00 2001 From: LopeKinz <48872005+LopeKinz@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:36:01 +0200 Subject: [PATCH 2/2] Update ai.py --- gpt_engineer/ai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpt_engineer/ai.py b/gpt_engineer/ai.py index 120be7c3fe..a24efc67ad 100644 --- a/gpt_engineer/ai.py +++ b/gpt_engineer/ai.py @@ -39,7 +39,7 @@ def fassistant(self, msg): def next(self, messages: list[dict[str, str]], prompt=None): if prompt: - messages += [{"role": "user", "content": prompt}] + messages = messages + [{"role": "user", "content": prompt}] logger.debug(f"Creating a new chat completion: {messages}") response = openai.ChatCompletion.create(