-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
WalkthroughThis pull request introduces significant enhancements to the Changes
Possibly related PRs
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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:
- Add type hints to improve IDE support and code clarity
- 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
📒 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.
* feat:binary handlers companion to JarbasHiveMind/hivemind-websocket-client#33 * requirements.txt
* feat:binary handlers companion to JarbasHiveMind/hivemind-websocket-client#33 and https://github.com/JarbasHiveMind/HiveMind-core/pull/100 * requirements.txt
* feat:binary handlers companion to JarbasHiveMind/hivemind-websocket-client#33 and https://github.com/JarbasHiveMind/HiveMind-core/pull/100 and JarbasHiveMind/hivemind-audio-binary-protocol#1 * requirements.txt
Summary by CodeRabbit
New Features
Improvements
HiveMessage
class to include optional metadata, allowing for more flexible message handling.Bug Fixes