mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2025-06-09 07:07:16 -04:00
Fix re-translate when use Continue or Start reply with functions.
Please check the changes! This will improve the re-translation of texts when using the Continue button or the Start reply with field.
This commit is contained in:
parent
ace8afb825
commit
3247cced95
1 changed files with 21 additions and 4 deletions
|
@ -391,6 +391,10 @@ def chatbot_wrapper(text, state, regenerate=False, _continue=False, loading_mess
|
||||||
# Generate
|
# Generate
|
||||||
reply = None
|
reply = None
|
||||||
for j, reply in enumerate(generate_reply(prompt, state, stopping_strings=stopping_strings, is_chat=True, for_ui=for_ui)):
|
for j, reply in enumerate(generate_reply(prompt, state, stopping_strings=stopping_strings, is_chat=True, for_ui=for_ui)):
|
||||||
|
# Handle start_with text (add it only once at the beginning)
|
||||||
|
if state.get('start_with', '') and j == 0 and not _continue and not regenerate:
|
||||||
|
reply = state['start_with'] + " " + reply
|
||||||
|
state['start_with'] = '' # Clear it after using
|
||||||
|
|
||||||
# Extract the reply
|
# Extract the reply
|
||||||
if state['mode'] in ['chat', 'chat-instruct']:
|
if state['mode'] in ['chat', 'chat-instruct']:
|
||||||
|
@ -409,20 +413,33 @@ def chatbot_wrapper(text, state, regenerate=False, _continue=False, loading_mess
|
||||||
return
|
return
|
||||||
|
|
||||||
if _continue:
|
if _continue:
|
||||||
output['internal'][-1] = [text, last_reply[0] + reply]
|
# For continuation, we need to separate the already translated part from the new generated text
|
||||||
output['visible'][-1] = [visible_text, last_reply[1] + visible_reply]
|
original_translated = output['visible'][-1][1] # Already translated part
|
||||||
|
new_content = reply[len(output['internal'][-1][1]):] if reply.startswith(output['internal'][-1][1]) else reply
|
||||||
|
new_content = new_content.lstrip()
|
||||||
|
|
||||||
|
# Only send the new content for translation
|
||||||
|
translated_new_content = apply_extensions('output', new_content, state, is_chat=True)
|
||||||
|
|
||||||
|
# Combine with the existing translation
|
||||||
|
full_translated = original_translated + " " + translated_new_content
|
||||||
|
|
||||||
|
output['internal'][-1] = [text, reply.lstrip(' ')]
|
||||||
|
output['visible'][-1] = [visible_text, full_translated]
|
||||||
if is_stream:
|
if is_stream:
|
||||||
yield output
|
yield output
|
||||||
elif not (j == 0 and visible_reply.strip() == ''):
|
elif not (j == 0 and visible_reply.strip() == ''):
|
||||||
output['internal'][-1] = [text, reply.lstrip(' ')]
|
output['internal'][-1] = [text, reply.lstrip(' ')]
|
||||||
output['visible'][-1] = [visible_text, visible_reply.lstrip(' ')]
|
output['visible'][-1] = [visible_text, apply_extensions('output', visible_reply.lstrip(' '), state, is_chat=True)]
|
||||||
if is_stream:
|
if is_stream:
|
||||||
yield output
|
yield output
|
||||||
|
|
||||||
if output['visible'][-1][1].endswith('▍'):
|
if output['visible'][-1][1].endswith('▍'):
|
||||||
output['visible'][-1][1] = output['visible'][-1][1][:-1]
|
output['visible'][-1][1] = output['visible'][-1][1][:-1]
|
||||||
|
|
||||||
output['visible'][-1][1] = apply_extensions('output', output['visible'][-1][1], state, is_chat=True)
|
# No need to apply extensions here for _continue case as we already handled it
|
||||||
|
if not _continue:
|
||||||
|
output['visible'][-1][1] = apply_extensions('output', output['visible'][-1][1], state, is_chat=True)
|
||||||
yield output
|
yield output
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue