IndexError: list index out of range (Chatbot is not working)

IndexError: list index out of range (Chatbot is not working)

我正在编写一个聊天机器人,但每次我 运行 我的程序开始对话时它都不起作用。 我收到该错误代码,为什么会这样,我该怎么办?

Error Code

说第46行有东西

def get_response(intents_list, intents_json):
tag = intents_list[0]["intent"] #line 46 
list_of_intents = intents["intents"]
for i in list_of_intents:
    if i ["tag"] == tag:
        result = random.choice(i["response"])
        break
return result

而且还说第59行有问题

while True:
message = input("")
ints = predict_class(message)
res = get_response(ints, intents) #line 59
print(res)

它确实看起来像 kike predict_class returns 一个空列表,所以 intents_list[0] 不存在并在第 46 行抛出越界。第 59 行只是调用堆栈,又名那就是你调用包含错误的函数的地方,你在该行上执行的操作。