Quickstart

Installation

  1. Install Flipgenic from PyPI:

    python -m pip install flipgenic
    
  2. Download the spaCy model:

    python -m spacy download en_core_web_md
    

Database Setup

Create an instance of Responder:

from flipgenic import Responder
responder = Responder('/path/to/storage/directory/')

Several files will be created in the given directory, which is also created if it does not exist.

Learning Responses

Initially, a Responder has no knowledge of how to communicate. You need to provide example replies which are reused in future conversations.

Responses are taught in pairs:

responder.learn_response('Hello', 'Hi')

Our Responder now knows that “Hi” is a suitable reply to “Hello”.

Batches

Multiple pairs can be added as a batch before saving:

responder.add_response('Hello', 'Hi')
responder.add_response('Hello', 'How are you?')
responder.add_response('How are you?', 'Fine, thanks!')
responder.commit_responses()

This is much more efficient when you are importing a large dataset. Data is held in memory until commit_responses is called.

Getting a Response

A response can be recalled as follows:

response, distance = responder.get_response('Hello')
print(response.text)

distance increases for uncertain replies. The lower the distance, the closer the match, and therefore responses with a lower distance are more likely to make sense.

Exact matches have a distance of 0. If no responses were available, the distance will be infinite. There is no upper limit on distances which can be returned, however values over 10 are unlikely for a populated database.