From 0903d2377f8c283175545471708f208f6e933e31 Mon Sep 17 00:00:00 2001 From: hwaking Date: Fri, 28 Apr 2023 14:51:48 +0800 Subject: [PATCH] Update web_demo2.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当前MAX_BOXES与MAX_TURNS不生效导致单次对话不终止显存不断增加最后显存溢出问题,修改最大对话轮数和最大历史对话数量使其生效,逻辑为历史最大对话框记录轮数达到MAX_BOXES时截断历史对话为最近MAX_TURNS数。 --- web_demo2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web_demo2.py b/web_demo2.py index 226682e..ce976b3 100644 --- a/web_demo2.py +++ b/web_demo2.py @@ -28,6 +28,8 @@ def predict(input, max_length, top_p, temperature, history=None): with container: if len(history) > 0: + if len(history)>MAX_BOXES: + history = history[-MAX_TURNS:] for i, (query, response) in enumerate(history): message(query, avatar_style="big-smile", key=str(i) + "_user") message(response, avatar_style="bottts", key=str(i)) @@ -66,4 +68,4 @@ if 'state' not in st.session_state: if st.button("发送", key="predict"): with st.spinner("AI正在思考,请稍等........"): # text generation - st.session_state["state"] = predict(prompt_text, max_length, top_p, temperature, st.session_state["state"]) \ No newline at end of file + st.session_state["state"] = predict(prompt_text, max_length, top_p, temperature, st.session_state["state"])