Skip to content

Commit c4bfd1b

Browse files
authored
Added LLM validation for vector collection [Logs Message Fix] (#2378)
* Added LLM validation for vector collection * Added LLM validation for vector collection * Added LLM validation for vector collection [Logs Message Fix] * Added LLM validation for vector collection [Logs Message Fix] * Added LLM validation for vector collection [Logs Message Fix]
1 parent 085c3f1 commit c4bfd1b

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

kairon/shared/pyscript/analytics_worker.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from mongoengine import connect, disconnect
1010

1111
from kairon import Utility
12+
from kairon.exceptions import AppException
1213
from kairon.shared.concurrency.actors.utils import PyscriptUtility
1314
from kairon.shared.pyscript.shared_pyscript_utils import PyscriptSharedUtility
1415
from kairon.shared.pyscript.callback_pyscript_utils import CallbackScriptUtility
@@ -76,11 +77,18 @@ def main():
7677

7778
except Exception as e:
7879
exit_code = 1
79-
print(json.dumps({
80-
"success": False,
81-
"error": str(e),
82-
"trace": traceback.format_exc()
83-
}), flush=True)
80+
81+
if isinstance(e, AppException):
82+
print(json.dumps({
83+
"success": False,
84+
"message": str(e)
85+
}), flush=True)
86+
else:
87+
print(json.dumps({
88+
"success": False,
89+
"error": str(e),
90+
"trace": traceback.format_exc()
91+
}), flush=True)
8492

8593
finally:
8694
_cleanup_and_exit(exit_code)

kairon/shared/pyscript/callback_pyscript_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def create_vector_collection(collection_name, model_id: str, user: str,
581581

582582
bot_settings = ActionUtility.get_bot_settings(bot=bot)
583583
if not bot_settings.get("llm_settings", {}).get("enable_faq", False):
584-
raise AppException("LLM is disabled, Please enable it")
584+
raise AppException("LLM is disabled, please enable it")
585585

586586
knowledge_vault_name = collection_name
587587
collection_name = f"{bot}_{collection_name}_faq_embd"

tests/unit_test/callback/pyscript_handler_test.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from kairon import Utility
2323
from kairon.events.executors.factory import ExecutorFactory
2424
from kairon.exceptions import AppException
25+
from kairon.shared.pyscript import analytics_worker
2526
from kairon.shared.actions.data_objects import EmailActionConfig
2627
from kairon.shared.actions.utils import ActionUtility
2728
from kairon.shared.callback.data_objects import CallbackConfig, encrypt_secret
@@ -4558,7 +4559,25 @@ def test_create_vector_collection_llm_disabled():
45584559
bot="bot123"
45594560
)
45604561

4561-
assert "LLM is disabled, Please enable it" in str(exc.value)
4562+
assert "LLM is disabled, please enable it" in str(exc.value)
4563+
4564+
4565+
def test_analytics_worker_handles_app_exception(monkeypatch, capsys):
4566+
monkeypatch.setattr("sys.stdin", io.StringIO("{}"))
4567+
4568+
def mock_exec(*args, **kwargs):
4569+
raise AppException("LLM is disabled, please enable it")
4570+
4571+
def mock_cleanup(*args, **kwargs):
4572+
return
4573+
4574+
monkeypatch.setattr("builtins.exec", mock_exec)
4575+
monkeypatch.setattr(analytics_worker, "_cleanup_and_exit", mock_cleanup)
4576+
analytics_worker.main()
4577+
captured = capsys.readouterr()
4578+
4579+
assert '"success": false' in captured.out.lower()
4580+
assert '"message": "LLM is disabled, please enable it"' in captured.out
45624581

45634582

45644583
def test_create_vector_collection_embedding_size_from_process_instruction():

0 commit comments

Comments
 (0)