我正在尝试与类似AI的系统进行对话,而且我一直在编写不同的单词对话。
我目前有:
hi = ['Hi', 'Hello', 'Sup', 'Howdy', 'Hey']
bye = ['Bye', 'Goodbye', 'Power down', 'Power off']
why = ['Why', 'For what']
hlp = ['Help', 'Assistance', 'Assistant', 'Aid']
med = ['Medical', 'Health']
like = ['Like', 'Enjoy', ]
name = str(input("Hello, I am Xavier. What is your name?\n"))
name = name.capitalize()
if name == 'D':
name = 'Creator'
print("\nHello there, " + name + ", I am here to be your virtual best friend, what ever I can do, I will do for you.\n")
while True:
import random
user_input = (input("\nInput\n>>> ")).capitalize()
user_input = user_input.split(" ")
for word in user_input:
if word in hi and word not in bye:
greeting = random.sample(['Hello there.', 'Howdy partner', 'It is nice to talk to you.', 'Hi friend.', 'Sup mah human!'], 1)
print (greeting)
elif word in bye and word not in hi:
farewell = random.sample(['Goodbye friend.', 'Goodbye', 'Farewell', 'See you later', 'Bye bud', 'Thanks for talking with me.'], 1)
print(farewell)
exit()
elif word in hi and word in bye:
print("You are confusing me.")
else:
els = random.sample(["That is not valid.", "Please try again.", "I apologize, but I do not understand.", "Try typing a different response.", "I do not comprehend.", "Je neux comprend pas."], 1)
print(els)
然而,当它运行时,它会单独读取每个单词,我想知道是否有一些我可以做的事情,使它只运行最相关的功能组合,而不是为每个单独运行一个,或者如果有的话一种让它读取每个单词的方法,并且具有诸如在输入中同时具有游戏和游戏的组合,并且将它们组合以执行单独的功能,不同于仅具有其中一个的功能。