flipgenic package¶
-
class
flipgenic.
Message
(text: str, metadata: Optional[str] = None)¶ Bases:
object
A piece of text.
- Parameters
text – The text of the message.
metadata – An arbitrary string which can be retrieved when the message is chosen as a response.
-
metadata
: str = None¶
-
text
: str¶
-
class
flipgenic.
Responder
(data_directory, spacy_model='en_core_web_md')¶ Bases:
object
Holds a database connection and handles learning and producing responses.
- Parameters
data_directory – Path to a folder which holds files for this Responder. Will be created if it doesn’t exist.
model – SpaCy model, or the name of one to be loaded.
-
add_response
(prompt, message)¶ Process a response pair without saving it immediately.
The response won’t be available as an output from
get_response
untilcommit_responses
is called.- Parameters
prompt – The text this is in response to.
message – The response to be learned. This can be a simple string, or an instance of
Message
if you would like to include metadata.
-
commit_responses
()¶ Save any responses which have not yet been written to the database.
-
get_all_responses
(text)¶ Return all relevant responses to a prompt along with their distance.
The distance returned gets closer to 0 the more confident the response is. There is no hard limit to how large the distance can be, however distances tend to range between 0 and 10.
Note that this only returns messages which are linked to the same vector, so their distances are all the same.
- Returns
(list of Message instances, distance)
-
get_response
(text)¶ Return the most confident response to a prompt.
The distance returned gets closer to 0 the more confident the response is. There is no hard limit to how large the distance can be, however distances tend to range between 0 and 10.
- Parameters
text – The prompt to respond to.
- Returns
Tuple of (message, distance).
-
learn_response
(*args, **kwargs)¶ Add a response pair and save it immediately.
Takes the same parameters as
add_response
.Other unsaved responses will also be committed when you call this method.