MCPcopy
hub / github.com/zai-org/ChatGLM2-6B / parse_text

Function parse_text

web_demo.py:30–60  ·  view source on GitHub ↗

copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/

(text)

Source from the content-addressed store, hash-verified

28
29
30def parse_text(text):
31 """copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/"""
32 lines = text.split("\n")
33 lines = [line for line in lines if line != ""]
34 count = 0
35 for i, line in enumerate(lines):
36 if "```" in line:
37 count += 1
38 items = line.split('`')
39 if count % 2 == 1:
40 lines[i] = f'<pre><code class="language-{items[-1]}">'
41 else:
42 lines[i] = f'<br></code></pre>'
43 else:
44 if i > 0:
45 if count % 2 == 1:
46 line = line.replace("`", "\`")
47 line = line.replace("<", "&lt;")
48 line = line.replace(">", "&gt;")
49 line = line.replace(" ", "&nbsp;")
50 line = line.replace("*", "&ast;")
51 line = line.replace("_", "&lowbar;")
52 line = line.replace("-", "&#45;")
53 line = line.replace(".", "&#46;")
54 line = line.replace("!", "&#33;")
55 line = line.replace("(", "&#40;")
56 line = line.replace(")", "&#41;")
57 line = line.replace("$", "&#36;")
58 lines[i] = "<br>"+line
59 text = "".join(lines)
60 return text
61
62
63def predict(input, chatbot, max_length, top_p, temperature, history, past_key_values):

Callers 1

predictFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected