mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2025-06-09 07:07:16 -04:00
Add the model name to each message's metadata
This commit is contained in:
parent
0816ecedb7
commit
9e80193008
2 changed files with 32 additions and 17 deletions
|
@ -710,7 +710,7 @@ def chatbot_wrapper(text, state, regenerate=False, _continue=False, loading_mess
|
||||||
|
|
||||||
# Add timestamp for assistant's response at the start of generation
|
# Add timestamp for assistant's response at the start of generation
|
||||||
row_idx = len(output['internal']) - 1
|
row_idx = len(output['internal']) - 1
|
||||||
update_message_metadata(output['metadata'], "assistant", row_idx, timestamp=get_current_timestamp())
|
update_message_metadata(output['metadata'], "assistant", row_idx, timestamp=get_current_timestamp(), model_name=shared.model_name)
|
||||||
|
|
||||||
# Generate
|
# Generate
|
||||||
reply = None
|
reply = None
|
||||||
|
|
|
@ -350,12 +350,14 @@ remove_button = f'<button class="footer-button footer-remove-button" title="Remo
|
||||||
info_button = f'<button class="footer-button footer-info-button" title="message">{info_svg}</button>'
|
info_button = f'<button class="footer-button footer-info-button" title="message">{info_svg}</button>'
|
||||||
|
|
||||||
|
|
||||||
def format_message_timestamp(history, role, index):
|
def format_message_timestamp(history, role, index, tooltip_include_timestamp=True):
|
||||||
"""Get a formatted timestamp HTML span for a message if available"""
|
"""Get a formatted timestamp HTML span for a message if available"""
|
||||||
key = f"{role}_{index}"
|
key = f"{role}_{index}"
|
||||||
if 'metadata' in history and key in history['metadata'] and history['metadata'][key].get('timestamp'):
|
if 'metadata' in history and key in history['metadata'] and history['metadata'][key].get('timestamp'):
|
||||||
timestamp = history['metadata'][key]['timestamp']
|
timestamp = history['metadata'][key]['timestamp']
|
||||||
return f"<span class='timestamp'>{timestamp}</span>"
|
tooltip_text = get_message_tooltip(history, role, index, include_timestamp=tooltip_include_timestamp)
|
||||||
|
title_attr = f' title="{html.escape(tooltip_text)}"' if tooltip_text else ''
|
||||||
|
return f"<span class='timestamp'{title_attr}>{timestamp}</span>"
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -388,6 +390,23 @@ def format_message_attachments(history, role, index):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def get_message_tooltip(history, role, index, include_timestamp=True):
|
||||||
|
"""Get tooltip text combining timestamp and model name for a message"""
|
||||||
|
key = f"{role}_{index}"
|
||||||
|
if 'metadata' not in history or key not in history['metadata']:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
meta = history['metadata'][key]
|
||||||
|
tooltip_parts = []
|
||||||
|
|
||||||
|
if include_timestamp and meta.get('timestamp'):
|
||||||
|
tooltip_parts.append(meta['timestamp'])
|
||||||
|
if meta.get('model_name'):
|
||||||
|
tooltip_parts.append(f"Model: {meta['model_name']}")
|
||||||
|
|
||||||
|
return " | ".join(tooltip_parts)
|
||||||
|
|
||||||
|
|
||||||
def get_version_navigation_html(history, i, role):
|
def get_version_navigation_html(history, i, role):
|
||||||
"""Generate simple navigation arrows for message versions"""
|
"""Generate simple navigation arrows for message versions"""
|
||||||
key = f"{role}_{i}"
|
key = f"{role}_{i}"
|
||||||
|
@ -462,15 +481,13 @@ def generate_instruct_html(history):
|
||||||
# Create info buttons for timestamps if they exist
|
# Create info buttons for timestamps if they exist
|
||||||
info_message_user = ""
|
info_message_user = ""
|
||||||
if user_timestamp != "":
|
if user_timestamp != "":
|
||||||
# Extract the timestamp value from the span
|
tooltip_text = get_message_tooltip(history, "user", i)
|
||||||
user_timestamp_value = user_timestamp.split('>', 1)[1].split('<', 1)[0]
|
info_message_user = info_button.replace('title="message"', f'title="{html.escape(tooltip_text)}"')
|
||||||
info_message_user = info_button.replace("message", user_timestamp_value)
|
|
||||||
|
|
||||||
info_message_assistant = ""
|
info_message_assistant = ""
|
||||||
if assistant_timestamp != "":
|
if assistant_timestamp != "":
|
||||||
# Extract the timestamp value from the span
|
tooltip_text = get_message_tooltip(history, "assistant", i)
|
||||||
assistant_timestamp_value = assistant_timestamp.split('>', 1)[1].split('<', 1)[0]
|
info_message_assistant = info_button.replace('title="message"', f'title="{html.escape(tooltip_text)}"')
|
||||||
info_message_assistant = info_button.replace("message", assistant_timestamp_value)
|
|
||||||
|
|
||||||
if converted_visible[0]: # Don't display empty user messages
|
if converted_visible[0]: # Don't display empty user messages
|
||||||
output += (
|
output += (
|
||||||
|
@ -521,8 +538,8 @@ def generate_cai_chat_html(history, name1, name2, style, character, reset_cache=
|
||||||
converted_visible = [convert_to_markdown_wrapped(entry, message_id=i, use_cache=i != len(history['visible']) - 1) for entry in row_visible]
|
converted_visible = [convert_to_markdown_wrapped(entry, message_id=i, use_cache=i != len(history['visible']) - 1) for entry in row_visible]
|
||||||
|
|
||||||
# Get timestamps
|
# Get timestamps
|
||||||
user_timestamp = format_message_timestamp(history, "user", i)
|
user_timestamp = format_message_timestamp(history, "user", i, tooltip_include_timestamp=False)
|
||||||
assistant_timestamp = format_message_timestamp(history, "assistant", i)
|
assistant_timestamp = format_message_timestamp(history, "assistant", i, tooltip_include_timestamp=False)
|
||||||
|
|
||||||
# Get attachments
|
# Get attachments
|
||||||
user_attachments = format_message_attachments(history, "user", i)
|
user_attachments = format_message_attachments(history, "user", i)
|
||||||
|
@ -580,15 +597,13 @@ def generate_chat_html(history, name1, name2, reset_cache=False):
|
||||||
# Create info buttons for timestamps if they exist
|
# Create info buttons for timestamps if they exist
|
||||||
info_message_user = ""
|
info_message_user = ""
|
||||||
if user_timestamp != "":
|
if user_timestamp != "":
|
||||||
# Extract the timestamp value from the span
|
tooltip_text = get_message_tooltip(history, "user", i)
|
||||||
user_timestamp_value = user_timestamp.split('>', 1)[1].split('<', 1)[0]
|
info_message_user = info_button.replace('title="message"', f'title="{html.escape(tooltip_text)}"')
|
||||||
info_message_user = info_button.replace("message", user_timestamp_value)
|
|
||||||
|
|
||||||
info_message_assistant = ""
|
info_message_assistant = ""
|
||||||
if assistant_timestamp != "":
|
if assistant_timestamp != "":
|
||||||
# Extract the timestamp value from the span
|
tooltip_text = get_message_tooltip(history, "assistant", i)
|
||||||
assistant_timestamp_value = assistant_timestamp.split('>', 1)[1].split('<', 1)[0]
|
info_message_assistant = info_button.replace('title="message"', f'title="{html.escape(tooltip_text)}"')
|
||||||
info_message_assistant = info_button.replace("message", assistant_timestamp_value)
|
|
||||||
|
|
||||||
if converted_visible[0]: # Don't display empty user messages
|
if converted_visible[0]: # Don't display empty user messages
|
||||||
output += (
|
output += (
|
||||||
|
|
Loading…
Add table
Reference in a new issue