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 '