Spaces:
Sleeping
Sleeping
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
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 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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."""
|