mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2025-06-08 22:56:24 -04:00
Save the chat history periodically during streaming
This commit is contained in:
parent
a1b3307b66
commit
1c7209a725
1 changed files with 8 additions and 1 deletions
|
@ -5,6 +5,7 @@ import html
|
||||||
import json
|
import json
|
||||||
import pprint
|
import pprint
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -485,10 +486,16 @@ def generate_chat_reply_wrapper(text, state, regenerate=False, _continue=False):
|
||||||
send_dummy_reply(state['start_with'], state)
|
send_dummy_reply(state['start_with'], state)
|
||||||
|
|
||||||
history = state['history']
|
history = state['history']
|
||||||
|
last_save_time = time.monotonic()
|
||||||
|
save_interval = 8
|
||||||
for i, history in enumerate(generate_chat_reply(text, state, regenerate, _continue, loading_message=True, for_ui=True)):
|
for i, history in enumerate(generate_chat_reply(text, state, regenerate, _continue, loading_message=True, for_ui=True)):
|
||||||
yield chat_html_wrapper(history, state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu']), history
|
yield chat_html_wrapper(history, state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu']), history
|
||||||
if i == 0:
|
|
||||||
|
current_time = time.monotonic()
|
||||||
|
# Save on first iteration or if save_interval seconds have passed
|
||||||
|
if i == 0 or (current_time - last_save_time) >= save_interval:
|
||||||
save_history(history, state['unique_id'], state['character_menu'], state['mode'])
|
save_history(history, state['unique_id'], state['character_menu'], state['mode'])
|
||||||
|
last_save_time = current_time
|
||||||
|
|
||||||
save_history(history, state['unique_id'], state['character_menu'], state['mode'])
|
save_history(history, state['unique_id'], state['character_menu'], state['mode'])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue