Merge branch 'main' into triple-backticks

This commit is contained in:
Paul Gauthier 2023-06-25 19:34:20 -07:00
commit 2b8717bdb6
5 changed files with 41 additions and 16 deletions

View file

@ -1 +1 @@
__version__ = "0.7.0" __version__ = "0.7.1"

View file

@ -44,7 +44,7 @@ class WholeFileCoder(Coder):
full_path = (Path(self.root) / fname).absolute() full_path = (Path(self.root) / fname).absolute()
if mode == "diff" and full_path.exists(): if mode == "diff" and full_path.exists():
orig_lines = full_path.read_text().splitlines() orig_lines = full_path.read_text().splitlines(keepends=True)
show_diff = diffs.diff_partial_update( show_diff = diffs.diff_partial_update(
orig_lines, orig_lines,
@ -99,7 +99,7 @@ class WholeFileCoder(Coder):
full_path = (Path(self.root) / fname).absolute() full_path = (Path(self.root) / fname).absolute()
if mode == "diff" and full_path.exists(): if mode == "diff" and full_path.exists():
orig_lines = full_path.read_text().splitlines() orig_lines = full_path.read_text().splitlines(keepends=True)
show_diff = diffs.diff_partial_update( show_diff = diffs.diff_partial_update(
orig_lines, orig_lines,

View file

@ -14,7 +14,8 @@ Once you understand the request you MUST:
3. If changes are needed, output a copy of each file that needs changes. 3. If changes are needed, output a copy of each file that needs changes.
""" """
system_reminder = """To return code you MUST use this *file listing* format: system_reminder = """To suggest changes to a file you MUST return the entire content of the updated file.
You MUST use this *file listing* format:
path/to/filename.js path/to/filename.js
{fence}javascript {fence}javascript

View file

@ -33,6 +33,13 @@ def create_progress_bar(percentage):
return bar return bar
def assert_newlines(lines):
if not lines:
return
for line in lines:
assert line and line[-1] == "\n", line
def diff_partial_update(lines_orig, lines_updated, final=False, fname=None): def diff_partial_update(lines_orig, lines_updated, final=False, fname=None):
""" """
Given only the first part of an updated file, show the diff while Given only the first part of an updated file, show the diff while
@ -43,6 +50,9 @@ def diff_partial_update(lines_orig, lines_updated, final=False, fname=None):
# dump(lines_orig) # dump(lines_orig)
# dump(lines_updated) # dump(lines_updated)
assert_newlines(lines_orig)
assert_newlines(lines_orig)
num_orig_lines = len(lines_orig) num_orig_lines = len(lines_orig)
if final: if final:

View file

@ -10,6 +10,7 @@ from collections import defaultdict
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from pathlib import Path from pathlib import Path
import git
import lox import lox
from rich.console import Console from rich.console import Console
@ -26,6 +27,11 @@ assert ORIGINAL_DNAME.exists() and ORIGINAL_DNAME.is_dir()
def main(): def main():
repo = git.Repo(search_parent_directories=True)
commit_hash = repo.head.object.hexsha[:7]
if repo.is_dirty():
commit_hash += "-dirty"
parser = argparse.ArgumentParser(description="Aider Benchmark") parser = argparse.ArgumentParser(description="Aider Benchmark")
parser.add_argument("dirname", type=str, help="Directory name") parser.add_argument("dirname", type=str, help="Directory name")
parser.add_argument("--model", "-m", type=str, help="Model name", default="gpt-3.5-turbo") parser.add_argument("--model", "-m", type=str, help="Model name", default="gpt-3.5-turbo")
@ -117,6 +123,7 @@ def main():
args.no_test, args.no_test,
args.verbose, args.verbose,
args.stats_only, args.stats_only,
commit_hash,
) )
all_results.append(results) all_results.append(results)
@ -133,6 +140,7 @@ def main():
args.no_test, args.no_test,
args.verbose, args.verbose,
args.stats_only, args.stats_only,
commit_hash,
) )
all_results = run_test_threaded.gather(tqdm=True) all_results = run_test_threaded.gather(tqdm=True)
@ -172,11 +180,10 @@ def summarize_results(dirname, all_results, total_tests=None):
total_cost += results["cost"] total_cost += results["cost"]
duration += results["duration"] duration += results["duration"]
for key in "model edit_format".split(): for key in "model edit_format commit_hash".split():
if key in results: val = results.get(key)
variants[key].add(results[key]) variants[key].add(val)
dump(completed_tests)
if not completed_tests: if not completed_tests:
return return
@ -189,7 +196,7 @@ def summarize_results(dirname, all_results, total_tests=None):
style = "red" style = "red"
else: else:
style = None style = None
val = ", ".join(val) val = ", ".join(map(str, val))
console.print(f"{key}: {val}", style=style) console.print(f"{key}: {val}", style=style)
console.print() console.print()
@ -213,7 +220,7 @@ def summarize_results(dirname, all_results, total_tests=None):
console.rule() console.rule()
def run_test(testdir, model_name, edit_format, retries, no_test, verbose, stats_only): def run_test(testdir, model_name, edit_format, retries, no_test, verbose, stats_only, commit_hash):
if not stats_only: if not stats_only:
dump(testdir) dump(testdir)
@ -248,12 +255,18 @@ def run_test(testdir, model_name, edit_format, retries, no_test, verbose, stats_
shutil.copy(original_fname, fname) shutil.copy(original_fname, fname)
file_list = " ".join(fname.name for fname in fnames) file_list = " ".join(fname.name for fname in fnames)
instructions = (testdir / ".docs/instructions.md").read_text() intro = testdir / ".docs/introduction.md"
instructions += ( if intro.exists():
"\n\n=====\n\nModify these files according to the above instructions. Only use standard" instructions = intro.read_text() + "\n\n"
" python libraries, don't suggest installing any packages.\n" else:
) instructions = ""
instructions += file_list instructions += (testdir / ".docs/instructions.md").read_text()
instructions += f"""
=====
Use the above instructions to modify the supplied files: {file_list}
Keep and implement the existing function or class stubs, they will be called from unit tests.
Only use standard python libraries, don't suggest installing any packages.
"""
io = InputOutput( io = InputOutput(
pretty=True, pretty=True,
@ -319,6 +332,7 @@ def run_test(testdir, model_name, edit_format, retries, no_test, verbose, stats_
tests_outcomes=test_outcomes, tests_outcomes=test_outcomes,
cost=coder.total_cost, cost=coder.total_cost,
duration=dur, duration=dur,
commit_hash=commit_hash,
) )
dump(results) dump(results)