我想让我的聊天机器人在服务器上运行,同时允许与用户来回进行对话。我怎样才能做到这一点?
我正在考虑使用 pm2 将机器人作为服务运行,但是如果用户正忙于收听传入的请求,用户怎么能“连接”到这个机器人呢?
我需要这个 .py 模块与机器人一起作为单独的服务器工作吗?
以下是机器人代码,它几乎是 chatterbot 设置指南中的样板:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
chatbot = ChatBot("Inssa Bot",
logic_adapters=[
"chatterbot.logic.MathematicalEvaluation",
"chatterbot.logic.TimeLogicAdapter"
],
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter"
)
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
chatbot.set_trainer(ListTrainer)
chatbot.train(conversation)
while True:
try:
say = input('Speak: ')
bot_input = chatbot.get_response(say)
print(bot_input)
except(KeyboardInterrupt, EOFError, SystemExit):
print('aaaaa')
break