mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-04-04 22:27:29 +00:00
Improve the wpp style & simplify the code
This commit is contained in:
parent
dfab11f0b5
commit
879fa3d8c4
2 changed files with 71 additions and 85 deletions
|
|
@ -595,64 +595,6 @@ def generate_cai_chat_html(history, name1, name2, style, character, reset_cache=
|
|||
return output
|
||||
|
||||
|
||||
def generate_chat_html(history, name1, name2, reset_cache=False, last_message_only=False):
|
||||
if not last_message_only:
|
||||
output = f'<style>{chat_styles["wpp"]}</style><div class="chat" id="chat"><div class="messages">'
|
||||
else:
|
||||
output = ""
|
||||
|
||||
def create_message(role, content, raw_content):
|
||||
"""Inner function for WPP-style messages."""
|
||||
text_class = "text-you" if role == "user" else "text-bot"
|
||||
|
||||
# Get role-specific data
|
||||
timestamp = format_message_timestamp(history, role, i)
|
||||
attachments = format_message_attachments(history, role, i)
|
||||
|
||||
# Create info button if timestamp exists
|
||||
info_message = ""
|
||||
if timestamp:
|
||||
tooltip_text = get_message_tooltip(history, role, i)
|
||||
info_message = info_button.replace('title="message"', f'title="{html.escape(tooltip_text)}"')
|
||||
|
||||
return (
|
||||
f'<div class="message" '
|
||||
f'data-raw="{html.escape(raw_content, quote=True)}"'
|
||||
f'data-index={i}>'
|
||||
f'<div class="{text_class}">'
|
||||
f'<div class="message-body">{content}</div>'
|
||||
f'{attachments}'
|
||||
f'{actions_html(history, i, role, info_message)}'
|
||||
f'</div>'
|
||||
f'</div>'
|
||||
)
|
||||
|
||||
# Determine range
|
||||
start_idx = len(history['visible']) - 1 if last_message_only else 0
|
||||
end_idx = len(history['visible'])
|
||||
|
||||
for i in range(start_idx, end_idx):
|
||||
row_visible = history['visible'][i]
|
||||
row_internal = history['internal'][i]
|
||||
|
||||
# Convert content
|
||||
if last_message_only:
|
||||
converted_visible = [None, convert_to_markdown_wrapped(row_visible[1], message_id=i, use_cache=i != len(history['visible']) - 1)]
|
||||
else:
|
||||
converted_visible = [convert_to_markdown_wrapped(entry, message_id=i, use_cache=i != len(history['visible']) - 1) for entry in row_visible]
|
||||
|
||||
# Generate messages
|
||||
if not last_message_only and converted_visible[0]:
|
||||
output += create_message("user", converted_visible[0], row_internal[0])
|
||||
|
||||
output += create_message("assistant", converted_visible[1], row_internal[1])
|
||||
|
||||
if not last_message_only:
|
||||
output += "</div></div>"
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def time_greeting():
|
||||
current_hour = datetime.datetime.now().hour
|
||||
if 5 <= current_hour < 12:
|
||||
|
|
@ -669,8 +611,6 @@ def chat_html_wrapper(history, name1, name2, mode, style, character, reset_cache
|
|||
result = f'<div class="chat" id="chat">{greeting}</div>'
|
||||
elif mode == 'instruct':
|
||||
result = generate_instruct_html(history, last_message_only=last_message_only)
|
||||
elif style == 'wpp':
|
||||
result = generate_chat_html(history, name1, name2, last_message_only=last_message_only)
|
||||
else:
|
||||
result = generate_cai_chat_html(history, name1, name2, style, character, reset_cache=reset_cache, last_message_only=last_message_only)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue