Stavové boty

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

Co rozumíme pod pojmem stavový?

"Miluji bezstavové systémy!"

"bezco nemají nevýhody?"

"nemají snad nevýhody?"

Building Chatbots in Python

Stavové automaty

  • Procházení nabídky
  • Zadání adresy a platebních údajů
  • Objednávka dokončena
Building Chatbots in Python

Implementace stavového automatu

INIT = 0
CHOOSE_COFFEE = 1
ORDERED = 2

Příklad pravidel:

policy_rules = {
    (INIT, "order"): (CHOOSE_COFFEE, "ok, Columbian or Kenyan?"),
    (CHOOSE_COFFEE, "specify_coffee"): 
    (ORDERED, "perfect, the beans are on their way!"),
}
Building Chatbots in Python

Použití stavového automatu

state = INIT
def respond(state, message):
   (new_state, response) = policy_rules[(state,
                                   interpret(message))]
   return new_state, response

def send_message(state, message):
    new_state, response = respond(state, message)
    return new_state

state = send_message(state, message)
Building Chatbots in Python

Pojďme si procvičit!

Building Chatbots in Python

Preparing Video For Download...