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/OPM Pipeline #2

Merged
merged 2 commits into from
Jul 20, 2024
Merged

feat/OPM Pipeline #2

merged 2 commits into from
Jul 20, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Jul 20, 2024

extracts pipeline from ovos-core into a plugin, now tied to the ovos maintained adapt fork

this opens the doors to continue integrating improvements such as the .excludes keyword

needs OpenVoiceOS/ovos-plugin-manager#242 and OpenVoiceOS/ovos-plugin-manager#241

Summary by CodeRabbit

  • New Features

    • Introduced an intent parsing service for enhanced interaction within the Mycroft AI ecosystem, supporting multi-language intent recognition.
    • Added new methods for managing intents and vocabulary, improving user interaction flexibility and contextual understanding.
  • Chores

    • Updated dependencies to include the latest version of the ovos-plugin-manager, ensuring compatibility with new features.
    • Enhanced package registration with new entry points for better integration within a plugin architecture.

extracts pipeline from ovos-core into a plugin, now tied to the ovos maintained adapt fork

this opens the doors to continue integrating improvements such as the .excludes keyword
@JarbasAl JarbasAl added the enhancement New feature or request label Jul 20, 2024
Copy link

coderabbitai bot commented Jul 20, 2024

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 49 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 as a PR comment. 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.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 8424b3f and ce7f183.

Walkthrough

The recent changes introduce a new intent parsing service in Mycroft AI, enhancing multilingual support with the AdaptPipeline class. This class manages intent recognition through a structured approach, allowing for dynamic registration and detachment of intents and vocabulary. A new dependency has been added for improved plugin management, while updates to the setup.py file facilitate integration within a plugin architecture, broadening the system's extensibility.

Changes

Files Change Summary
ovos_adapt/opm.py Implemented AdaptPipeline class for intent parsing; added methods for intent management and thread safety.
requirements.txt Added ovos-plugin-manager>=0.0.26a32 dependency for enhanced functionality.
setup.py Introduced PLUGIN_ENTRY_POINT for plugin architecture integration; updated entry_points.

Poem

🐇 In the meadow, intentions bloom,
With words that dance, dispelling gloom.
A pipeline grows, with plugins in tow,
Adapt and learn, let the queries flow.
Celebrate the changes, a joyous leap,
In the world of AI, new dreams we’ll reap! 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@JarbasAl JarbasAl changed the title rename to ovos-adapt to avoid conflicts with original namespace feat/OPM Pipeline Jul 20, 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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bb97ec3 and 8424b3f.

Files selected for processing (3)
  • ovos_adapt/opm.py (1 hunks)
  • requirements.txt (1 hunks)
  • setup.py (4 hunks)
Files skipped from review due to trivial changes (1)
  • requirements.txt
Additional context used
Ruff
ovos_adapt/opm.py

180-180: Use of functools.lru_cache or functools.cache on methods can lead to memory leaks

(B019)


340-340: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

Additional comments not posted (17)
setup.py (2)

35-35: LGTM! Plugin entry point is correctly defined.

The PLUGIN_ENTRY_POINT is defined correctly for the ovos-adapt-pipeline-plugin.


46-46: LGTM! Entry points updated correctly.

The entry_points parameter in setup() is updated correctly to include the new PLUGIN_ENTRY_POINT.

ovos_adapt/opm.py (15)

67-77: LGTM! Deprecation handling is correct.

The property context_keywords is correctly marked as deprecated, and appropriate warnings are logged when accessed.


79-88: LGTM! Deprecation handling is correct.

The property context_max_frames is correctly marked as deprecated, and appropriate warnings are logged when accessed.


90-98: LGTM! Deprecation handling is correct.

The property context_timeout is correctly marked as deprecated, and appropriate warnings are logged when accessed.


100-109: LGTM! Deprecation handling is correct.

The property context_greedy is correctly marked as deprecated, and appropriate warnings are logged when accessed.


111-122: LGTM! Deprecation handling is correct.

The property context_manager is correctly marked as deprecated, and appropriate warnings are logged when accessed.


123-137: LGTM! Deprecation handling is correct.

The method update_context is correctly marked as deprecated, and appropriate warnings are logged when called.


138-150: LGTM! High confidence intent matching logic is correct.

The method match_high correctly matches intents with high confidence.

Verify confidence threshold.

Ensure that the confidence threshold self.conf_high is appropriate for your use case.


152-164: LGTM! Medium confidence intent matching logic is correct.

The method match_medium correctly matches intents with medium confidence.

Verify confidence threshold.

Ensure that the confidence threshold self.conf_med is appropriate for your use case.


166-178: LGTM! Low confidence intent matching logic is correct.

The method match_low correctly matches intents with low confidence.

Verify confidence threshold.

Ensure that the confidence threshold self.conf_low is appropriate for your use case.


259-267: LGTM! Deprecation handling is correct.

The method register_vocab is correctly marked as deprecated and calls register_vocabulary instead.


269-289: LGTM! Vocabulary registration logic is correct.

The method register_vocabulary correctly registers skill vocabulary as adapt entities.

Verify locking mechanism.

Ensure that the locking mechanism is appropriate and there are no potential race conditions.


290-298: LGTM! Intent registration logic is correct.

The method register_intent correctly registers new intents with the adapt engine.

Verify locking mechanism.

Ensure that the locking mechanism is appropriate and there are no potential race conditions.


300-315: LGTM! Skill detachment logic is correct.

The method detach_skill correctly removes all intents for a skill and detaches related keywords and regexes.

Verify locking mechanism.

Ensure that the locking mechanism is appropriate and there are no potential race conditions.


345-355: LGTM! Intent detachment logic is correct.

The method detach_intent correctly detaches a single intent.


357-360: LGTM! Shutdown logic is correct.

The method shutdown correctly drops all intent parsers for all languages.

ovos_adapt/opm.py Show resolved Hide resolved
Comment on lines +180 to +258
@lru_cache(maxsize=3) # NOTE - message is a string because of this
def match_intent(self, utterances: Tuple[str],
lang: Optional[str] = None,
message: Optional[str] = None):
"""Run the Adapt engine to search for an matching intent.

Args:
utterances (iterable): utterances for consideration in intent
matching. As a practical matter, a single utterance will
be passed in most cases. But there are instances, such as
streaming STT that could pass multiple. Each utterance is
represented as a tuple containing the raw, normalized, and
possibly other variations of the utterance.
limit (float): confidence threshold for intent matching
lang (str): language to use for intent matching
message (Message): message to use for context

Returns:
Intent structure, or None if no match was found.
"""

if message:
message = Message.deserialize(message)
sess = SessionManager.get(message)

# we call flatten in case someone is sending the old style list of tuples
utterances = flatten_list(utterances)

utterances = [u for u in utterances if len(u.split()) < self.max_words]
if not utterances:
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping adapt match")
return None

lang = lang or self.lang
if lang not in self.engines:
return None

best_intent = {}

def take_best(intent, utt):
nonlocal best_intent
best = best_intent.get('confidence', 0.0) if best_intent else 0.0
conf = intent.get('confidence', 0.0)
skill = intent['intent_type'].split(":")[0]
if best < conf and intent["intent_type"] not in sess.blacklisted_intents \
and skill not in sess.blacklisted_skills:
best_intent = intent
# TODO - Shouldn't Adapt do this?
best_intent['utterance'] = utt

for utt in utterances:
try:
intents = [i for i in self.engines[lang].determine_intent(
utt, 100,
include_tags=True,
context_manager=sess.context)]
if intents:
utt_best = max(
intents, key=lambda x: x.get('confidence', 0.0)
)
take_best(utt_best, utt)

except Exception as err:
LOG.exception(err)

if best_intent:
ents = [tag['entities'][0] for tag in best_intent['__tags__'] if 'entities' in tag]

sess.context.update_context(ents)

skill_id = best_intent['intent_type'].split(":")[0]
ret = IntentMatch(
'Adapt', best_intent['intent_type'], best_intent, skill_id,
best_intent['utterance']
)
else:
ret = None
return ret

Copy link

Choose a reason for hiding this comment

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

LGTM! Intent matching logic is correct.

The method match_intent correctly matches intents using the Adapt engine.

Potential memory leak issue.

The use of lru_cache on methods can lead to memory leaks. Consider using a different caching strategy.

Tools
Ruff

180-180: Use of functools.lru_cache or functools.cache on methods can lead to memory leaks

(B019)

ovos_adapt/opm.py Show resolved Hide resolved
ovos_adapt/opm.py Show resolved Hide resolved
@JarbasAl JarbasAl merged commit 09ef431 into dev Jul 20, 2024
@JarbasAl JarbasAl deleted the feat/opm_pipeline branch July 20, 2024 17:22
This was referenced Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant