Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback Data while file upload #1596

Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion kairon/importer/data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ def import_data(self):
self.validator.bot_content,
self.validator.chat_client_config.get('config'),
self.validator.other_collections,
self.overwrite, self.files_to_save)
self.overwrite, self.files_to_save,
file_upload=True)
Comment on lines +59 to +60
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider making file_upload parameter configurable

The file_upload parameter is hardcoded to True, which means all imports will be treated as file uploads. Consider making this configurable through the constructor or method parameter to support different import scenarios.

- file_upload=True)
+ file_upload: bool = True)

And update the constructor:

 def __init__(self, path: Text, bot: Text, user: Text, files_to_save: set, save_data: bool = True,
-             overwrite: bool = True):
+             overwrite: bool = True, file_upload: bool = True):
     """Initialize data importer"""
     self.path = path
     self.bot = bot
     self.user = user
     self.save_data = save_data
     self.overwrite = overwrite
     self.files_to_save = files_to_save
+    self.file_upload = file_upload

Committable suggestion skipped: line range outside the PR's diff.

12 changes: 7 additions & 5 deletions kairon/shared/data/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ def save_training_data(
other_collections: dict = None,
overwrite: bool = False,
what: set = REQUIREMENTS.copy(),
file_upload: bool = False
):
if overwrite:
self.delete_bot_data(bot, user, what)
Expand All @@ -585,7 +586,7 @@ def save_training_data(
if "rules" in what:
self.save_rules(story_graph.story_steps, bot, user)
if "config" in what:
self.add_or_overwrite_config(config, bot, user)
self.add_or_overwrite_config(config, bot, user, file_upload)
if "chat_client_config" in what:
self.save_chat_client_config(chat_client_config, bot, user)
if "multiflow_stories" in what:
Expand Down Expand Up @@ -2131,7 +2132,7 @@ def save_config(self, configs: dict, bot: Text, user: Text):
logging.info(e)
raise AppException(e)

def add_or_overwrite_config(self, configs: dict, bot: Text, user: Text):
def add_or_overwrite_config(self, configs: dict, bot: Text, user: Text, file_upload: bool = False):
"""
saves bot configuration

Expand All @@ -2142,7 +2143,7 @@ def add_or_overwrite_config(self, configs: dict, bot: Text, user: Text):
"""
for custom_component in Utility.environment["model"]["pipeline"]["custom"]:
self.__insert_bot_id(configs, bot, custom_component)
self.add_default_fallback_config(configs, bot, user)
self.add_default_fallback_config(configs, bot, user, file_upload)
try:
config_obj = Configs.objects().get(bot=bot)
except DoesNotExist:
Expand Down Expand Up @@ -5402,7 +5403,7 @@ def prepare_training_data_for_validation(
rules = self.get_rules_for_training(bot)
YAMLStoryWriter().dump(rules_path, rules.story_steps)

def add_default_fallback_config(self, config_obj: dict, bot: Text, user: Text):
def add_default_fallback_config(self, config_obj: dict, bot: Text, user: Text, file_upload: bool = False):
idx = next(
(
idx
Expand Down Expand Up @@ -5449,7 +5450,8 @@ def add_default_fallback_config(self, config_obj: dict, bot: Text, user: Text):
fallback = {"name": "FallbackClassifier", "threshold": 0.7}
config_obj["pipeline"].insert(property_idx + 1, fallback)

self.add_default_fallback_data(bot, user, True, True)
if not file_upload:
self.add_default_fallback_data(bot, user, True, True)

def add_default_fallback_data(
self,
Expand Down
Loading