https://github.com/deeppavlov/dialog_flow_db_connector
Dialog Flow DB Connector is an addon for the Dialog Flow Framework and allows you to to save and retrieve user dialogue states (in the form of a `Context` object) using various database backends.
https://github.com/deeppavlov/dialog_flow_db_connector
Last synced: 6 months ago
JSON representation
Dialog Flow DB Connector is an addon for the Dialog Flow Framework and allows you to to save and retrieve user dialogue states (in the form of a `Context` object) using various database backends.
- Host: GitHub
- URL: https://github.com/deeppavlov/dialog_flow_db_connector
- Owner: deeppavlov
- License: apache-2.0
- Created: 2022-04-27T12:48:49.000Z (over 4 years ago)
- Default Branch: dev
- Last Pushed: 2022-08-24T21:19:00.000Z (almost 4 years ago)
- Last Synced: 2024-11-05T06:05:15.225Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 74.2 KB
- Stars: 1
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Dialog Flow DB Connector
[There](https://github.com/deepmipt/dialog_flow_db_connector) is an addon for the [Dialog Flow Framework](https://github.com/deepmipt/dialog_flow_engine), a minimalistic open-source engine for conversational services.
[Dialog Flow DB Connector](https://github.com/deepmipt/dialog_flow_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:
* [json](https://www.json.org/json-en.html)
* [pickle](https://docs.python.org/3/library/pickle.html)
* [shelve](https://docs.python.org/3/library/shelve.html)
* [Sqlite](https://www.sqlite.org/index.html)
* [Postgresql](https://www.postgresql.org/)
* [MySQL](https://www.mysql.com/)
* [MongoDB](https://www.mongodb.com/)
* [Redis](https://redis.io/)
* [YDB](https://ydb.tech/)
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.
[](https://github.com/deepmipt/dialog_flow_db_connector)
[](https://github.com/deepmipt/dialog_flow_db_connector)
[](https://github.com/deepmipt/dialog_flow_db_connector/blob/main/LICENSE)

# Quick Start
## Installation
```bash
pip install df-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.
```bash
pip install df-db-connector[redis]
pip install df-db-connector[mongodb]
pip install df-db-connector[mysql]
pip install df-db-connector[postgresql]
pip install df-db-connector[sqlite]
pip install df-db-connector[ydb]
```
## Basic example
```python
from df_engine.core import Context, Actor
from df_db_connector import SQLConnector
from .script import some_df_script
db = SQLConnector("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](https://github.com/deepmipt/dialog_flow_db_connector/tree/main/examples) on GitHub.
# Contributing to the Dialog Flow DB Connector
Please refer to [CONTRIBUTING.md](https://github.com/deepmipt/dialog_flow_db_connector/blob/main/CONTRIBUTING.md).