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

Hide Default Slots from UI #1612

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

himanshugt16
Copy link
Contributor

@himanshugt16 himanshugt16 commented Dec 2, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced data validation for uploaded training files, providing summaries of validation errors.
    • Improved handling of slot retrieval by excluding system slots.
  • Bug Fixes

    • Robust error handling added for saving HTTP actions and configuration files.
  • Tests

    • Updated tests to validate the exclusion of system slots in slot retrieval, ensuring accuracy in response data.

Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request focus on the MongoProcessor class within the kairon/shared/data/processor.py file. Key modifications include the exclusion of system slots in the get_existing_slots method, the addition of a validation step in the validate_and_prepare_data method for uploaded training files, and improved error handling in the save_data_without_event method. Additionally, the test suite in tests/integration_test/services_test.py has been updated to reflect these changes, particularly in validating the slot retrieval process.

Changes

File Change Summary
kairon/shared/data/processor.py - Updated get_existing_slots to exclude system slots.
- Modified validate_and_prepare_data to include validation for uploaded files.
- Enhanced save_data_without_event with better error handling.
tests/integration_test/services_test.py - Added KaironSystemSlots import.
- Introduced excluded_slots variable in test_get_slots to validate slot retrieval against excluded slots.

Possibly related PRs

  • slot mapped actions fix #1588: Modifies the MongoProcessor class in kairon/shared/data/processor.py, affecting methods related to slot mapping, relevant to the filtering of system slots.
  • Delete slot and slot mapping #1605: Alters the MongoProcessor class in kairon/shared/data/processor.py, specifically the delete_slot method, which is related to overall slot management improvements.

Poem

🐇 In the land of slots and data bright,
A rabbit hops with pure delight.
System slots, now out of sight,
Validation's here, all feels just right!
With every save, a joyful cheer,
For clean data brings us near! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
tests/integration_test/services_test.py (1)

9702-9712: Test modifications look good with a minor readability suggestion.

The test changes effectively validate both the count and content of returned slots, ensuring system slots are properly excluded.

Consider extracting the magic number 21 to a constant for better maintainability:

+    TOTAL_SLOTS_COUNT = 21  # Total number of slots before exclusion
-    assert len(actual["data"]) == 21 - len(excluded_slots)
+    assert len(actual["data"]) == TOTAL_SLOTS_COUNT - len(excluded_slots)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f2f296b and b255b17.

📒 Files selected for processing (3)
  • kairon/shared/data/processor.py (1 hunks)
  • tests/integration_test/services_test.py (2 hunks)
  • tests/unit_test/data_processor/data_processor_test.py (1 hunks)
🔥 Files not summarized due to errors (1)
  • tests/unit_test/data_processor/data_processor_test.py: Error: Server error: no LLM provider could handle the message
🔇 Additional comments (2)
tests/integration_test/services_test.py (2)

50-50: LGTM!

The addition of KaironSystemSlots import is appropriate and well-placed with other constant imports.


9702-9712: Verify similar test cases for consistency.

While these changes look good, we should ensure other test cases that deal with slots are updated consistently.

Let's check for other test cases that might need similar updates:

✅ Verification successful

Let me gather more specific information about the test cases that might need updates.


Based on the analysis of the test files, I can now provide a final response:

No additional test updates required for system slot exclusion

The system slot exclusion logic is correctly implemented in the specific test case, and after reviewing related test cases, no other tests require similar updates because:

  • The only slot count assertion in integration tests that needs to handle system slot exclusion is already updated in the current changes
  • Other slot-related tests in the codebase are either:
    • Unit tests that work with specific, controlled test data
    • Tests that verify different aspects of slots (influence_conversation, mapping, etc.)
    • Tests that don't deal with system slots enumeration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for other test cases that might need similar updates
# Look for test cases that deal with slots and might need similar exclusion logic

# Search for test methods that deal with slots
rg -l "test.*slot" "tests/"

# Search for assertions on slot counts
rg "assert.*len.*slot" "tests/"

# Search for specific slot-related API calls
rg "get_existing_slots|slot.*response.json" "tests/"

Length of output: 4231


Script:

#!/bin/bash
# Get more context around slot-related test assertions
rg -B 5 -A 5 "assert.*len.*slot" tests/integration_test/services_test.py tests/unit_test/data_processor/data_processor_test.py

# Look for system slot related patterns
rg -B 3 -A 3 "system.*slot|slot.*system" tests/

Length of output: 17820

]
assert len(slots) == 24
assert len(slots) == 10
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

The test assertion needs to be updated to reflect system slots exclusion

Based on the implementation in get_existing_slots, the method now explicitly excludes system slots defined in KaironSystemSlots enum (which includes 'kairon_action_response', 'bot', 'image', 'audio', 'video'). However, the test still expects 10 slots in total, which doesn't align with this filtering behavior. The test should be updated to expect fewer slots, excluding these system slots.

  • tests/unit_test/data_processor/data_processor_test.py: Update the assertion assert len(slots) == 10 to reflect the correct number of slots after system slots exclusion.
🔗 Analysis chain

Verify if this assertion aligns with hiding default slots

The assertion len(slots) == 10 seems to include all slots, which might be inconsistent with the PR objective of hiding default slots from the UI. Please verify if this test case should be updated to reflect the new behavior where default slots are excluded.

Let's verify the implementation of slot filtering:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the implementation of get_existing_slots to understand the expected behavior
ast-grep --pattern 'def get_existing_slots'

# Search for any constants or configurations defining default/system slots
rg -l "default.*slots|system.*slots" --type py

Length of output: 315


Script:

#!/bin/bash
# Let's examine the implementation of get_existing_slots in the processor
rg -A 10 "def get_existing_slots" kairon/shared/data/processor.py

# Look for the test context around the assertion
rg -B 5 -A 5 "assert len\(slots\) == 10" tests/unit_test/data_processor/data_processor_test.py

# Search for any system/default slots definitions
rg "DEFAULT_SLOTS|SYSTEM_SLOTS" --type py

Length of output: 1141


Script:

#!/bin/bash
# Let's look for KaironSystemSlots definition
rg -A 5 "class KaironSystemSlots" --type py

# Let's see the full test context to understand what slots are being tested
ast-grep --pattern 'def test_get_existing_slots'

# Look for any slot-related enums or constants
rg "class.*Slots.*\(Enum\)" --type py

Length of output: 464

Comment on lines +5267 to +5269
excluded_slots = list(KaironSystemSlots)
query = Q(bot=bot, status=True) & Q(name__nin=excluded_slots)
for slot in Slots.objects(query):
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical Issue: Exclude system slot names correctly by extracting values

Currently, excluded_slots = list(KaironSystemSlots) will create a list of Enum members, not their values. This means the query name__nin=excluded_slots may not filter out the system slots as intended. To properly exclude the system slots by their names, you should extract the .value from each Enum member.

Apply this diff to fix the issue:

-            excluded_slots = list(KaironSystemSlots)
+            excluded_slots = [slot.value for slot in KaironSystemSlots]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
excluded_slots = list(KaironSystemSlots)
query = Q(bot=bot, status=True) & Q(name__nin=excluded_slots)
for slot in Slots.objects(query):
excluded_slots = [slot.value for slot in KaironSystemSlots]
query = Q(bot=bot, status=True) & Q(name__nin=excluded_slots)
for slot in Slots.objects(query):

Copy link
Collaborator

@hiteshghuge hiteshghuge left a comment

Choose a reason for hiding this comment

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

reviewed

@hiteshghuge hiteshghuge merged commit 9d1d50e into digiteinfotech:master Dec 2, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants