Skip to content

Commit ea4e29d

Browse files
committed
Persist tags to output
1 parent 2b33c9d commit ea4e29d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

chatterbot/chatterbot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ def __init__(self, statement, count=1):
232232
persona='bot:' + self.name
233233
)
234234

235+
response.add_tags(*result.get_tags())
236+
235237
response.confidence = result.confidence
236238

237239
return response

tests/test_chatbot.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ def test_response_with_tags_added(self):
222222
self.assertIsLength(results, 2)
223223
self.assertIn('test', results[0].get_tags())
224224

225+
def test_response_preserves_tags(self):
226+
"""
227+
The response returned from the chatbot should preserve tags
228+
from the statement that was used to generated the response.
229+
"""
230+
self._create_with_search_text(text='Hello', tags=['test'])
231+
response = self.chatbot.get_response('Hello')
232+
233+
self.assertEqual(response.get_tags(), ['test'])
234+
225235
def test_get_response_with_text_and_kwargs(self):
226236
self.chatbot.get_response('Hello', conversation='greetings')
227237

0 commit comments

Comments
 (0)