Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I Was Coding a chatbot, but it doesn’t work Every time I Run my program and start A conversation.
I get that error code, why is that so and what can I do ?

Error Code

It says that there is something in line 46

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

and it also says that there is a problem in line 59

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

>Solution :

It indeed looks kike predict_class returns an empty list so intents_list[0] does not exist and throws an out of bound on line 46. Line 59 is just the call stack, aka that is where you call the function that contains the error, which you do on that line.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading