/dff-db-connector

Primary LanguagePythonApache License 2.0Apache-2.0

Dff DB Connector

Dff DB Connector is an extension to the Dialogflow Framework, a minimalistic open-source engine for conversational services.

Dff DB Connector allows you to 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.

Codestyle Tests License Apache 2.0 Python 3.6, 3.7, 3.8, 3.9

Quick Start

Installation

pip install dff-db-connector

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-db-connector[redis]
pip install dff-db-connector[mongodb]
pip install dff-db-connector[mysql]
pip install dff-db-connector[postgresql]
pip install dff-db-connector[sqlite]

Basic example

from df_engine.core import Context, Actor
from dff_db_connector import SqlConnector
from .plot import some_dff_plot

db = SqlConnector("postgresql://user:password@host:port/dbname")

actor = Actor(some_dff_plot, 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 Dff DB Connector

Please refer to CONTRIBUTING.md.