mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-03-01 04:06:07 +00:00
Update personality.py
This commit is contained in:
parent
feaf1710d4
commit
9efab84767
@ -1330,7 +1330,9 @@ Don't forget encapsulate the code inside a html code tag. This is mandatory.
|
|||||||
|
|
||||||
def extract_thinking_blocks(self, text: str) -> List[str]:
|
def extract_thinking_blocks(self, text: str) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Extracts content between <thinking> or <think> tags from a given text.
|
Extracts content between <thinking> or tags from a given text.
|
||||||
|
If a closing tag is present without an opening tag, the content from the start of the text up to the closing tag is extracted.
|
||||||
|
If both opening and closing tags are present, extracts all content between them.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
text (str): The text containing thinking blocks
|
text (str): The text containing thinking blocks
|
||||||
@ -1338,15 +1340,23 @@ Don't forget encapsulate the code inside a html code tag. This is mandatory.
|
|||||||
Returns:
|
Returns:
|
||||||
List[str]: List of extracted thinking contents
|
List[str]: List of extracted thinking contents
|
||||||
"""
|
"""
|
||||||
import re
|
# Pattern to match both thinking and think blocks with matching tags
|
||||||
|
|
||||||
# Pattern to match both <thinking> and <think> blocks with matching tags
|
|
||||||
pattern = r'<(thinking|think)>(.*?)</\1>'
|
pattern = r'<(thinking|think)>(.*?)</\1>'
|
||||||
matches = re.finditer(pattern, text, re.DOTALL)
|
matches = re.finditer(pattern, text, re.DOTALL)
|
||||||
|
|
||||||
# Extract content from the second group (index 2) and clean
|
# Extract content from the second group and clean
|
||||||
thinking_blocks = [match.group(2).strip() for match in matches]
|
thinking_blocks = [match.group(2).strip() for match in matches]
|
||||||
|
|
||||||
|
# Check for closing tags without opening tags
|
||||||
|
if not thinking_blocks:
|
||||||
|
# Look for any closing tag without a matching opening tag
|
||||||
|
closing_pattern = r'</(thinking|think)>'
|
||||||
|
closing_match = re.search(closing_pattern, text)
|
||||||
|
if closing_match:
|
||||||
|
# Extract content from start up to the closing tag
|
||||||
|
content = text.split('</')[0].strip()
|
||||||
|
thinking_blocks.append(content)
|
||||||
|
|
||||||
return thinking_blocks
|
return thinking_blocks
|
||||||
|
|
||||||
def remove_thinking_blocks(self, text: str) -> str:
|
def remove_thinking_blocks(self, text: str) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user