github-actions[bot] commited on
Commit
3226ae7
·
1 Parent(s): c828a47

Auto-sync from demo at Wed Nov 12 06:19:26 UTC 2025

Browse files
Files changed (1) hide show
  1. graphgen/bases/base_llm_wrapper.py +10 -4
graphgen/bases/base_llm_wrapper.py CHANGED
@@ -61,11 +61,17 @@ class BaseLLMWrapper(abc.ABC):
61
  def filter_think_tags(text: str, think_tag: str = "think") -> str:
62
  """
63
  Remove <think> tags from the text.
64
- If the text contains <think> and </think>, it removes everything between them and the tags themselves.
 
65
  """
66
- think_pattern = re.compile(rf"<{think_tag}>.*?</{think_tag}>", re.DOTALL)
67
- filtered_text = think_pattern.sub("", text).strip()
68
- return filtered_text if filtered_text else text.strip()
 
 
 
 
 
69
 
70
  def shutdown(self) -> None:
71
  """Shutdown the LLM engine if applicable."""
 
61
  def filter_think_tags(text: str, think_tag: str = "think") -> str:
62
  """
63
  Remove <think> tags from the text.
64
+ - If the text contains <think> and </think>, it removes everything between them and the tags themselves.
65
+ - If the text contains only </think>, it removes content before the tag.
66
  """
67
+ paired_pattern = re.compile(rf"<{think_tag}>.*?</{think_tag}>", re.DOTALL)
68
+ filtered = paired_pattern.sub("", text)
69
+
70
+ orphan_pattern = re.compile(rf"^.*?</{think_tag}>", re.DOTALL)
71
+ filtered = orphan_pattern.sub("", filtered)
72
+
73
+ filtered = filtered.strip()
74
+ return filtered if filtered else text.strip()
75
 
76
  def shutdown(self) -> None:
77
  """Shutdown the LLM engine if applicable."""