Stuff
This commit is contained in:
parent
f306faab16
commit
e9a0719eb2
|
@ -149,10 +149,11 @@ AIDER_LINT = bash_cmd(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
LLM_MESSAGE_FORMAT = """/code {issue}"""
|
LLM_MESSAGE_FORMAT = """{issue}\nDo not wait for explicit approval before working on code changes."""
|
||||||
|
|
||||||
#MODEL = 'ollama/gemma3:27b'
|
#CODE_MODEL = 'ollama/gemma3:4b'
|
||||||
MODEL = 'ollama/gemma3:4b'
|
CODE_MODEL = None
|
||||||
|
EVALUATOR_MODEL = 'ollama/gemma3:27b'
|
||||||
|
|
||||||
def create_aider_command(issue: str) -> list[str]:
|
def create_aider_command(issue: str) -> list[str]:
|
||||||
l = [
|
l = [
|
||||||
|
@ -161,15 +162,13 @@ def create_aider_command(issue: str) -> list[str]:
|
||||||
'english',
|
'english',
|
||||||
'--no-stream',
|
'--no-stream',
|
||||||
'--no-analytics',
|
'--no-analytics',
|
||||||
'--no-check-update',
|
#'--no-check-update',
|
||||||
'--test-cmd',
|
'--test-cmd',
|
||||||
AIDER_TEST,
|
AIDER_TEST,
|
||||||
'--lint-cmd',
|
'--lint-cmd',
|
||||||
AIDER_LINT,
|
AIDER_LINT,
|
||||||
'--auto-test',
|
'--auto-test',
|
||||||
'--no-auto-lint',
|
'--no-auto-lint',
|
||||||
'--message',
|
|
||||||
LLM_MESSAGE_FORMAT.format(issue=issue),
|
|
||||||
'--yes',
|
'--yes',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -186,9 +185,16 @@ def create_aider_command(issue: str) -> list[str]:
|
||||||
if False:
|
if False:
|
||||||
l.append('--architect')
|
l.append('--architect')
|
||||||
|
|
||||||
if MODEL:
|
if CODE_MODEL:
|
||||||
l.append('--model')
|
l.append('--model')
|
||||||
l.append(MODEL)
|
l.append(CODE_MODEL)
|
||||||
|
|
||||||
|
if CODE_MODEL.startswith('ollama/'):
|
||||||
|
l.append('--auto-lint')
|
||||||
|
|
||||||
|
if True:
|
||||||
|
l.append('--message')
|
||||||
|
l.append(LLM_MESSAGE_FORMAT.format(issue=issue))
|
||||||
|
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
@ -310,8 +316,10 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
|
||||||
|
|
||||||
def issue_solution_round(repository_path, issue_content):
|
def issue_solution_round(repository_path, issue_content):
|
||||||
# Primary Aider command
|
# Primary Aider command
|
||||||
|
aider_command = create_aider_command(issue_content)
|
||||||
|
print(aider_command)
|
||||||
aider_did_not_crash = run_cmd(
|
aider_did_not_crash = run_cmd(
|
||||||
create_aider_command(issue_content),
|
aider_command,
|
||||||
repository_path,
|
repository_path,
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
|
@ -326,7 +334,7 @@ def issue_solution_round(repository_path, issue_content):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_ollama(cwd: Path, texts: list[str]) -> str:
|
def run_ollama(cwd: Path, texts: list[str]) -> str:
|
||||||
cmd = ['ollama', 'run', MODEL.removeprefix('ollama/')]
|
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
|
||||||
print(cmd)
|
print(cmd)
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
cmd,
|
cmd,
|
||||||
|
@ -337,21 +345,30 @@ def run_ollama(cwd: Path, texts: list[str]) -> str:
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
stdout, stderr = process.communicate('\n'.join(texts))
|
stdout, stderr = process.communicate('\n'.join(texts))
|
||||||
|
print(stdout)
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
def parse_yes_no_answer(text: str) -> bool | None:
|
||||||
|
text = text.lower().strip()
|
||||||
|
words = text.split('\n \t.,?-')
|
||||||
|
print(words)
|
||||||
|
if words[-1] in {'yes', 'agree'}:
|
||||||
|
return True
|
||||||
|
if words[-1] in {'no', 'disagree'}:
|
||||||
|
return False
|
||||||
|
return None
|
||||||
|
|
||||||
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
||||||
texts = list(initial_texts)
|
texts = list(initial_texts)
|
||||||
texts.append('Think through your answer, and end it with "yes" or "no".')
|
texts.append('Think through your answer.')
|
||||||
while True:
|
while True:
|
||||||
result = run_ollama(cwd, texts).lower().removesuffix('.').strip()
|
response = run_ollama(cwd, texts)
|
||||||
print(result)
|
yes_or_no = parse_yes_no_answer(response)
|
||||||
if result.endswith('yes'):
|
if yes_or_no is not None:
|
||||||
return True
|
return yes_or_no
|
||||||
elif result.endswith('no'):
|
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
texts.append(result)
|
texts.append(response)
|
||||||
texts.append('Please answer either yes or no.')
|
texts.append('Please answer either "yes" or "no".')
|
||||||
|
|
||||||
def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
||||||
summary = run_ollama(
|
summary = run_ollama(
|
||||||
|
@ -360,17 +377,25 @@ def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
||||||
get_diff(repository_path, 'HEAD', 'main')
|
get_diff(repository_path, 'HEAD', 'main')
|
||||||
])
|
])
|
||||||
|
|
||||||
print(summary)
|
|
||||||
|
|
||||||
return run_ollama_and_get_yes_or_no(
|
return run_ollama_and_get_yes_or_no(
|
||||||
repository_path,
|
repository_path,
|
||||||
['Does this changeset the task?',
|
['Does this changeset accomplish the entire task?',
|
||||||
'# Change set',
|
'# Change set',
|
||||||
summary,
|
summary,
|
||||||
'# Issue',
|
'# Issue',
|
||||||
issue_content,
|
issue_content,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def get_head_commit_hash(repository_path: Path) -> str:
|
||||||
|
return subprocess.run(
|
||||||
|
['git', 'rev-parse', 'HEAD'],
|
||||||
|
check=True,
|
||||||
|
cwd=repository_path,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
).stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
def solve_issue_in_repository(
|
def solve_issue_in_repository(
|
||||||
repository_config: RepositoryConfig,
|
repository_config: RepositoryConfig,
|
||||||
repository_path: Path,
|
repository_path: Path,
|
||||||
|
@ -393,36 +418,31 @@ def solve_issue_in_repository(
|
||||||
run_cmd(['git', 'add', '.'], repository_path)
|
run_cmd(['git', 'add', '.'], repository_path)
|
||||||
run_cmd(['git', 'commit', '-m', 'Initial ruff pass'], repository_path, check=False)
|
run_cmd(['git', 'commit', '-m', 'Initial ruff pass'], repository_path, check=False)
|
||||||
|
|
||||||
# Save the commit hash after ruff but before aider
|
|
||||||
pre_aider_commit = subprocess.run(
|
|
||||||
['git', 'rev-parse', 'HEAD'],
|
|
||||||
check=True,
|
|
||||||
cwd=repository_path,
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
).stdout.strip()
|
|
||||||
|
|
||||||
# Run aider
|
# Run aider
|
||||||
issue_content = f'# {issue_title}\n{issue_description}'
|
issue_content = f'# {issue_title}\n{issue_description}'
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
# Save the commit hash after ruff but before aider
|
||||||
|
pre_aider_commit = get_head_commit_hash(repository_path)
|
||||||
|
|
||||||
|
# Run aider
|
||||||
aider_did_not_crash = issue_solution_round(repository_path, issue_content)
|
aider_did_not_crash = issue_solution_round(repository_path, issue_content)
|
||||||
if not aider_did_not_crash:
|
if not aider_did_not_crash:
|
||||||
logger.error('Aider invocation failed for issue #%s', issue_number)
|
logger.error('Aider invocation failed for issue #%s', issue_number)
|
||||||
return IssueResolution(False)
|
return IssueResolution(False)
|
||||||
|
|
||||||
|
# Check if aider made any changes beyond the initial ruff pass
|
||||||
|
if not has_commits_on_branch(repository_path, pre_aider_commit, 'HEAD'):
|
||||||
|
logger.error(
|
||||||
|
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
|
||||||
|
issue_number,
|
||||||
|
)
|
||||||
|
return IssueResolution(False)
|
||||||
|
|
||||||
# Verify whether this is a satisfactory solution
|
# Verify whether this is a satisfactory solution
|
||||||
if verify_solution(repository_path, issue_content):
|
if verify_solution(repository_path, issue_content):
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check if aider made any changes beyond the initial ruff pass
|
|
||||||
if not has_commits_on_branch(repository_path, repository_config.base_branch, branch_name):
|
|
||||||
logger.info(
|
|
||||||
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
|
|
||||||
issue_number,
|
|
||||||
)
|
|
||||||
return IssueResolution(False)
|
|
||||||
|
|
||||||
# Push changes
|
# Push changes
|
||||||
return push_changes(
|
return push_changes(
|
||||||
repository_config,
|
repository_config,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user