Update web_demo2.py

当前MAX_BOXES与MAX_TURNS不生效导致单次对话不终止显存不断增加最后显存溢出问题,修改最大对话轮数和最大历史对话数量使其生效,逻辑为历史最大对话框记录轮数达到MAX_BOXES时截断历史对话为最近MAX_TURNS数。
pull/851/head
hwaking 2023-04-28 14:51:48 +08:00 committed by GitHub
parent 2a9119bc96
commit 0903d2377f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -28,6 +28,8 @@ def predict(input, max_length, top_p, temperature, history=None):
with container: with container:
if len(history) > 0: if len(history) > 0:
if len(history)>MAX_BOXES:
history = history[-MAX_TURNS:]
for i, (query, response) in enumerate(history): for i, (query, response) in enumerate(history):
message(query, avatar_style="big-smile", key=str(i) + "_user") message(query, avatar_style="big-smile", key=str(i) + "_user")
message(response, avatar_style="bottts", key=str(i)) message(response, avatar_style="bottts", key=str(i))