More flexible yes/no
All checks were successful
Run Python tests (through Pytest) / Test (push) Successful in 24s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s

This commit is contained in:
Jon Michael Aanes 2025-05-11 20:37:51 +02:00
parent 3e5b88a736
commit 224e195726

View File

@ -348,7 +348,6 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
def issue_solution_round(repository_path, issue_content):
# Primary Aider command
aider_command = create_aider_command(issue_content)
print(aider_command)
aider_did_not_crash = run_cmd(
aider_command,
repository_path,
@ -365,12 +364,16 @@ def issue_solution_round(repository_path, issue_content):
return True
def remove_thinking_tokens(text: str) -> str:
text = re.sub('^<think>.*?</think>', '', text, flags=re.MULTILINE)
return text.strip()
text = re.sub(r'^\s*<think>.*?</think>', '', text, flags=re.MULTILINE | re.DOTALL)
text = text.strip()
return text
assert remove_thinking_tokens('<think>Hello</think>\nWorld\n') == 'World'
assert remove_thinking_tokens('<think>\nHello\n</think>\nWorld\n') == 'World'
assert remove_thinking_tokens('\n<think>\nHello\n</think>\nWorld\n') == 'World'
def run_ollama(cwd: Path, texts: list[str]) -> str:
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
print(cmd)
process = subprocess.Popen(
cmd,
cwd=cwd,
@ -381,20 +384,21 @@ def run_ollama(cwd: Path, texts: list[str]) -> str:
)
stdout, stderr = process.communicate('\n'.join(texts))
stdout = remove_thinking_tokens(stdout)
print(stdout)
return stdout
def parse_yes_no_answer(text: str) -> bool | None:
text = text.lower().strip()
words = text.split('\n \t.,?-')
print(words)
interword = '\n \t.,?-'
text = text.lower().strip(interword)
words = text.split(interword)
if words[-1] in {'yes', 'agree'}:
return True
if words[-1] in {'no', 'disagree'}:
return False
return None
assert parse_yes_no_answer('Yes.') == True
assert parse_yes_no_answer('no') == False
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
texts = list(initial_texts)