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:binary handlers #33

Merged
merged 1 commit into from
Oct 30, 2024
Merged

feat:binary handlers #33

merged 1 commit into from
Oct 30, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Oct 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced enhanced handling for binary messages, including specific callbacks for TTS audio and file messages.
    • Added support for additional binary payload types in message processing.
  • Improvements

    • Enhanced the HiveMessage class to include optional metadata, allowing for more flexible message handling.
    • Updated message serialization to ensure proper inclusion of metadata and binary type information.
  • Bug Fixes

    • Improved error handling for unrecognized binary message types with appropriate logging.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

This pull request introduces significant enhancements to the HiveMessageBusClient and HiveMessage classes within the hivemind_bus_client module. A new class, BinaryDataCallbacks, is added to handle binary TTS audio and file messages. The HiveMessageBusClient constructor is updated to accept this new class for processing binary data. Additionally, the HiveMessage class is modified to include a metadata parameter, enhancing message handling capabilities. Changes also affect the serialization process, ensuring that the new metadata and binary type are correctly incorporated into HiveMessage instances.

Changes

File Path Change Summary
hivemind_bus_client/client.py - Added BinaryDataCallbacks class with methods handle_receive_tts and handle_receive_file.
- Updated HiveMessageBusClient constructor to include bin_callbacks.
- Added _handle_binary method for processing binary messages.
hivemind_bus_client/message.py - Expanded HiveMindBinaryPayloadType with new values: STT_AUDIO_TRANSCRIBE, STT_AUDIO_HANDLE, TTS_AUDIO.
- Updated HiveMessage constructor to include metadata.
- Added metadata property and modified as_dict and deserialize methods to handle metadata.
hivemind_bus_client/serialization.py - Modified _decode_bitstring_v1 to include metadata and bin_type in HiveMessage construction.

Possibly related PRs

  • fix:binary payloads #30: The changes in this PR enhance the HiveMessageBusClient class to handle binary payloads, which is directly related to the new binary data handling introduced in the main PR, particularly the modifications to the emit method and the handling of binary message types.

Poem

In the hive where messages flow,
New callbacks help them grow.
With TTS and files in sight,
Metadata shines, oh what a delight!
Bunnies hop with joy and cheer,
For binary magic is finally here! 🐇✨


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
Contributor

@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: 7

🧹 Outside diff range and nitpick comments (1)
hivemind_bus_client/serialization.py (1)

124-125: Consider adding type hints and documentation for binary message handling.

Since this is part of a new binary handlers feature, it would be helpful to:

  1. Add type hints to improve IDE support and code clarity
  2. Add a docstring explaining the binary message handling process

Example improvement:

-def _decode_bitstring_v1(s):
+def _decode_bitstring_v1(s: BitStream) -> HiveMessage:
+    """Decode a bitstring into a HiveMessage, with special handling for binary payloads.
+    
+    Args:
+        s: BitStream containing the encoded message
+        
+    Returns:
+        HiveMessage: Decoded message with metadata and binary type for binary messages
+    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 35f4f02 and 665ec45.

📒 Files selected for processing (3)
  • hivemind_bus_client/client.py (4 hunks)
  • hivemind_bus_client/message.py (8 hunks)
  • hivemind_bus_client/serialization.py (1 hunks)
🧰 Additional context used
🪛 Ruff
hivemind_bus_client/client.py

104-104: Do not perform function call BinaryDataCallbacks in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


306-306: Do not use bare except

(E722)


312-312: Do not use bare except

(E722)

hivemind_bus_client/message.py

193-193: Do not use bare except

(E722)

🔇 Additional comments (6)
hivemind_bus_client/serialization.py (1)

124-125: LGTM! Explicit parameter naming improves clarity.

The change to use explicit parameter names (metadata=meta, bin_type=bin_type) instead of kwargs improves code clarity and maintainability.

Let's verify the metadata handling across the codebase:

✅ Verification successful

Metadata handling is consistent across the codebase

The explicit parameter naming in _decode_bitstring_v1 aligns with the established metadata handling pattern throughout the codebase:

  • HiveMessage class properly initializes metadata with an optional dictionary parameter
  • Metadata is consistently accessed via the metadata property
  • All deserialization methods handle metadata consistently with default empty dict
  • Binary message types (TTS_AUDIO, FILE) correctly utilize metadata for additional parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check metadata usage in HiveMessage construction and related classes

# Search for HiveMessage instantiations to verify consistent metadata handling
ast-grep --pattern 'HiveMessage($$$)'

# Check for any metadata processing in related files
rg -l "metadata" --type python

Length of output: 4742


Script:

#!/bin/bash
# Let's verify metadata handling with proper file type
rg -t py "metadata" -A 2 -B 2

# Check HiveMessage class definition to understand metadata parameter
ast-grep --pattern 'class HiveMessage:
  $$$'

Length of output: 20231

hivemind_bus_client/message.py (4)

39-41: LGTM: Well-documented binary payload types.

The new enum values for STT and TTS audio handling are clearly documented and follow a logical progression from existing values.


53-54: LGTM: Safe metadata handling in constructor.

The metadata parameter is properly typed and safely initialized with a default empty dict.

Also applies to: 66-66


157-157: LGTM: Proper metadata serialization.

The metadata field is correctly included in the dictionary representation.


39-41: Verify binary message handling implementation.

Let's verify the usage of new binary types and metadata across the codebase to ensure consistent implementation.

Also applies to: 53-54

✅ Verification successful

Binary message types and metadata handling are properly implemented

The verification shows consistent implementation:

  • Binary types (STT_AUDIO_TRANSCRIBE, STT_AUDIO_HANDLE, TTS_AUDIO) are properly defined and used in message handling
  • TTS_AUDIO type is correctly handled in client.py with appropriate metadata extraction (lang, utterance)
  • Metadata is consistently extracted with proper default value ({}) across message construction
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of new binary types
echo "Checking STT/TTS binary type usage:"
rg "STT_AUDIO_TRANSCRIBE|STT_AUDIO_HANDLE|TTS_AUDIO" -A 2

echo -e "\nChecking metadata usage in message handling:"
rg "metadata.*=.*payload\.get\(['\"]metadata['\"]" -A 2

Length of output: 1931

hivemind_bus_client/client.py (1)

286-286: Avoid redundant check for "ciphertext" in message.

The condition if isinstance(message, dict) and "ciphertext" in message: is redundant because earlier in the on_message method, messages containing "ciphertext" are already decrypted. If decryption fails, the message would not reach this point as a dictionary. Consider removing this block or handling it differently.

Please verify if this check is necessary, or if it can be safely removed to avoid confusion.

hivemind_bus_client/message.py Show resolved Hide resolved
hivemind_bus_client/message.py Show resolved Hide resolved
hivemind_bus_client/client.py Show resolved Hide resolved
hivemind_bus_client/client.py Show resolved Hide resolved
hivemind_bus_client/client.py Show resolved Hide resolved
hivemind_bus_client/client.py Show resolved Hide resolved
hivemind_bus_client/client.py Show resolved Hide resolved
@JarbasAl JarbasAl merged commit 7e58b13 into dev Oct 30, 2024
3 checks passed
@JarbasAl JarbasAl deleted the feat/bin branch October 30, 2024 13:57
JarbasAl added a commit to JarbasHiveMind/ZZZ-HiveMind-core that referenced this pull request Oct 30, 2024
* feat:binary handlers

companion to JarbasHiveMind/hivemind-websocket-client#33

* requirements.txt
JarbasAl added a commit to JarbasHiveMind/hivemind-audio-binary-protocol that referenced this pull request Oct 30, 2024
JarbasAl added a commit to JarbasHiveMind/hivemind-mic-satellite that referenced this pull request Oct 30, 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