change clip history policy
This commit is contained in:
parent
c181ad38b4
commit
f4127a9c9c
@ -404,7 +404,7 @@ def 编译Latex(chatbot, history, main_file_original, main_file_modified, work_f
|
|||||||
result_pdf = pj(work_folder_modified, f'merge_diff.pdf') # get pdf path
|
result_pdf = pj(work_folder_modified, f'merge_diff.pdf') # get pdf path
|
||||||
promote_file_to_downloadzone(result_pdf, rename_file=None, chatbot=chatbot) # promote file to web UI
|
promote_file_to_downloadzone(result_pdf, rename_file=None, chatbot=chatbot) # promote file to web UI
|
||||||
if modified_pdf_success:
|
if modified_pdf_success:
|
||||||
yield from update_ui_lastest_msg(f'转化PDF编译已经成功, 即将退出 ...', chatbot, history) # 刷新Gradio前端界面
|
yield from update_ui_lastest_msg(f'转化PDF编译已经成功, 正在尝试生成对比PDF, 请稍后 ...', chatbot, history) # 刷新Gradio前端界面
|
||||||
result_pdf = pj(work_folder_modified, f'{main_file_modified}.pdf') # get pdf path
|
result_pdf = pj(work_folder_modified, f'{main_file_modified}.pdf') # get pdf path
|
||||||
origin_pdf = pj(work_folder_original, f'{main_file_original}.pdf') # get pdf path
|
origin_pdf = pj(work_folder_original, f'{main_file_original}.pdf') # get pdf path
|
||||||
if os.path.exists(pj(work_folder, '..', 'translation')):
|
if os.path.exists(pj(work_folder, '..', 'translation')):
|
||||||
|
@ -1007,14 +1007,19 @@ def clip_history(inputs, history, tokenizer, max_token_limit):
|
|||||||
def get_token_num(txt):
|
def get_token_num(txt):
|
||||||
return len(tokenizer.encode(txt, disallowed_special=()))
|
return len(tokenizer.encode(txt, disallowed_special=()))
|
||||||
input_token_num = get_token_num(inputs)
|
input_token_num = get_token_num(inputs)
|
||||||
|
|
||||||
|
if max_token_limit < 5000: output_token_expect = 256 # 4k & 2k models
|
||||||
|
elif max_token_limit < 9000: output_token_expect = 512 # 8k models
|
||||||
|
else: output_token_expect = 1024 # 16k & 32k models
|
||||||
|
|
||||||
if input_token_num < max_token_limit * 3 / 4:
|
if input_token_num < max_token_limit * 3 / 4:
|
||||||
# 当输入部分的token占比小于限制的3/4时,裁剪时
|
# 当输入部分的token占比小于限制的3/4时,裁剪时
|
||||||
# 1. 把input的余量留出来
|
# 1. 把input的余量留出来
|
||||||
max_token_limit = max_token_limit - input_token_num
|
max_token_limit = max_token_limit - input_token_num
|
||||||
# 2. 把输出用的余量留出来
|
# 2. 把输出用的余量留出来
|
||||||
max_token_limit = max_token_limit - 128
|
max_token_limit = max_token_limit - output_token_expect
|
||||||
# 3. 如果余量太小了,直接清除历史
|
# 3. 如果余量太小了,直接清除历史
|
||||||
if max_token_limit < 128:
|
if max_token_limit < output_token_expect:
|
||||||
history = []
|
history = []
|
||||||
return history
|
return history
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user