From 224e195726c8a75a552772a4e70ca3df9c8feb02 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 11 May 2025 20:37:51 +0200 Subject: [PATCH] More flexible yes/no --- aider_gitea/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 749e216..bea6d24 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -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('^.*?', '', text, flags=re.MULTILINE) - return text.strip() + text = re.sub(r'^\s*.*?', '', text, flags=re.MULTILINE | re.DOTALL) + text = text.strip() + return text + +assert remove_thinking_tokens('Hello\nWorld\n') == 'World' +assert remove_thinking_tokens('\nHello\n\nWorld\n') == 'World' +assert remove_thinking_tokens('\n\nHello\n\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)