优化isay markdown
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -152,3 +152,4 @@ request_llm/moss
|
|||||||
multi-language
|
multi-language
|
||||||
request_llm/moss
|
request_llm/moss
|
||||||
media
|
media
|
||||||
|
__test.py
|
||||||
|
|||||||
20
toolbox.py
20
toolbox.py
@ -247,16 +247,13 @@ def text_divide_paragraph(text):
|
|||||||
"""
|
"""
|
||||||
将文本按照段落分隔符分割开,生成带有段落标签的HTML代码。
|
将文本按照段落分隔符分割开,生成带有段落标签的HTML代码。
|
||||||
"""
|
"""
|
||||||
if '```' in text:
|
regex = r'```[\s\S]*?```(?:(?!```).)*$'
|
||||||
# careful input
|
codeblock_matches = re.findall(regex, text)
|
||||||
return text
|
for match in codeblock_matches:
|
||||||
else:
|
text = text.replace(match, match.replace('\n\n\n\n', '\n\n'))
|
||||||
# wtf input
|
text = re.sub(r'\n{3,}', '\n\n', text)
|
||||||
# lines = text.split("\n")
|
return text.strip()
|
||||||
# for i, line in enumerate(lines):
|
|
||||||
# lines[i] = lines[i].replace(" ", " ")
|
|
||||||
# text = "</br>".join(lines)
|
|
||||||
return text
|
|
||||||
|
|
||||||
@lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度
|
@lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度
|
||||||
def markdown_convertion(txt):
|
def markdown_convertion(txt):
|
||||||
@ -368,8 +365,7 @@ def format_io(self, y):
|
|||||||
if y is None or y == []:
|
if y is None or y == []:
|
||||||
return []
|
return []
|
||||||
i_ask, gpt_reply = y[-1]
|
i_ask, gpt_reply = y[-1]
|
||||||
# i_ask = text_divide_paragraph(i_ask) # 输入部分太自由,预处理一波
|
i_ask = text_divide_paragraph(i_ask) # 输入部分太自由,预处理一波
|
||||||
i_ask = re.sub(r'\n+', '\n\n', i_ask)
|
|
||||||
gpt_reply = close_up_code_segment_during_stream(gpt_reply) # 当代码输出半截的时候,试着补上后个```
|
gpt_reply = close_up_code_segment_during_stream(gpt_reply) # 当代码输出半截的时候,试着补上后个```
|
||||||
y[-1] = (
|
y[-1] = (
|
||||||
# None if i_ask is None else markdown.markdown(i_ask, extensions=['fenced_code', 'tables']),
|
# None if i_ask is None else markdown.markdown(i_ask, extensions=['fenced_code', 'tables']),
|
||||||
|
|||||||
Reference in New Issue
Block a user