Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions chatterbot/chatterbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,24 @@ def learn_response(self, statement, previous_statement=None):
"""
Learn that the statement provided is a valid response.
"""
from chatterbot.conversation import Statement

if not previous_statement:
previous_statement = statement.in_response_to

if not previous_statement:
previous_statement = self.get_latest_response(statement.conversation)
if previous_statement:
previous_statement = previous_statement.text
Comment thread
iamhssingh marked this conversation as resolved.

previous_statement_text = previous_statement

if not isinstance(previous_statement, (str, type(None), )):
if not isinstance(previous_statement, (Statement, str, type(None), )):
statement.in_response_to = previous_statement.text
elif isinstance(previous_statement, str):
statement.in_response_to = previous_statement

self.logger.info('Adding "{}" as a response to "{}"'.format(
Comment thread
iamhssingh marked this conversation as resolved.
statement.text,
previous_statement_text
))
elif isinstance(previous_statement, Statement):
statement.in_response_to = previous_statement.text
statement.search_in_response_to = previous_statement.search_text
previous_statement_text = previous_statement.text
Comment thread
iamhssingh marked this conversation as resolved.

# Save the input statement
return self.storage.create(**statement.serialize())
Expand Down