Skip to main content

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.

Documentation Status Codestyle Tests License Apache 2.0 Python 3.7, 3.8, 3.9 PyPI Downloads

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dff-0.2.0.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dff-0.2.0-py3-none-any.whl (84.2 kB view details)

Uploaded Python 3

File details

Details for the file dff-0.2.0.tar.gz.

File metadata

  • Download URL: dff-0.2.0.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for dff-0.2.0.tar.gz
Algorithm Hash digest
SHA256 674605e75787ba94e931a5b796708b8ed8186f848a659e9ff8c9ac6ee2bd25d4
MD5 e6a66f16e1edddbe623d8cab749491fa
BLAKE2b-256 1c9227c68cba2b82ff3d4f2a0de14525ec84d6996da87d33abedb8f9a6826c27

See more details on using hashes here.

File details

Details for the file dff-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dff-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 84.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for dff-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2265876be776351ac7b6bdf069b5d497d99fb924315dd9f91c84925a45220090
MD5 d1bd0491b85208018330a0de50655663
BLAKE2b-256 5ccef73acc62966c37759f3e58bfe18c387c8b1fa395572a045f67613b3b0513

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page