diff --git a/modules/models/base_model.py b/modules/models/base_model.py index 8535d008..3df666df 100644 --- a/modules/models/base_model.py +++ b/modules/models/base_model.py @@ -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'

{action_name}: {action_input}\n\n

' + return f'

{action_name}: {action_input}\n

' else: return "" diff --git a/modules/utils.py b/modules/utils.py index 36cecaab..d5a387f5 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -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'

(.*?)<\/p>' - agent_matches = re.findall(agent_prefix_pattern, message_clipped) + agent_prefix_pattern = r'(

.*?<\/p>)' + # 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'

{part}

' - 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'
{escape_markdown(part)}
' if need_escape else f'
{part}
' + else: + final_message += part return final_message @@ -233,7 +231,7 @@ def convert_bot_before_marked(chat_message): if '
' in chat_message: return chat_message else: - raw = f'
{clip_rawtext(chat_message)}
' + raw = f'
{clip_rawtext(chat_message)}
' # really_raw = f'{START_OF_OUTPUT_MARK}
{clip_rawtext(chat_message, need_escape=False)}\n
{END_OF_OUTPUT_MARK}' code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL) diff --git a/web_assets/stylesheet/chatbot.css b/web_assets/stylesheet/chatbot.css index 2a3d00a9..a7be4a0a 100644 --- a/web_assets/stylesheet/chatbot.css +++ b/web_assets/stylesheet/chatbot.css @@ -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: '🐯';