MCPcopy
hub / github.com/zai-org/GLM-4 / postprocess_text

Function postprocess_text

demo/composite_demo/src/conversation.py:145–163  ·  view source on GitHub ↗
(text: str, replace_quote: bool)

Source from the content-addressed store, hash-verified

143
144
145def postprocess_text(text: str, replace_quote: bool) -> str:
146 text = text.replace(r"\(", "$")
147 text = text.replace(r"\)", "$")
148 text = text.replace(r"\[", "$$")
149 text = text.replace(r"\]", "$$")
150 text = text.replace("<|assistant|>", "")
151 text = text.replace("<|observation|>", "")
152 text = text.replace("<|system|>", "")
153 text = text.replace("<|user|>", "")
154 text = text.replace("<|endoftext|>", "")
155
156 # Replace quotes
157 if replace_quote:
158 for match in QUOTE_REGEX.finditer(text):
159 quote_id = match.group(1)
160 quote = quotes.get(quote_id, Quote("未找到引用内容", ""))
161 text = text.replace(match.group(0), f" (来源:[{quote.title}]({quote.url})) ")
162
163 return text.strip()

Callers 2

commit_conversationFunction · 0.90
mainFunction · 0.90

Calls 1

QuoteClass · 0.90

Tested by

no test coverage detected