From f604cd50ca1ce11a1cbececcdad3c8a806571a30 Mon Sep 17 00:00:00 2001 From: kodaline Date: Sat, 25 Nov 2023 00:24:03 +0100 Subject: [PATCH] IMP: method ad hoc for max user input - cheshire_cat.py: new method store_long_input_to_declarative to deal with very long inputs improvement of issue #558 --- core/cat/looking_glass/cheshire_cat.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/cat/looking_glass/cheshire_cat.py b/core/cat/looking_glass/cheshire_cat.py index 52a86353..8c7fcd95 100644 --- a/core/cat/looking_glass/cheshire_cat.py +++ b/core/cat/looking_glass/cheshire_cat.py @@ -428,16 +428,7 @@ def __call__(self, user_message_json): # split text after MAX_TEXT_INPUT tokens, on a whitespace, if any, and send it to declarative memory if len(user_message_json["text"]) > MAX_TEXT_INPUT: - index = MAX_TEXT_INPUT - char = user_message_json["text"][index] - while not char.isspace() and index > 0: - index -= 1 - char = user_message_json["text"][index] - if index <= 0: - index = MAX_TEXT_INPUT - user_message_json["text"], to_declarative_memory = user_message_json["text"][:index], user_message_json["text"][index:] - docs = self.rabbit_hole.string_to_docs(to_declarative_memory, content_type="text/plain") - self.rabbit_hole.store_documents(docs=docs, source="") + self.store_long_input_to_declarative(user_message_json) # store last message in working memory user_working_memory["user_message_json"] = user_message_json @@ -553,3 +544,15 @@ def get_static_path(): """Allows the Cat exposing the static files path.""" log.warning("This method will be removed, import cat.utils tu usit instead.") return utils.get_static_path() + + def store_long_input_to_declarative(self, user_message_json): + index = MAX_TEXT_INPUT + char = user_message_json["text"][index] + while not char.isspace() and index > 0: + index -= 1 + char = user_message_json["text"][index] + if index <= 0: + index = MAX_TEXT_INPUT + user_message_json["text"], to_declarative_memory = user_message_json["text"][:index], user_message_json["text"][index:] + docs = self.rabbit_hole.string_to_docs(to_declarative_memory, content_type="text/plain") + self.rabbit_hole.store_documents(docs=docs, source="") \ No newline at end of file