File size: 1,220 Bytes
e76d8cf
 
 
7186d9b
 
 
 
e76d8cf
 
 
 
7186d9b
 
 
e76d8cf
 
7186d9b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from predict import predict_no_ui_long_connection
from toolbox import CatchException, report_execption, write_results_to_file
import datetime

@CatchException
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
    history = []    # 清空历史,以免输入溢出
    for i in range(3):
        currentMonth = (datetime.date.today() + datetime.timedelta(days=i)).month
        currentDay = (datetime.date.today() + datetime.timedelta(days=i)).day
        i_say = f'今天是{currentMonth}{currentDay}日,历史中的{currentMonth}{currentDay}日发生了哪些大事?'
        chatbot.append((i_say, "[Local Message] waiting gpt response."))
        yield chatbot, history, '正常'  # 由于请求gpt需要一段时间,我们先及时地做一次状态显示

        # history = [] 每次询问不携带之前的询问历史
        gpt_say = predict_no_ui_long_connection(inputs=i_say, top_p=top_p, temperature=temperature, history=[], sys_prompt="You are a history teacher.") # 请求gpt,需要一段时间

        chatbot[-1] = (i_say, gpt_say)
        history.append(i_say);history.append(gpt_say)
        yield chatbot, history, '正常'  # 显示