mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-10-01 01:26:03 -04:00
UI: make text between quotes colored in chat mode
This commit is contained in:
parent
98ed6d3a66
commit
e637b702ff
12
css/main.css
12
css/main.css
@ -406,6 +406,18 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
|
|||||||
color: var(--body-text-color);
|
color: var(--body-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message q {
|
||||||
|
color: #707070;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .message q {
|
||||||
|
color: orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message q::before, .message q::after {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
|
||||||
.message-body li {
|
.message-body li {
|
||||||
list-style-position: outside;
|
list-style-position: outside;
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ def start_new_chat(state):
|
|||||||
greeting = replace_character_names(state['greeting'], state['name1'], state['name2'])
|
greeting = replace_character_names(state['greeting'], state['name1'], state['name2'])
|
||||||
if greeting != '':
|
if greeting != '':
|
||||||
history['internal'] += [['<|BEGIN-VISIBLE-CHAT|>', greeting]]
|
history['internal'] += [['<|BEGIN-VISIBLE-CHAT|>', greeting]]
|
||||||
history['visible'] += [['', apply_extensions('output', greeting, state, is_chat=True)]]
|
history['visible'] += [['', apply_extensions('output', html.escape(greeting), state, is_chat=True)]]
|
||||||
|
|
||||||
unique_id = datetime.now().strftime('%Y%m%d-%H-%M-%S')
|
unique_id = datetime.now().strftime('%Y%m%d-%H-%M-%S')
|
||||||
save_history(history, unique_id, state['character_menu'], state['mode'])
|
save_history(history, unique_id, state['character_menu'], state['mode'])
|
||||||
|
@ -42,6 +42,29 @@ def fix_newlines(string):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
def replace_quotes(text):
|
||||||
|
|
||||||
|
# Define a list of quote pairs (opening and closing), using HTML entities
|
||||||
|
quote_pairs = [
|
||||||
|
('"', '"'), # Double quotes
|
||||||
|
('“', '”'), # Unicode left and right double quotation marks
|
||||||
|
('‘', '’'), # Unicode left and right single quotation marks
|
||||||
|
('«', '»'), # French quotes
|
||||||
|
('„', '“'), # German quotes
|
||||||
|
('‘', '’'), # Alternative single quotes
|
||||||
|
('“', '”'), # Unicode quotes (numeric entities)
|
||||||
|
('“', '”'), # Unicode quotes (hex entities)
|
||||||
|
]
|
||||||
|
|
||||||
|
# Create a regex pattern that matches any of the quote pairs, including newlines
|
||||||
|
pattern = '|'.join(f'({re.escape(open_q)})(.*?)({re.escape(close_q)})' for open_q, close_q in quote_pairs)
|
||||||
|
|
||||||
|
# Replace matched patterns with <q> tags, keeping original quotes
|
||||||
|
replaced_text = re.sub(pattern, lambda m: f'<q>{m.group(1)}{m.group(2)}{m.group(3)}</q>', text, flags=re.DOTALL)
|
||||||
|
|
||||||
|
return replaced_text
|
||||||
|
|
||||||
|
|
||||||
def replace_blockquote(m):
|
def replace_blockquote(m):
|
||||||
return m.group().replace('\n', '\n> ').replace('\\begin{blockquote}', '').replace('\\end{blockquote}', '')
|
return m.group().replace('\n', '\n> ').replace('\\begin{blockquote}', '').replace('\\end{blockquote}', '')
|
||||||
|
|
||||||
@ -49,6 +72,9 @@ def replace_blockquote(m):
|
|||||||
@functools.lru_cache(maxsize=4096)
|
@functools.lru_cache(maxsize=4096)
|
||||||
def convert_to_markdown(string):
|
def convert_to_markdown(string):
|
||||||
|
|
||||||
|
# Quote to <q></q>
|
||||||
|
string = replace_quotes(string)
|
||||||
|
|
||||||
# Blockquote
|
# Blockquote
|
||||||
string = re.sub(r'(^|[\n])>', r'\1>', string)
|
string = re.sub(r'(^|[\n])>', r'\1>', string)
|
||||||
pattern = re.compile(r'\\begin{blockquote}(.*?)\\end{blockquote}', re.DOTALL)
|
pattern = re.compile(r'\\begin{blockquote}(.*?)\\end{blockquote}', re.DOTALL)
|
||||||
|
Loading…
Reference in New Issue
Block a user