-
Notifications
You must be signed in to change notification settings - Fork 80
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
Reload model changes. #1106
Reload model changes. #1106
Conversation
Warning Rate Limit Exceeded@nupur-khare has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 27 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe recent updates focus on enhancing the model reload functionality with better error handling, user activity logging, and audit logging. Changes include splitting the reload function for improved clarity, adding checks to prevent concurrent reloads, and ensuring that user activities are logged and audited appropriately. These modifications aim to streamline the reload process, making it more robust and transparent for users and administrators. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (10)
- kairon/chat/agent_processor.py (3 hunks)
- kairon/chat/routers/web_client.py (2 hunks)
- kairon/chat/utils.py (2 hunks)
- kairon/shared/constants.py (1 hunks)
- kairon/shared/data/audit/processor.py (1 hunks)
- tests/integration_test/chat_service_test.py (4 hunks)
- tests/integration_test/services_test.py (1 hunks)
- tests/unit_test/data_processor/agent_processor_test.py (3 hunks)
- tests/unit_test/data_processor/data_processor_test.py (1 hunks)
- tests/unit_test/utility_test.py (4 hunks)
Additional comments: 25
kairon/chat/routers/web_client.py (1)
- 79-81: The changes to
reload_model
function introduce a check to prevent concurrent reloads, which is a good practice to avoid race conditions. However, ensure that theChatUtils.is_reload_model_in_progress
method is atomic and thread-safe to prevent race conditions in a multi-threaded or multi-process environment.kairon/chat/agent_processor.py (3)
47-47: The
reload
function signature has been modified to include an64-70: User activity is logged upon successful model reload. It's important to ensure that the
UserActivityLogger.add_log
method handles any exceptions internally and does not disrupt the reload process.68-70: The logging of a model reload failure is done within the
except
block. Verify that theUserActivityLogger.add_log
method is robust and does not raise exceptions that could mask the original exception causing the reload to fail.kairon/shared/data/audit/processor.py (1)
- 32-32: The logic to fetch user information now considers bot data if account data is not provided. Ensure that this change does not introduce any security or privacy concerns, especially in cases where the bot data might not be intended to be used for user identification.
kairon/shared/constants.py (1)
- 61-63: The addition of
reload_model_enqueued
,reload_model_failure
, andreload_model_completion
to theUserActivityType
enum is consistent with the changes in other files to enhance logging and tracking of the model reload process.kairon/chat/utils.py (2)
39-57: The new
is_reload_model_in_progress
method introduces a mechanism to check for ongoing reloads. Verify that this method is reliable and does not return false negatives, which could lead to concurrent reloads.60-70: The updated
reload
method now includes error handling and user activity logging. Ensure that the error handling is comprehensive and that the logging does not interfere with the reload process or exception propagation.tests/unit_test/data_processor/agent_processor_test.py (2)
34-35: The test setup now includes
pytest.email
andpytest.account
assignments. Verify that these new assignments are used consistently across all relevant test cases and that they align with the new changes in the codebase.131-141: New test cases have been added to set up a user and bot for testing. Ensure that these test cases are complete and cover the scenarios introduced by the new changes, particularly the logging and error handling in the reload process.
tests/integration_test/chat_service_test.py (6)
5-5: Import of
datetime
module is correct and necessary for timestamping in tests.31-32: Import statements for
AuditLogData
andAuditlogActions
are correct and necessary for audit logging in tests.802-804: The addition of
mock_reload_model_in_progress
parameter totest_reload
function is necessary to mock the state of model reloading.846-866: The new test function
test_reload_event_already_in_progress
correctly tests the scenario where a reload event is already in progress.869-891: The new test function
test_reload_event_exception_in_reload
correctly tests the scenario where an exception occurs during the model reload.843-895: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [2-893]
No further issues found in the rest of the file.
tests/unit_test/utility_test.py (6)
7-7: Import of
datetime
module added.30-30: Import of
TelegramResponseConverter
added.31-31: Import of
ChatUtils
added.34-34: Import of
UserActivityType
added.37-37: Modification of
DEFAULT_SYSTEM_PROMPT
import.2787-2797: New test method
test_is_reload_model_in_progress_failure
added to check if the model reload is already in progress and raises an exception if it is.def test_is_reload_model_in_progress_failure(self): AuditLogData( attributes=[{"key": "bot", "value": pytest.bot}], user="test", timestamp=datetime.utcnow(), action=AuditlogActions.ACTIVITY.value, entity=UserActivityType.reload_model_enqueued.value, data={'message': 'Model reload enqueued!'} ).save() in_progress = ChatUtils.is_reload_model_in_progress(pytest.bot, False) assert in_progress with pytest.raises(AppException, match='Model reload enqueued. Check logs.'): ChatUtils.is_reload_model_in_progress(pytest.bot)tests/integration_test/services_test.py (1)
- 5863-5889: The test
test_reload_model_in_progress
is well-structured and includes proper mocking and assertions to validate the behavior when a model reload is already in progress. It checks the response status, message, and success flag, which aligns with the PR objectives to handle concurrent reload tasks.tests/unit_test/data_processor/data_processor_test.py (2)
15303-15305: The addition of
account_response
andbot_response
variables suggests that the test now includes creating an account and a bot before retrieving an agent. Ensure that these additions align with the test's purpose and that the created entities are properly cleaned up after the test to prevent side effects on other tests.15313-15316: The test case
test_get_agent_from_cache_does_not_exists
now includes setup steps for account and bot creation. Ensure that theAppException
is raised for the correct reason (agent not found) and not due to any other error. Also, confirm that any entities created during the test are properly cleaned up afterwards.
agent = AgentProcessor.get_agent("tests") | ||
account_response = AccountProcessor.add_account('test_agent_account', 'testAgent') | ||
bot_response = AccountProcessor.add_bot("tests", account_response["_id"], "testAgent") | ||
agent = AgentProcessor.get_agent("tests", account_response["_id"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The verification process has revealed the following:
- The
AgentProcessor.get_agent
method is called with a single parameter in multiple locations within the codebase, which does not match the updated method signature that requires two parameters. - The new method signature with two parameters is used in a few locations, but not consistently across the entire codebase.
Given this information, it is clear that not all calls to the AgentProcessor.get_agent
method have been updated to match the new signature. This inconsistency can lead to runtime errors where the method is called with an incorrect number of arguments.
Based on the findings:
- : Calls to
AgentProcessor.get_agent
with the old signature still exist in the codebase, which do not match the updated method signature requiring two parameters.
Analysis chain
The get_agent
method now takes an additional parameter. Verify that all calls to this method across the codebase have been updated to match the new signature.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for the old method signature to find omissions. Expecting no results.
ast-grep --lang python --pattern $'AgentProcessor.get_agent($_)'
# Search for the new method signature to validate usage. Expecting list of locations where the new signature is used.
ast-grep --lang python --pattern $'AgentProcessor.get_agent($_, $_)'
Length of output: 2170
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
reload
functionality for better management and logging.Tests
Documentation