Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
fb1e611
1
Parent(s):
17ee059
fix: 修正新的原始文本输出在川虎助理中的显示
Browse files- modules/models/base_model.py +1 -1
- modules/utils.py +10 -12
- web_assets/stylesheet/chatbot.css +7 -1
modules/models/base_model.py
CHANGED
@@ -78,7 +78,7 @@ def get_action_description(text):
|
|
78 |
action_name = json_dict['action']
|
79 |
action_input = json_dict['action_input']
|
80 |
if action_name != "Final Answer":
|
81 |
-
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}\n
|
82 |
else:
|
83 |
return ""
|
84 |
|
|
|
78 |
action_name = json_dict['action']
|
79 |
action_input = json_dict['action_input']
|
80 |
if action_name != "Final Answer":
|
81 |
+
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}\n</p><!-- E O PREFIX -->'
|
82 |
else:
|
83 |
return ""
|
84 |
|
modules/utils.py
CHANGED
@@ -211,18 +211,16 @@ def clip_rawtext(chat_message, need_escape=True):
|
|
211 |
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
|
212 |
message_clipped = chat_message[:hr_match.start()] if hr_match else chat_message
|
213 |
# second, avoid agent-prefix being escaped
|
214 |
-
agent_prefix_pattern = r'<!-- S O PREFIX --><p class="agent-prefix"
|
215 |
-
agent_matches = re.findall(agent_prefix_pattern, message_clipped)
|
|
|
216 |
final_message = ""
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
final_message += f'<!-- S O PREFIX --><p class="agent-prefix">{part}</p><!-- E O PREFIX -->'
|
224 |
-
else:
|
225 |
-
final_message = escape_markdown(message_clipped) if need_escape else message_clipped
|
226 |
return final_message
|
227 |
|
228 |
|
@@ -233,7 +231,7 @@ def convert_bot_before_marked(chat_message):
|
|
233 |
if '<div class="md-message">' in chat_message:
|
234 |
return chat_message
|
235 |
else:
|
236 |
-
raw = f'<div class="raw-message hideM"
|
237 |
# really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_rawtext(chat_message, need_escape=False)}\n</div>{END_OF_OUTPUT_MARK}'
|
238 |
|
239 |
code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
|
|
|
211 |
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
|
212 |
message_clipped = chat_message[:hr_match.start()] if hr_match else chat_message
|
213 |
# second, avoid agent-prefix being escaped
|
214 |
+
agent_prefix_pattern = r'(<!-- S O PREFIX --><p class="agent-prefix">.*?<\/p><!-- E O PREFIX -->)'
|
215 |
+
# agent_matches = re.findall(agent_prefix_pattern, message_clipped)
|
216 |
+
agent_parts = re.split(agent_prefix_pattern, message_clipped, flags=re.DOTALL)
|
217 |
final_message = ""
|
218 |
+
for i, part in enumerate(agent_parts):
|
219 |
+
if i % 2 == 0:
|
220 |
+
if part != "" and part != "\n":
|
221 |
+
final_message += f'<pre class="fake-pre">{escape_markdown(part)}</pre>' if need_escape else f'<pre class="fake-pre">{part}</pre>'
|
222 |
+
else:
|
223 |
+
final_message += part
|
|
|
|
|
|
|
224 |
return final_message
|
225 |
|
226 |
|
|
|
231 |
if '<div class="md-message">' in chat_message:
|
232 |
return chat_message
|
233 |
else:
|
234 |
+
raw = f'<div class="raw-message hideM">{clip_rawtext(chat_message)}</div>'
|
235 |
# really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_rawtext(chat_message, need_escape=False)}\n</div>{END_OF_OUTPUT_MARK}'
|
236 |
|
237 |
code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
|
web_assets/stylesheet/chatbot.css
CHANGED
@@ -42,7 +42,13 @@ hr.append-display {
|
|
42 |
.agent-prefix {
|
43 |
font-size: smaller;
|
44 |
opacity: 0.6;
|
45 |
-
padding: 6px 0
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
}
|
47 |
.agent-prefix::before {
|
48 |
content: '🐯';
|
|
|
42 |
.agent-prefix {
|
43 |
font-size: smaller;
|
44 |
opacity: 0.6;
|
45 |
+
padding: 6px 0 12px;
|
46 |
+
}
|
47 |
+
.raw-message p.agent-prefix + p.agent-prefix {
|
48 |
+
margin-top: -1.2em !important;
|
49 |
+
}
|
50 |
+
.md-message p.agent-prefix + p.agent-prefix {
|
51 |
+
margin-top: -1.8em !important;
|
52 |
}
|
53 |
.agent-prefix::before {
|
54 |
content: '🐯';
|