Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- context = {}
- ERROR_THRESHOLD = 0.25
- def classify(sentence):
- results = model.predict([bow(sentence, words)])[0]
- results = [[i,r] for i,r in enumerate(results) if r>ERROR_THRESHOLD]
- results.sort(key=lambda x: x[1], reverse=True)
- return_list = []
- for r in results:
- return_list.append((classes[r[0]], r[1]))
- return return_list
- def response(sentence, userID='123', show_details=False):
- results = classify(sentence)
- if results:
- while results:
- for i in intents['intents']:
- if i['tag'] == results[0][0]:
- if 'context_set' in i:
- if show_details: print ('context:', i['context_set'])
- context[userID] = i['context_set']
- if not 'context_filter' in i or (userID in context and 'context_filter' in i and i['context_filter'] == context[userID]):
- if show_details: print ('tag:', i['tag'])
- # sorteia uma resposta da intenção
- return print("ChatBot:",random.choice(i['responses']))
- results.pop(0)
- #funcao para receber frases e dar respostas com detalhes
- def mensagem(frase):
- response(frase, show_details=True)
- #example
- mensagem("oi tudo bem ?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement