Python 如何在聊天机器人中为消息的响应添加延迟?
当我使用time.sleep(2)时,客户和支持消息都有2秒钟的延迟,但我只想为客户提供2秒钟的延迟。 在这个项目中,客户是botPython 如何在聊天机器人中为消息的响应添加延迟?,python,time,chatbot,Python,Time,Chatbot,当我使用time.sleep(2)时,客户和支持消息都有2秒钟的延迟,但我只想为客户提供2秒钟的延迟。 在这个项目中,客户是bot 这是从预测中提取的聊天机器人响应 这是用于发送消息和获取响应的函数 创建用于发送消息的按钮 你说的时间是什么意思?睡眠(2)不起作用?不,它不起作用。你能告诉我你尝试了什么,什么不起作用吗?你到底在哪里增加了时间。睡眠(2)?我刚刚更新了代码 def chatbot_response(msg): ints = predict_class(msg, model
你说的时间是什么意思?睡眠(2)不起作用?不,它不起作用。你能告诉我你尝试了什么,什么不起作用吗?你到底在哪里增加了时间。睡眠(2)?我刚刚更新了代码
def chatbot_response(msg):
ints = predict_class(msg, model)
res = getResponse(ints, intents)
return res
def send():
msg = EntryBox.get("1.0",'end-1c').strip()
EntryBox.delete("0.0",END)
if msg != '':
ChatLog.config(state=NORMAL)
ChatLog.insert(END, "Support: " + msg + '\n\n')
ChatLog.config(foreground="#442265", font=("Verdana", 12 ))
res = chatbot_response(msg)
time.sleep(2)
ChatLog.insert(END, "Customer: " + res + '\n\n')
ChatLog.config(state=DISABLED)
ChatLog.yview(END)
SendButton = Button(base, font=("Verdana",12,'bold'), text="Send", width="12", height=5,
bd=0, bg="#D4AF37", activebackground="#D4AF37",fg='#ffffff',
command= send )