Package: dff
Dialog Flow FrameworkThe Dialog Flow Framework (DFF) allows you to develop conversational services.
DFF offers a specialized domain-specific language (DSL) for quickly writing dialogs in pure Python. The service is created by defining a special dialog graph that determines the behavior of the dialog agent. The latter is then leveraged in the DFF pipeline.
You can use the framework in various services such as social networks, call centers, websites, personal assistants, etc.Why choose DFFWritten in pure Python, the framework is easily accessible for both beginners and experienced developers.For the same reason, all the abstractions used in DFF can be easily customized and extended using regular language synthax.DFF offers easy and straightforward tools for state management which is as easy as setting values of a Python dictionary.The framework is being actively maintained and thoroughly tested. The team is open to suggestions and quickly reacts to bug reports.Quick StartInstallationDFF can be installed via pip:pipinstalldffThe above command will set the minimum dependencies to start working with DFF.
The installation process allows the user to choose from different packages based on their dependencies, which are:pipinstalldff[json]# dependencies for using JSONpipinstalldff[pickle]# dependencies for using Picklepipinstalldff[redis]# dependencies for using Redispipinstalldff[mongodb]# dependencies for using MongoDBpipinstalldff[mysql]# dependencies for using MySQLpipinstalldff[postgresql]# dependencies for using PostgreSQLpipinstalldff[sqlite]# dependencies for using SQLitepipinstalldff[ydb]# dependencies for using Yandex Databasepipinstalldff[telegram]# dependencies for using Telegrampipinstalldff[benchmark]# dependencies for benchmarkingFor example, if you are going to use one of the database backends,
you can specify the corresponding requirements yourself. Multiple dependencies can be installed at once, e.g.pipinstalldff[postgresql,mysql]Basic exampleThe following code snippet builds a simplistic chat bot that replies with messagesHi!andOKdepending on user input, which only takes a few lines of code.
All the abstractions used in this example are thoroughly explained in the dedicateduser guide.fromdff.scriptimportGLOBAL,TRANSITIONS,RESPONSE,Messagefromdff.pipelineimportPipelineimportdff.script.conditions.std_conditionsascnd# create a dialog scriptscript={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="OK")},},}# init pipelinepipeline=Pipeline.from_script(script,start_label=("flow","node_hi"))defturn_handler(in_request:Message,pipeline:Pipeline)->Message:# Pass user request into pipeline and get dialog context (message history)# The pipeline will automatically choose the correct response using scriptctx=pipeline(in_request,0)# Get last response from the contextout_response=ctx.last_responsereturnout_responsewhileTrue:in_request=input("Your message: ")out_response=turn_handler(Message(text=in_request),pipeline)print("Response: ",out_response.text)When you run this code, you get similar output:Your message: hi
Response:  OK
Your message: Hi
Response:  Hi!
Your message: ok
Response:  OK
Your message: ok
Response:  OKMore advanced examples are available as a part of documentation:tutorials.Further stepsTo further explore the API of the framework, you can make use of thedetailed documentation.
Broken down into several sections to highlight all the aspects of development with DFF,
the documentation for the library is constantly available online.Contributing to the Dialog Flow FrameworkWe are open to accepting pull requests and bug reports.
Please refer toCONTRIBUTING.md.LicenseDFF is distributed under the terms of theApache License 2.0.