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

feat/domain_engine #31

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

feat/domain_engine #31

wants to merge 6 commits into from

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Dec 9, 2024

match the skill first, and then the intent

Summary by CodeRabbit

  • New Features

    • Introduced a new DomainIntentContainer class for domain-aware intent recognition.
    • Added intent_names property to both IntentContainer and IntentManager classes for easier access to intent names.
    • Enhanced PadatiousPipeline to accept different intent container types.
  • Bug Fixes

    • Improved the handling of intent removal based on the container type.
  • Tests

    • Added unit tests for the DomainIntentContainer to ensure correct intent registration and calculations.
  • Chores

    • Minor adjustments made to type hints and deprecation warnings for a streamlined API.

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes in this pull request enhance the IntentContainer, IntentManager, and introduce a new DomainIntentContainer class, which organizes intents into domains for better management. The IntentContainer now has a default cache directory and a new property for intent names. The IntentManager also gains a property for accessing intent names. Additionally, unit tests for the new DomainIntentContainer are introduced, ensuring functionality for domain-specific intent management.

Changes

File Path Change Summary
ovos_padatious/intent_container.py Updated __init__ to set a default cache_dir, added intent_names property.
ovos_padatious/intent_manager.py Added intent_names property to aggregate intent names from training data.
tests/test_domain.py Added unit tests for DomainIntentContainer, including methods for registering/removing intents and calculating domains.
ovos_padatious/domain_container.py Introduced DomainIntentContainer class with methods for managing domain-specific intents and entities.
ovos_padatious/opm.py Modified PadatiousPipeline to accept engine_class, updated methods for intent registration and detachment.

Possibly related PRs

  • drop threading #19: This PR modifies the IntentContainer class, which is directly related to the changes made in the main PR that also involves the IntentContainer class, specifically in the constructor and method signatures.
  • feat!:pipeline factory #15: Changes in this PR to the PadatiousPipeline class may indirectly relate to the main PR's enhancements in the IntentContainer, as both are part of the intent management system and may interact with each other.
  • feat/opm_pipeline #2: Similar to feat!:pipeline factory #15, this PR involves the PadatiousPipeline and its interaction with intent management, which could be relevant to the changes made in the main PR regarding intent handling.

Suggested labels

feature, breaking

🐰 In a world of intents, we hop and play,
New domains to explore, come join the fray!
With containers that cache, and names to declare,
Our intent's now structured, with love and care.
So let’s train our models, let’s make them bright,
For every query, we’ll get it right! 🌟


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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: 4

🧹 Outside diff range and nitpick comments (4)
ovos_padatious/domain_engine.py (2)

128-131: Avoid reusing variable names to prevent confusion

In the calc_intent method, the parameter domain is reassigned within the method using domain = domain or self.domain_engine.calc_intent(query).name. Reusing the variable name domain can lead to confusion and reduce code readability. Consider using a different variable name for the local assignment, such as resolved_domain.

Apply this diff to rename the local variable:

-        domain: str = domain or self.domain_engine.calc_intent(query).name
+        resolved_domain = domain or self.domain_engine.calc_intent(query).name
+        if resolved_domain in self.domains:
+            return self.domains[resolved_domain].calc_intent(query)
-        if domain in self.domains:
-            return self.domains[domain].calc_intent(query)

147-154: Clarify variable naming in loops to enhance readability

In the calc_intents method, the parameter domain and the loop variable domain represent different entities—one is a string, and the other is a MatchData object. This reuse of the variable name domain may cause confusion. Consider renaming the loop variable to something like domain_match for clarity.

Apply this diff to rename the loop variable:

             matches = []
             domains = self.calc_domains(query)[:top_k_domains]
-            for domain in domains:
-                if domain.name in self.domains:
-                    matches += self.domains[domain.name].calc_intents(query)
+            for domain_match in domains:
+                if domain_match.name in self.domains:
+                    matches += self.domains[domain_match.name].calc_intents(query)
tests/test_domain.py (1)

5-5: Remove placeholder comment in import statement

Line 5 contains a placeholder comment that suggests replacing 'your_module' with the actual module name. Since the module is correctly imported, the comment can be removed to clean up the code.

Apply this diff to remove the comment:

- from ovos_padatious.domain_engine import DomainIntentEngine  # Replace 'your_module' with the actual module name
+ from ovos_padatious.domain_engine import DomainIntentEngine
ovos_padatious/intent_container.py (1)

59-59: Update docstring to reflect optional cache_dir parameter

Since cache_dir is now optional and defaults to a computed path if not provided, the docstring should be updated to indicate that cache_dir is optional.

Apply this diff to update the docstring:

     """
     Creates an IntentContainer object used to load and match intents

     Args:
-        cache_dir (str): Directory for caching the neural network models and intent/entity files.
+        cache_dir (Optional[str]): Directory for caching the neural network models and intent/entity files. If not provided, a default path is used.
     """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d5965cb and 26af1fc.

📒 Files selected for processing (4)
  • ovos_padatious/domain_engine.py (1 hunks)
  • ovos_padatious/intent_container.py (3 hunks)
  • ovos_padatious/intent_manager.py (1 hunks)
  • tests/test_domain.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.0)
tests/test_domain.py

3-3: ovos_padatious.intent_container.IntentContainer imported but unused

Remove unused import: ovos_padatious.intent_container.IntentContainer

(F401)

🔇 Additional comments (2)
ovos_padatious/intent_manager.py (1)

25-28: Addition of intent_names property is appropriate

The new intent_names property correctly provides a list of intent names from both trained intents and intents pending training. This enhances accessibility and aligns with best practices.

ovos_padatious/intent_container.py (1)

70-73: The addition of intent_names property enhances encapsulation

The new intent_names property provides external access to the intent names managed by the IntentContainer, promoting encapsulation and improving usability.

ovos_padatious/domain_engine.py Outdated Show resolved Hide resolved
tests/test_domain.py Outdated Show resolved Hide resolved
tests/test_domain.py Outdated Show resolved Hide resolved
ovos_padatious/intent_container.py Show resolved Hide resolved
@JarbasAl JarbasAl marked this pull request as draft December 9, 2024 21:18
match the skill first, and then the intent
match the skill first, and then the intent
@JarbasAl JarbasAl marked this pull request as ready for review December 12, 2024 11:59
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_padatious/domain_container.py (1)

135-135: Avoid reassigning function parameters with type annotations

In line 135, the parameter domain is reassigned with a type annotation:

domain: str = domain or self.domain_engine.calc_intent(query).name

Reassigning a function parameter can lead to confusion and is generally discouraged. Additionally, re-annotating the variable domain is unnecessary since it is already typed in the function signature. Consider assigning the value to a new local variable without re-annotation:

-domain: str = domain or self.domain_engine.calc_intent(query).name
+current_domain = domain or self.domain_engine.calc_intent(query).name
tests/test_domain.py (1)

4-4: Remove placeholder comment in import statement

In line 4, there is a placeholder comment that is no longer needed:

from ovos_padatious.domain_container import DomainIntentContainer  # Replace 'your_module' with the actual module name

Since the module import is already correct, remove the placeholder comment to clean up the code:

-from ovos_padatious.domain_container import DomainIntentContainer  # Replace 'your_module' with the actual module name
+from ovos_padatious.domain_container import DomainIntentContainer
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26af1fc and 02d2aa3.

📒 Files selected for processing (5)
  • ovos_padatious/domain_container.py (1 hunks)
  • ovos_padatious/intent_container.py (3 hunks)
  • ovos_padatious/intent_manager.py (1 hunks)
  • ovos_padatious/opm.py (11 hunks)
  • tests/test_domain.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • ovos_padatious/intent_manager.py
  • ovos_padatious/intent_container.py

ovos_padatious/opm.py Outdated Show resolved Hide resolved
Comment on lines +304 to +306
skill_id = message.data.get("skill_id") or message.context.get("skill_id")
self._skill2intent[skill_id].append(message.data['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

Ensure skill_id is properly obtained and handled

In the register_intent method, skill_id is obtained using:

skill_id = message.data.get("skill_id") or message.context.get("skill_id")

If skill_id is None, the intent might be registered under a None key in _skill2intent, which could lead to issues when detaching intents or skills. It's important to ensure that skill_id is not None. Consider adding a check to handle this situation:

if not skill_id:
    LOG.error("Skill ID is missing. Cannot register intent without a valid skill ID.")
    return

This will prevent unintended behaviors and ensure that each intent is associated with a valid skill.

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)
ovos_padatious/opm.py (1)

117-127: Consider adding validation for engine_class parameter

While the implementation is correct, it would be beneficial to validate that the provided engine_class is a valid PadatiousEngine type.

 self.engine_class = engine_class or IntentContainer
+if not issubclass(self.engine_class, (IntentContainer, DomainIntentContainer)):
+    raise ValueError(f"Invalid engine_class: {engine_class}. Must be IntentContainer or DomainIntentContainer")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02d2aa3 and e103c75.

📒 Files selected for processing (1)
  • ovos_padatious/opm.py (11 hunks)
🔇 Additional comments (7)
ovos_padatious/opm.py (7)

36-36: Correct the import statement for DomainIntentContainer

The import statement is incorrect as noted in previous reviews.

-from ovos_padatious.domain_container import DomainIntentContainer
+from ovos_padatious.domain_engine import DomainIntentContainer

41-43: LGTM! Well-defined type alias.

The PadatiousEngine type alias improves code readability and maintainability by clearly defining the allowed engine types.


Line range hint 98-116: LGTM! Well-implemented engine class selection.

The implementation provides flexibility in engine selection while maintaining backward compatibility through config.


241-246: LGTM! Proper handling of intent removal for both container types.

The implementation correctly differentiates between container types and uses the appropriate removal method.


Line range hint 274-292: LGTM! Well-structured registration logic.

The implementation properly handles both container types and correctly manages skill_id.


304-306: Ensure skill_id is properly obtained and handled

The skill_id handling could be improved to prevent None values.

 skill_id = message.data.get("skill_id") or message.context.get("skill_id")
+if not skill_id:
+    LOG.error("Skill ID is missing. Cannot register intent without a valid skill ID.")
+    return
 self._skill2intent[skill_id].append(message.data['name'])

422-422: LGTM! Accurate type annotation.

The type annotation correctly represents the possible container types.

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