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

fix:finish extracting intent classes from adapt package #248

Merged
merged 4 commits into from
Oct 14, 2024
Merged

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Oct 14, 2024

ports usage of "excludes"

needed for OpenVoiceOS/ovos-core#527

companion to OpenVoiceOS/ovos-adapt-pipeline-plugin#6

Summary by CodeRabbit

  • New Features
    • Introduced an excludes parameter in the Intent class to specify entities that should not be included.
    • Enhanced the IntentBuilder class to support the exclusion of specific entities during intent construction.
  • Improvements
    • Streamlined the validation process for intents, allowing for more complex definitions and improved handling of required and optional entities.
    • Updated intent registration tests to incorporate the excludes functionality, ensuring accurate intent management.

@github-actions github-actions bot added the fix label Oct 14, 2024
Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request introduces substantial modifications to the Intent and IntentBuilder classes in the ovos_workshop/intents.py file. Key changes include the addition of an excludes parameter to the Intent constructor, enhancements to the validation methods, and updates to the IntentBuilder class to support excluded entities. The tests in test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py have also been updated to reflect these changes, ensuring that the intent registration logic correctly incorporates the excludes functionality.

Changes

File Path Change Summary
ovos_workshop/intents.py Updated _IntentMeta for improved instance checks; restructured Intent to include excludes parameter; modified validate and validate_with_tags methods for streamlined validation; updated IntentBuilder to include excludes and modified build method; added exclude method in IntentBuilder; several helper methods enhanced.
test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py Modified tests to include excludes in expected results for test_register_intent, test_enable_disable_intent, and test_register_decorators; improved formatting and structure for readability.

Poem

🐇 In the workshop where intents do play,
New paths are forged, bright as day.
With excludes now, we craft with care,
No unwanted tags, just the ones we share.
A dance of logic, a hop of delight,
Intentions clear, our future is bright! 🌟


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.

@github-actions github-actions bot added fix and removed fix labels Oct 14, 2024
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: 1

🧹 Outside diff range and nitpick comments (3)
ovos_workshop/intents.py (3)

Line range hint 26-39: Update the docstring of the Intent constructor to include the excludes parameter

The __init__ method of the Intent class now includes the excludes parameter, but the docstring does not document this parameter. Please update the docstring to include a description of excludes and its purpose.


52-65: Reflect exclusion logic in the validate_with_tags method docstring

The validate_with_tags method now includes logic to handle excluded entities. The docstring should be updated to mention that it checks for excluded entities before validating required and optional entities, and that it returns a confidence of 0.0 if any excluded entities are found.


Line range hint 559-585: Handle 'excludes' in the munge_intent_parser function

The munge_intent_parser function currently modifies the requires, optional, and at_least_one attributes to make them skill-exclusive. With the addition of the excludes attribute to the Intent class, please update the function to also munge the excludes list to ensure consistency and correct behavior.

Apply this diff to handle excludes in munge_intent_parser:

 def munge_intent_parser(intent_parser, name, skill_id):
     # Existing code...

     # Munge optional keywords
     opts = []
     for i in intent_parser.optional:
         if not i[0].startswith(skill_id):
             kw = (skill_id + i[0], skill_id + i[0])
             opts.append(kw)
         else:
             opts.append(i)
     intent_parser.optional = opts

+    # Munge excludes keywords
+    excludes = []
+    for entity in intent_parser.excludes:
+        if not entity.startswith(skill_id):
+            excludes.append(skill_id + entity)
+        else:
+            excludes.append(entity)
+    intent_parser.excludes = excludes

     # Munge at_least_one keywords
     at_least_one = []
     for i in intent_parser.at_least_one:
         element = [skill_id + e.replace(skill_id, '') for e in i]
         at_least_one.append(tuple(element))
     intent_parser.at_least_one = at_least_one
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6a1aa6a and 9fa58fa.

📒 Files selected for processing (1)
  • ovos_workshop/intents.py (7 hunks)
🧰 Additional context used

ovos_workshop/intents.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 64.35644% with 36 lines in your changes missing coverage. Please review.

Project coverage is 49.58%. Comparing base (7c02206) to head (ac06d73).
Report is 34 commits behind head on dev.

Files with missing lines Patch % Lines
ovos_workshop/intents.py 64.35% 36 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #248      +/-   ##
==========================================
- Coverage   53.41%   49.58%   -3.84%     
==========================================
  Files          37       37              
  Lines        4362     4439      +77     
==========================================
- Hits         2330     2201     -129     
- Misses       2032     2238     +206     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added fix and removed fix labels Oct 14, 2024
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: 0

🧹 Outside diff range and nitpick comments (1)
test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py (1)

Line range hint 112-267: Consider enhancing tests for 'excludes' functionality

While the addition of the 'excludes' field to the expected results is correct and consistent across all relevant test methods, consider enhancing the tests to more thoroughly validate the 'excludes' functionality:

  1. Add test cases that explicitly check the behavior of intents with non-empty 'excludes' lists.
  2. Include tests that verify the runtime behavior of intents with exclusions, not just their registration.
  3. Consider adding edge cases, such as circular exclusions or exclusions of non-existent intents.

These additions would provide more comprehensive coverage of the new functionality and help catch potential edge cases or unexpected behaviors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9fa58fa and 6bbbda9.

📒 Files selected for processing (1)
  • test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py (5 hunks)
🧰 Additional context used
🔇 Additional comments (5)
test/unittests/skills/test_mycroft_skill/test_mycroft_skill.py (5)

112-113: LGTM: 'excludes' field added to expected intent registration result.

The addition of the 'excludes' field to the expected result in the test_register_intent method is consistent with the changes described in the PR objectives. This update correctly tests for the new functionality of excluding intents.


125-126: LGTM: 'excludes' field added to expected intent registration result for IntentBuilder.

The addition of the 'excludes' field to the expected result for the IntentBuilder object in the test_register_intent method is correct and consistent with the previous change. This ensures that the test covers the new functionality for both Intent and IntentBuilder objects.


147-148: LGTM: 'excludes' field added to expected result in enable/disable intent test.

The addition of the 'excludes' field to the expected result in the test_enable_disable_intent method is appropriate. This change ensures that the test correctly verifies the presence of the 'excludes' field when enabling an intent.


167-168: LGTM: 'excludes' field added to expected result in enable/disable intent handlers test.

The addition of the 'excludes' field to the expected result in the test_enable_disable_intent_handlers method is correct. This change ensures that the test verifies the presence of the 'excludes' field when enabling an intent through the intent handlers.


266-267: LGTM: 'excludes' field added to expected result in register decorators test.

The addition of the 'excludes' field to the expected result in the test_register_decorators method is appropriate. This change ensures that the test verifies the presence of the 'excludes' field when using decorated intents.

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 (2)
ovos_workshop/intents.py (2)

Line range hint 26-39: Add unit tests for the new 'excludes' functionality

The Intent class now includes an excludes parameter to handle excluded entities. To ensure this new feature works correctly and to prevent future regressions, it's important to add unit tests that cover scenarios involving excluded entities.

Would you like assistance in creating unit tests for the excludes parameter?


272-283: Improve the docstring formatting for the exclude method

The docstring for the exclude method lacks proper formatting and clarity.

Apply this diff to enhance readability and conform to documentation standards:

         """
-        The intent parser must not contain an entity of the provided type.
-
-        Args:
-            entity_type(str): an entity type
-
-        Returns:
-            self: to continue modifications.
-        """
+        """The intent parser must not contain an entity of the provided type.
+
+        Args:
+            entity_type (str): The entity type to exclude.
+
+        Returns:
+            IntentBuilder: The instance of IntentBuilder to allow method chaining.
+        """

This clarifies the purpose of the method and correctly formats the docstring.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6bbbda9 and 2cacfc8.

📒 Files selected for processing (1)
  • ovos_workshop/intents.py (7 hunks)
🧰 Additional context used

Comment on lines +119 to +122
CLIENT_ENTITY_NAME = 'Client' # TODO - ??? what is this magic string

target_client, canonical_form, confidence = \
self._find_first_tag(local_tags, CLIENT_ENTITY_NAME)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Clarify the purpose of CLIENT_ENTITY_NAME and address the TODO comment

The constant CLIENT_ENTITY_NAME is set to 'Client', accompanied by a TODO comment questioning its purpose:

CLIENT_ENTITY_NAME = 'Client'  # TODO - ??? what is this magic string

It's important to address this TODO comment to improve code clarity. If CLIENT_ENTITY_NAME is necessary, please provide documentation explaining its role. If it's unused or obsolete, consider removing it to clean up the codebase.

Would you like assistance in determining the necessity of CLIENT_ENTITY_NAME and updating the code accordingly?

ovos_workshop/intents.py Show resolved Hide resolved
@JarbasAl JarbasAl merged commit 95ee0eb into dev Oct 14, 2024
8 of 9 checks passed
@JarbasAl JarbasAl deleted the fix/Adapt branch October 14, 2024 05:08
@coderabbitai coderabbitai bot mentioned this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant