Skip to content

Commit

Permalink
fix: 修正新的原始文本输出在川虎助理中的显示
Browse files Browse the repository at this point in the history
  • Loading branch information
Keldos-Li committed Nov 18, 2023
1 parent 17ee059 commit fb1e611
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion modules/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_action_description(text):
action_name = json_dict['action']
action_input = json_dict['action_input']
if action_name != "Final Answer":
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}\n\n</p><!-- E O PREFIX -->'
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}\n</p><!-- E O PREFIX -->'
else:
return ""

Expand Down
22 changes: 10 additions & 12 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,16 @@ def clip_rawtext(chat_message, need_escape=True):
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
message_clipped = chat_message[:hr_match.start()] if hr_match else chat_message
# second, avoid agent-prefix being escaped
agent_prefix_pattern = r'<!-- S O PREFIX --><p class="agent-prefix">(.*?)<\/p><!-- E O PREFIX -->'
agent_matches = re.findall(agent_prefix_pattern, message_clipped)
agent_prefix_pattern = r'(<!-- S O PREFIX --><p class="agent-prefix">.*?<\/p><!-- E O PREFIX -->)'
# agent_matches = re.findall(agent_prefix_pattern, message_clipped)
agent_parts = re.split(agent_prefix_pattern, message_clipped, flags=re.DOTALL)
final_message = ""
if agent_matches:
agent_parts = re.split(agent_prefix_pattern, message_clipped)
for i, part in enumerate(agent_parts):
if i % 2 == 0:
final_message += escape_markdown(part) if need_escape else part
else:
final_message += f'<!-- S O PREFIX --><p class="agent-prefix">{part}</p><!-- E O PREFIX -->'
else:
final_message = escape_markdown(message_clipped) if need_escape else message_clipped
for i, part in enumerate(agent_parts):
if i % 2 == 0:
if part != "" and part != "\n":
final_message += f'<pre class="fake-pre">{escape_markdown(part)}</pre>' if need_escape else f'<pre class="fake-pre">{part}</pre>'
else:
final_message += part
return final_message


Expand All @@ -233,7 +231,7 @@ def convert_bot_before_marked(chat_message):
if '<div class="md-message">' in chat_message:
return chat_message
else:
raw = f'<div class="raw-message hideM"><pre class="fake-pre">{clip_rawtext(chat_message)}</pre></div>'
raw = f'<div class="raw-message hideM">{clip_rawtext(chat_message)}</div>'
# 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}'

code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
Expand Down
8 changes: 7 additions & 1 deletion web_assets/stylesheet/chatbot.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ hr.append-display {
.agent-prefix {
font-size: smaller;
opacity: 0.6;
padding: 6px 0 4px;
padding: 6px 0 12px;
}
.raw-message p.agent-prefix + p.agent-prefix {
margin-top: -1.2em !important;
}
.md-message p.agent-prefix + p.agent-prefix {
margin-top: -1.8em !important;
}
.agent-prefix::before {
content: '🐯';
Expand Down

0 comments on commit fb1e611

Please sign in to comment.