MCPcopy
hub / github.com/oobabooga/textgen / handle_edit_message_click

Function handle_edit_message_click

modules/chat.py:2624–2668  ·  view source on GitHub ↗
(state)

Source from the content-addressed store, hash-verified

2622
2623
2624def handle_edit_message_click(state):
2625 history = state['history']
2626 message_index = int(state['edit_message_index'])
2627 new_text = state['edit_message_text']
2628 role = state['edit_message_role'] # "user" or "assistant"
2629
2630 if message_index >= len(history['internal']):
2631 html_output = redraw_html(history, state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu'])
2632 return [history, html_output]
2633
2634 role_idx = 0 if role == "user" else 1
2635
2636 if 'metadata' not in history:
2637 history['metadata'] = {}
2638
2639 key = f"{role}_{message_index}"
2640 if key not in history['metadata']:
2641 history['metadata'][key] = {}
2642
2643 # If no versions exist yet for this message, store the current (pre-edit) content as the first version.
2644 if "versions" not in history['metadata'][key] or not history['metadata'][key]["versions"]:
2645 original_content = history['internal'][message_index][role_idx]
2646 original_visible = history['visible'][message_index][role_idx]
2647 original_timestamp = history['metadata'][key].get('timestamp', get_current_timestamp())
2648
2649 version_entry = {
2650 "content": original_content,
2651 "visible_content": original_visible,
2652 "timestamp": original_timestamp
2653 }
2654 ts = history['metadata'][key].get('tool_sequence')
2655 if ts is not None:
2656 version_entry['tool_sequence'] = ts
2657 history['metadata'][key]["versions"] = [version_entry]
2658
2659 history['internal'][message_index][role_idx] = apply_extensions('input', new_text, state, is_chat=True)
2660 history['visible'][message_index][role_idx] = html.escape(new_text)
2661 history['metadata'][key].pop('tool_sequence', None)
2662
2663 add_message_version(history, role, message_index, is_current=True)
2664
2665 save_history(history, state['unique_id'], state['character_menu'], state['mode'])
2666 html_output = redraw_html(history, state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu'])
2667
2668 return [history, html_output]
2669
2670
2671def handle_navigate_version_click(state):

Callers

nothing calls this directly

Calls 6

apply_extensionsFunction · 0.90
redraw_htmlFunction · 0.85
add_message_versionFunction · 0.85
save_historyFunction · 0.85
get_current_timestampFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected