Skip to content

Commit 164730a

Browse files
authored
Add claude 3 / anthropic with cost calculation + convenience fixes. gpt-engineer is coauthor (#1080)
* add anthropic support * Collapse * more tokens * Cleanup and simplify CLI * Improve CLI tool entry point functionality * Update improve function name to improve_fn and api key * Update file_selector.py with path selection improvements * Improve diff parsing * Fix color diff * Do proper logging * Undo indent * Fix yes no * Fix logs
1 parent c7c2fc7 commit 164730a

21 files changed

+337
-186
lines changed

.env.template

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### OpenAI Setup ###
22

33
# OPENAI_API_KEY=Your personal OpenAI API key from https://platform.openai.com/account/api-keys
4-
OPENAI_API_KEY=$key
4+
OPENAI_API_KEY=...
5+
ANTHROPIC_API_KEY=...

gpt_engineer/applications/cli/cli_agent.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
execute_entrypoint,
1919
gen_code,
2020
gen_entrypoint,
21-
improve,
21+
improve_fn,
2222
)
2323
from gpt_engineer.core.files_dict import FilesDict
2424
from gpt_engineer.core.preprompts_holder import PrepromptsHolder
@@ -87,7 +87,7 @@ def __init__(
8787
execution_env: BaseExecutionEnv,
8888
ai: AI = None,
8989
code_gen_fn: CodeGenType = gen_code,
90-
improve_fn: ImproveType = improve,
90+
improve_fn: ImproveType = improve_fn,
9191
process_code_fn: CodeProcessor = execute_entrypoint,
9292
preprompts_holder: PrepromptsHolder = None,
9393
):
@@ -106,7 +106,7 @@ def with_default_config(
106106
execution_env: DiskExecutionEnv,
107107
ai: AI = None,
108108
code_gen_fn: CodeGenType = gen_code,
109-
improve_fn: ImproveType = improve,
109+
improve_fn: ImproveType = improve_fn,
110110
process_code_fn: CodeProcessor = execute_entrypoint,
111111
preprompts_holder: PrepromptsHolder = None,
112112
):

gpt_engineer/applications/cli/file_selector.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import subprocess
2323

2424
from pathlib import Path
25-
from typing import Any, Dict, List, Union
25+
from typing import Any, Dict, Generator, List, Union
2626

2727
import toml
2828

@@ -288,14 +288,22 @@ def get_files_from_toml(
288288
print(f"\nYou have selected the following files:\n{input_path}")
289289

290290
project_path = Path(input_path).resolve()
291-
all_paths = set(
291+
selected_paths = set(
292292
project_path.joinpath(file).resolve(strict=False) for file in selected_files
293293
)
294294

295+
for displayable_path in DisplayablePath.make_tree(project_path):
296+
if displayable_path.path in selected_paths:
297+
p = displayable_path
298+
while p.parent and p.parent.path not in selected_paths:
299+
selected_paths.add(p.parent.path)
300+
p = p.parent
301+
295302
try:
296303
for displayable_path in DisplayablePath.make_tree(project_path):
297-
if displayable_path.path in all_paths:
304+
if displayable_path.path in selected_paths:
298305
print(displayable_path.displayable())
306+
299307
except FileNotFoundError:
300308
print("Specified path does not exist: ", project_path)
301309
except Exception as e:
@@ -378,24 +386,6 @@ def get_current_files(self, project_path: Union[str, Path]) -> List[str]:
378386

379387
return all_files
380388

381-
def is_in_ignoring_extensions(self, path: Path) -> bool:
382-
"""
383-
Checks if a file path should be ignored based on predefined criteria.
384-
385-
Parameters
386-
----------
387-
path : Path
388-
The path to the file to be checked.
389-
390-
Returns
391-
-------
392-
bool
393-
True if the file should not be ignored, False otherwise.
394-
"""
395-
is_hidden = not path.name.startswith(".")
396-
is_pycache = "__pycache__" not in path.name
397-
return is_hidden and is_pycache
398-
399389

400390
class DisplayablePath(object):
401391
"""
@@ -444,7 +434,7 @@ def display_name(self) -> str:
444434
@classmethod
445435
def make_tree(
446436
cls, root: Union[str, Path], parent=None, is_last=False, criteria=None
447-
):
437+
) -> Generator["DisplayablePath", None, None]:
448438
"""
449439
Creates a tree of DisplayablePath objects from a root directory.
450440

gpt_engineer/applications/cli/learning.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ class Learning:
118118
+ "(ncertain): "
119119
)
120120

121-
VALID_INPUTS = ("y", "n", "u")
122-
123121

124122
def human_review_input() -> Optional[Review]:
125123
"""
@@ -142,17 +140,17 @@ def human_review_input() -> Optional[Review]:
142140
print()
143141

144142
ran = input("Did the generated code run at all? " + TERM_CHOICES)
145-
ran = ask_for_valid_input(ran, VALID_INPUTS)
143+
ran = ask_for_valid_input(ran)
146144

147145
if ran == "y":
148146
perfect = input(
149147
"Did the generated code do everything you wanted? " + TERM_CHOICES
150148
)
151-
perfect = ask_for_valid_input(perfect, VALID_INPUTS)
149+
perfect = ask_for_valid_input(perfect)
152150

153151
if perfect != "y":
154152
useful = input("Did the generated code do anything useful? " + TERM_CHOICES)
155-
useful = ask_for_valid_input(useful, VALID_INPUTS)
153+
useful = ask_for_valid_input(useful)
156154
else:
157155
useful = ""
158156
else:
@@ -176,8 +174,8 @@ def human_review_input() -> Optional[Review]:
176174
)
177175

178176

179-
def ask_for_valid_input(ran, valid_inputs):
180-
while ran not in valid_inputs:
177+
def ask_for_valid_input(ran):
178+
while ran not in ("y", "n", "u"):
181179
ran = input("Invalid input. Please enter y, n, or u: ")
182180
return ran
183181

0 commit comments

Comments
 (0)