akhaliq HF Staff commited on
Commit
f2c450a
·
1 Parent(s): 2db0fee
Files changed (2) hide show
  1. anycoder_app/models.py +14 -0
  2. anycoder_app/parsers.py +14 -0
anycoder_app/models.py CHANGED
@@ -222,7 +222,21 @@ def history_to_chatbot_messages(history: History) -> List[Dict[str, str]]:
222
  messages.append({"role": "assistant", "content": assistant_msg})
223
  return messages
224
 
 
 
 
 
 
 
 
 
 
 
 
225
  def remove_code_block(text):
 
 
 
226
  # Try to match code blocks with language markers
227
  patterns = [
228
  r'```(?:html|HTML)\n([\s\S]+?)\n```', # Match ```html or ```HTML
 
222
  messages.append({"role": "assistant", "content": assistant_msg})
223
  return messages
224
 
225
+ def strip_tool_call_markers(text):
226
+ """Remove TOOL_CALL markers that some LLMs (like Qwen) add to their output."""
227
+ if not text:
228
+ return text
229
+ # Remove [TOOL_CALL] and [/TOOL_CALL] markers
230
+ text = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE)
231
+ # Remove standalone }} that appears with tool calls
232
+ # Only remove if it's on its own line or at the end
233
+ text = re.sub(r'^\s*\}\}\s*$', '', text, flags=re.MULTILINE)
234
+ return text.strip()
235
+
236
  def remove_code_block(text):
237
+ # First strip any tool call markers
238
+ text = strip_tool_call_markers(text)
239
+
240
  # Try to match code blocks with language markers
241
  patterns = [
242
  r'```(?:html|HTML)\n([\s\S]+?)\n```', # Match ```html or ```HTML
anycoder_app/parsers.py CHANGED
@@ -15,7 +15,21 @@ from .config import SEARCH_START, DIVIDER, REPLACE_END
15
  # Type definitions
16
  History = List[Dict[str, str]]
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  def remove_code_block(text):
 
 
 
19
  # Try to match code blocks with language markers
20
  patterns = [
21
  r'```(?:html|HTML)\n([\s\S]+?)\n```', # Match ```html or ```HTML
 
15
  # Type definitions
16
  History = List[Dict[str, str]]
17
 
18
+ def strip_tool_call_markers(text):
19
+ """Remove TOOL_CALL markers that some LLMs (like Qwen) add to their output."""
20
+ if not text:
21
+ return text
22
+ # Remove [TOOL_CALL] and [/TOOL_CALL] markers
23
+ text = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE)
24
+ # Remove standalone }} that appears with tool calls
25
+ # Only remove if it's on its own line or at the end
26
+ text = re.sub(r'^\s*\}\}\s*$', '', text, flags=re.MULTILINE)
27
+ return text.strip()
28
+
29
  def remove_code_block(text):
30
+ # First strip any tool call markers
31
+ text = strip_tool_call_markers(text)
32
+
33
  # Try to match code blocks with language markers
34
  patterns = [
35
  r'```(?:html|HTML)\n([\s\S]+?)\n```', # Match ```html or ```HTML