More flexible yes/no
This commit is contained in:
parent
3e5b88a736
commit
224e195726
|
@ -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):
|
def issue_solution_round(repository_path, issue_content):
|
||||||
# Primary Aider command
|
# Primary Aider command
|
||||||
aider_command = create_aider_command(issue_content)
|
aider_command = create_aider_command(issue_content)
|
||||||
print(aider_command)
|
|
||||||
aider_did_not_crash = run_cmd(
|
aider_did_not_crash = run_cmd(
|
||||||
aider_command,
|
aider_command,
|
||||||
repository_path,
|
repository_path,
|
||||||
|
@ -365,12 +364,16 @@ def issue_solution_round(repository_path, issue_content):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def remove_thinking_tokens(text: str) -> str:
|
def remove_thinking_tokens(text: str) -> str:
|
||||||
text = re.sub('^<think>.*?</think>', '', text, flags=re.MULTILINE)
|
text = re.sub(r'^\s*<think>.*?</think>', '', text, flags=re.MULTILINE | re.DOTALL)
|
||||||
return text.strip()
|
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:
|
def run_ollama(cwd: Path, texts: list[str]) -> str:
|
||||||
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
|
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
|
||||||
print(cmd)
|
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
cmd,
|
cmd,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
|
@ -381,20 +384,21 @@ def run_ollama(cwd: Path, texts: list[str]) -> str:
|
||||||
)
|
)
|
||||||
stdout, stderr = process.communicate('\n'.join(texts))
|
stdout, stderr = process.communicate('\n'.join(texts))
|
||||||
stdout = remove_thinking_tokens(stdout)
|
stdout = remove_thinking_tokens(stdout)
|
||||||
print(stdout)
|
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
|
||||||
def parse_yes_no_answer(text: str) -> bool | None:
|
def parse_yes_no_answer(text: str) -> bool | None:
|
||||||
text = text.lower().strip()
|
interword = '\n \t.,?-'
|
||||||
words = text.split('\n \t.,?-')
|
text = text.lower().strip(interword)
|
||||||
print(words)
|
words = text.split(interword)
|
||||||
if words[-1] in {'yes', 'agree'}:
|
if words[-1] in {'yes', 'agree'}:
|
||||||
return True
|
return True
|
||||||
if words[-1] in {'no', 'disagree'}:
|
if words[-1] in {'no', 'disagree'}:
|
||||||
return False
|
return False
|
||||||
return None
|
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:
|
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
||||||
texts = list(initial_texts)
|
texts = list(initial_texts)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user