The Dialog Flow Engine (DFE) allows you to write conversational services. The service is written by defining a special dialog graph that describes the behavior of the dialog service. The dialog graph contains the dialog script. DFE offers a specialized language (DSL) for quickly writing dialog graphs. You can use it in such services for writing skills for Amazon Alexa and etc, chat-bots for social networks, websites call-centers and etc.
Project description
Dialog Flow Engine
The Dialog Flow Engine (DFE) allows you to write conversational services. The service is written by defining a special dialog graph that describes the behavior of the dialog service. The dialog graph contains the dialog script. DFE offers a specialized language (DSL) for quickly writing dialog graphs. You can use it in such services for writing skills for Amazon Alexa and etc, chat-bots for social networks, websites call-centers and etc.
Quick Start
Installation
pip install df_engine
Basic example
from df_engine.core.keywords import GLOBAL, TRANSITIONS, RESPONSE
from df_engine.core import Context, Actor
import df_engine.conditions as cnd
from typing import Union
# create script of dialog
script = {
GLOBAL: {TRANSITIONS: {("flow", "node_hi"): cnd.exact_match("Hi"), ("flow", "node_ok"): cnd.true()}},
"flow": {
"node_hi": {RESPONSE: "Hi!!!"},
"node_ok": {RESPONSE: "Okey"},
},
}
# init actor
actor = Actor(script, start_label=("flow", "node_hi"))
# handler requests
def turn_handler(in_request: str, ctx: Union[Context, dict], actor: Actor):
# Context.cast - gets an object type of [Context, str, dict] returns an object type of Context
ctx = Context.cast(ctx)
# Add in current context a next request of user
ctx.add_request(in_request)
# pass the context into actor and it returns updated context with actor response
ctx = actor(ctx)
# get last actor response from the context
out_response = ctx.last_response
# the next condition branching needs for testing
return out_response, ctx
ctx = {}
while True:
in_request = input("type your answer: ")
out_response, ctx = turn_handler(in_request, ctx, actor)
print(out_response)
When you run this code, you get similar output:
type your answer: hi
Okey
type your answer: Hi
Hi!!!
type your answer: ok
Okey
type your answer: ok
Okey
To get more advanced examples, take a look at examples on GitHub.
Contributing to the Dialog Flow Engine
Please refer to CONTRIBUTING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file df_qwerty-0.9.0.tar.gz
.
File metadata
- Download URL: df_qwerty-0.9.0.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27f392424942a079d33d1fe23bc731ab9440db9bd675f83fa1ec0c1d221d676e |
|
MD5 | 1f763b59f7df6e6e001cdefc3f5773f8 |
|
BLAKE2b-256 | 034caf2ecb9c8f8f77684d66ebf02040eb1af52ea0f19e9c3f2eeb3281a59a59 |
File details
Details for the file df_qwerty-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: df_qwerty-0.9.0-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9339f811c53d0895e92e812fba2b146d7f94678b9010172adc1a4def847b147f |
|
MD5 | d44da4e8e0e080a410be34e28c771940 |
|
BLAKE2b-256 | 333322d7b475de62de29a4a067f1528a51444123fda86c7f865f20eee42166cf |