From 3e5b88a7362dcd5b9c11b605518dd77487dc8650 Mon Sep 17 00:00:00 2001
From: Jon Michael Aanes <jonjmaa@gmail.com>
Date: Sun, 11 May 2025 16:37:51 +0200
Subject: [PATCH] Avoid emitting thinking tokens

---
 aider_gitea/__init__.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py
index 1491098..749e216 100644
--- a/aider_gitea/__init__.py
+++ b/aider_gitea/__init__.py
@@ -162,7 +162,7 @@ LLM_MESSAGE_FORMAT = """{issue}
 
 Go ahead with the changes you deem appropriate without waiting for explicit approval.
 
-Do not draft changes beforehand; only write code once prompted for a specific file.
+Do not draft changes beforehand; produce changes only once prompted for a specific file.
 """
 
 CODE_MODEL = None
@@ -364,6 +364,9 @@ 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()
 
 def run_ollama(cwd: Path, texts: list[str]) -> str:
     cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
@@ -377,6 +380,7 @@ def run_ollama(cwd: Path, texts: list[str]) -> str:
         text=True,
     )
     stdout, stderr = process.communicate('\n'.join(texts))
+    stdout = remove_thinking_tokens(stdout)
     print(stdout)
     return stdout