mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-01-20 03:36:30 +00:00
Update personality.py
This commit is contained in:
parent
0a255b9e17
commit
8087904aef
@ -2384,18 +2384,17 @@ The AI should respond in this format using data from actions_list:
|
|||||||
def extract_code_blocks(self, text: str) -> List[dict]:
|
def extract_code_blocks(self, text: str) -> List[dict]:
|
||||||
# Regular expression pattern to match code blocks
|
# Regular expression pattern to match code blocks
|
||||||
pattern = r'(```)?([\w-]+)?( `[^\n]*`)?\n(.*?)\n(```)?'
|
pattern = r'(```)?([\w-]+)?( `[^\n]*`)?\n(.*?)\n(```)?'
|
||||||
|
|
||||||
# Find all matches of the pattern in the text
|
# Find all matches of the pattern in the text
|
||||||
matches = re.findall(pattern, text, re.DOTALL)
|
matches = re.findall(pattern, text, re.DOTALL)
|
||||||
|
|
||||||
# Process the matches and return a list of dictionaries
|
# Process the matches and return a list of dictionaries
|
||||||
code_blocks = []
|
code_blocks = []
|
||||||
for match in matches:
|
for match in matches:
|
||||||
index = text.index(match[0])
|
index = text.index(match[0])
|
||||||
content = match[3].strip()
|
content = match[3].strip() or text[index:]
|
||||||
language = match[1] or ''
|
language = match[1] or ''
|
||||||
type_ = 'code' if not match[1] else 'markup' if match[2] else 'language-specific'
|
type_ = 'code' if not match[1] else 'markup' if match[2] else 'language-specific'
|
||||||
|
|
||||||
code_blocks.append({
|
code_blocks.append({
|
||||||
'index': index,
|
'index': index,
|
||||||
'content': content,
|
'content': content,
|
||||||
|
Loading…
Reference in New Issue
Block a user