The Dialog Flow Framework (DFF) 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. DFF 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 Framework
The Dialog Flow Framework (DFF) 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. DFF 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 -- dff
Installation
pip install dff
Basic example
from dff.script import GLOBAL, TRANSITIONS, RESPONSE, Context, Actor, Message
import dff.script.conditions.std_conditions as cnd
from typing import Union
# create script of dialog
script = {
GLOBAL: {TRANSITIONS: {("flow", "node_hi"): cnd.exact_match(Message(text="Hi")), ("flow", "node_ok"): cnd.true()}},
"flow": {
"node_hi": {RESPONSE: Message(text="Hi!!!")},
"node_ok": {RESPONSE: Message(text="Okey")},
},
}
# init actor
actor = Actor(script, start_label=("flow", "node_hi"))
# handler requests
def turn_handler(in_request: Message, 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(Message(text=in_request), ctx, actor)
print(out_response.text)
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.
Quick Start -- db_connector
Description
Dialog Flow DB Connector allows you to save and retrieve user dialogue states (in the form of a Context
object) using various database backends.
Currently, the supported options are:
Aside from this, we offer some interfaces for saving data to your local file system. These are not meant to be used in production, but can be helpful for prototyping your application.
Installation
pip install dff
Please, note that if you are going to use one of the database backends, you will have to specify an extra or install the corresponding requirements yourself.
pip install dff[redis]
pip install dff[mongodb]
pip install dff[mysql]
pip install dff[postgresql]
pip install dff[sqlite]
pip install dff[ydb]
Basic example
from dff.script import Context, Actor
from dff.context_storages import SQLContextStorage
from .script import some_df_script
db = SQLContextStorage("postgresql://user:password@host:port/dbname")
actor = Actor(some_df_script, start_label=("root", "start"), fallback_label=("root", "fallback"))
def handle_request(request):
user_id = request.args["user_id"]
if user_id not in db:
context = Context(id=user_id)
else:
context = db[user_id]
new_context = actor(context)
db[user_id] = new_context
assert user_id in db
return new_context.last_response
To get more advanced examples, take a look at examples on GitHub.
Contributing to the Dialog Flow Framework
Please refer to CONTRIBUTING.md.
TODO: split README.md to addons/README.rst & split examples and docs
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.