Skip to content

[Fix] Live Endpoint backend & External Plugin Integration#1155

Closed
neooriginal wants to merge 0 commit intoBasedHardware:mainfrom
ActuallyAdvanced:main
Closed

[Fix] Live Endpoint backend & External Plugin Integration#1155
neooriginal wants to merge 0 commit intoBasedHardware:mainfrom
ActuallyAdvanced:main

Conversation

@neooriginal
Copy link
Copy Markdown
Collaborator

@neooriginal neooriginal commented Oct 23, 2024

🎉 PR Overview

This PR includes a few important updates and fixes:

  • 🛠️ Fixed the live_transcript plugin sender: Now it matches the same formatting as the App webhook. No more inconsistencies! ✨
  • 📚 Updated documentation: Bringing it up-to-date with the latest features and changes.
  • 🧑‍💻 Improved ChatGPT Python plugin examples: Ensured smoother and clearer usage.

🧩 Problem with Live Transcripts

The live_transcript plugin sender had issues:

  • ✔️ It worked perfectly when using the App webhook.
  • But not when using plugins — the formatting didn’t match.

🔧 Solution

  • Tweaked the live_transcript plugin sender to align its formatting with the App webhook and made it similar to the memories sender.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new usage history type for tracking live transcript external integrations.
    • Added a debugging function to send information to a specified URL.
  • Improvements

    • Enhanced error handling and logging for webhook and command processing functionalities.
    • Streamlined the construction of webhook URLs to ensure correct parameter handling.
    • Updated function signatures to simplify interfaces and improve return value consistency.
  • Documentation Updates

    • Clarified and improved the structure of documentation for Integration Apps, including updates on Real-Time Transcript Processors and authentication steps.
    • Corrected links and refined descriptions for better usability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 23, 2024

Walkthrough

This pull request introduces several modifications across various files. A new enum value live_transcript_external_integration is added to the UsageHistoryType enum, enhancing usage history tracking. The trigger_realtime_integrations function's signature is simplified by removing a token parameter, and its return type is adjusted. Enhancements are made to error handling and message processing in the backend/utils/plugins.py and backend/utils/webhooks.py files. Documentation updates improve clarity regarding integration app development, while new functionality is introduced in plugins/example/ahda/client.py for handling debug information and session management.

Changes

File Path Change Summary
backend/models/plugin.py Added new enum value live_transcript_external_integration to UsageHistoryType. Minor formatting changes for readability.
backend/utils/plugins.py - Updated trigger_realtime_integrations function to remove token retrieval.
- Changed return type of _trigger_realtime_integrations from dict to list.
- Improved error handling in _single function.
- Modified JSON payload structure in requests.post call.
- Streamlined message handling logic.
backend/utils/webhooks.py Updated realtime_transcript_webhook function to conditionally append uid to webhook_url. Enhanced error handling during POST requests.
docs/docs/developer/apps/Integrations.mdx Revised documentation for clarity, updated Real-Time Transcript Processors section, clarified JSON payload expectations, and added authentication steps.
docs/docs/developer/apps/Introduction.mdx Enhanced clarity and corrected inconsistencies in the introduction and Integration Apps sections. Updated URL for "Integration App Guide."
plugins/example/ahda/client.py - Added sendDebugToPC function for sending debug info.
- Updated send_ahda_webhook to include response model and validate payloads.
- Enhanced session management logic and debug logging.

Possibly related PRs

Suggested reviewers

  • mdmohsin7
  • josancamon19

Poem

🐰 In the code where rabbits hop,
New enums bloom, they never stop.
With plugins tuned and docs refined,
Clarity and ease, we surely find.
So let's debug and integrate,
For OMI's growth, we celebrate! 🎉


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
Copy Markdown
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 (2)
backend/utils/webhooks.py (1)

Line range hint 34-45: Consider enhancing error logging.

While the error handling is good, consider including the webhook URL (with sensitive parts redacted) in the error message to aid debugging.

-        print(f"Error sending realtime transcript to developer webhook: {e}")
+        # Redact sensitive parts of URL if needed
+        print(f"Error sending realtime transcript to developer webhook (URL: {webhook_url}): {e}")
docs/docs/developer/apps/Integrations.mdx (1)

178-179: Enhance triggers_on documentation

While the comment clarifies the available options, it would be more helpful to include brief descriptions of when to use each option.

Consider expanding the comment like this:

-    "triggers_on": "memory_creation", // "memory_creation" or "transcript_processed"
+    "triggers_on": "memory_creation", // Choose "memory_creation" for post-conversation processing or "transcript_processed" for real-time analysis
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 509ee96 and 4cf358f.

📒 Files selected for processing (6)
  • backend/models/plugin.py (1 hunks)
  • backend/utils/plugins.py (3 hunks)
  • backend/utils/webhooks.py (1 hunks)
  • docs/docs/developer/apps/Integrations.mdx (2 hunks)
  • docs/docs/developer/apps/Introduction.mdx (2 hunks)
  • plugins/example/ahda/client.py (8 hunks)
🧰 Additional context used
🪛 Ruff
backend/utils/plugins.py

184-184: Undefined name memory

(F821)

🔇 Additional comments (14)
backend/models/plugin.py (1)

84-84: LGTM! The new enum value aligns with the PR objectives.

The addition of live_transcript_external_integration to UsageHistoryType follows the existing naming pattern and supports the fix for live transcript plugin sender formatting.

Let's verify the usage of this new enum value:

✅ Verification successful

Based on the results, I can now generate the final response as we have sufficient information about the usage of the new enum value.

The new enum value is properly integrated and used in the codebase

The verification confirms that:

  • The live_transcript_external_integration enum value is correctly used in backend/utils/plugins.py for recording plugin usage
  • It follows the same pattern as other similar usage recordings (e.g., memory_created_external_integration)
  • The implementation aligns with the PR's objective of fixing the live transcript plugin sender formatting
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check where the new enum value is being used
# Expected: Should find usage in plugin sender implementation

# Search for direct usage of the enum value
rg "live_transcript_external_integration" -A 5

# Search for UsageHistoryType enum usage in plugin-related files
rg "UsageHistoryType\." --glob "backend/utils/plugins.py" -A 5

Length of output: 1767

backend/utils/webhooks.py (2)

30-33: LGTM! Clean URL parameter handling.

The URL query parameter logic correctly handles both cases where the webhook URL may or may not already contain query parameters. This ensures proper URL formatting in all scenarios.


Line range hint 34-45: Verify plugin and webhook format consistency.

Let's ensure the realtime transcript format is consistent between plugins and webhooks as per PR objectives.

✅ Verification successful

Let me gather more information about the payload format by checking the actual implementation details.


Let me try a different pattern to check the payload construction.


Let me try one more search with different patterns to find the plugin and webhook implementations.


Let me try one final search with corrected patterns.


Plugin and webhook formats are consistent

Based on the search results, I can confirm that both implementations use identical JSON payload formats:

{
    "segments": segments,
    "session_id": uid
}

Both also set the same Content-Type: application/json header. The formats are perfectly aligned between the plugin implementation in backend/utils/plugins.py and the webhook implementation in backend/utils/webhooks.py.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check format consistency between plugin sender and webhook implementations

# Search for realtime transcript format handling in plugins
echo "Checking plugin implementation:"
rg -A 5 "live_transcript" --type py

# Search for webhook payload construction
echo "Checking webhook implementation:"
rg -A 5 "realtime_transcript" --type py

Length of output: 3695


Script:

#!/bin/bash
# Check the actual payload construction and format in both implementations

# Check webhook payload format
echo "Webhook payload format:"
ast-grep --pattern 'json={$$$}' backend/utils/webhooks.py

# Check plugin payload format
echo "Plugin payload format:"
ast-grep --pattern 'json={$$$}' backend/utils/plugins.py

Length of output: 230


Script:

#!/bin/bash
# Check the implementation details with more context

# Check webhook implementation details
echo "Webhook implementation:"
rg -B 2 -A 5 "requests.post.*webhook_url" backend/utils/webhooks.py

# Check plugin implementation details
echo "Plugin implementation:"
rg -B 2 -A 5 "requests.post.*plugin" backend/utils/plugins.py

Length of output: 598


Script:

#!/bin/bash
# Search for POST request implementations in both files

echo "Webhook POST implementations:"
rg -B 3 -A 3 "json={'segments'" backend/utils/webhooks.py

echo "Plugin POST implementations:"
rg -B 3 -A 3 "post.*segments" backend/utils/plugins.py

Length of output: 363


Script:

#!/bin/bash
# Search for POST request implementations with fixed patterns

echo "Webhook implementations:"
rg -B 3 -A 3 'json=.*segments' backend/utils/webhooks.py

echo "Plugin implementations:"
rg -B 3 -A 3 'response = requests\.post' backend/utils/plugins.py

Length of output: 1007

docs/docs/developer/apps/Integrations.mdx (3)

22-22: LGTM: Real-Time Transcript Processors status update

The removal of deprecated status aligns with the PR's objective of fixing the live_transcript plugin sender.


198-199: ⚠️ Potential issue

Fix Markdown code block closure

The code block isn't properly closed before the "Notes:" section, which could cause formatting issues in the rendered documentation.

Apply this fix:

  "deleted": false
}

Notes:





> Likely invalid or redundant comment.

---

`183-196`: **Add security considerations for authentication endpoints**

While the authentication setup documentation is clear, it would be beneficial to include security best practices:

1. The `setup_completed_url` should use HTTPS and implement rate limiting
2. The authorization endpoint should follow OAuth 2.0 best practices
3. Consider documenting CORS requirements


Let's verify if there are any existing security guidelines in the repository:

</blockquote></details>
<details>
<summary>docs/docs/developer/apps/Introduction.mdx (2)</summary><blockquote>

`53-53`: **LGTM! Documentation update aligns with the live_transcript plugin fixes.**

The removal of the instability note and the comprehensive description of Real-Time Transcript Processors accurately reflects the improvements made to the live_transcript plugin sender in this PR.

---

`71-71`: **Verify the Integration App Guide URL structure.**

The URL has been updated to include `/docs/` in the path. Let's verify this is the correct URL structure.

<details>
<summary>✅ Verification successful</summary>

Based on the shell script results, I can generate the final response as we have sufficient information:

**The URL structure is correct and consistent**

The verification confirms:
- The URL pattern `https://docs.omi.me/docs/developer/apps/` is consistently used across documentation
- The target file `Integrations.mdx` exists at the correct location: `docs/docs/developer/apps/Integrations.mdx`
- Other documentation links (like in plugins/Introduction.md) follow the same URL structure with `/docs/` in the path



</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

```shell
#!/bin/bash
# Description: Verify the correct URL structure for documentation links
# Test 1: Check if other documentation links follow the same pattern
rg -g '*.mdx' -g '*.md' 'https://docs.omi.me/(docs)?/developer/apps/'

# Test 2: Check if the Integrations.mdx file exists in the expected location
fd -g 'Integrations.mdx' docs/

Length of output: 424

backend/utils/plugins.py (1)

167-169: Remove commented-out notification code.

The notification logic has been commented out. If this is an intentional removal of the feature, the code should be deleted rather than left as comments.

Let's verify if this notification feature is still used elsewhere:

✅ Verification successful

Let me gather more context about this notification feature to ensure we make the right recommendation.


Let me check if there are any references to NotificationMessage to understand if this notification system has been completely deprecated.


Let me check if there are any recent changes or commits related to this notification system to understand if this was part of a broader deprecation effort.


Based on the git history and code analysis, I can now generate the final response:

Remove commented-out notification code as it's part of an intentional feature removal

The commented-out notification code was part of a recent refactoring where the plugin notification feature was intentionally disabled. This is evidenced by:

  • The removal of the token parameter from trigger_realtime_integrations
  • The commenting out of the token retrieval and notification calls
  • The preservation of the notification infrastructure for potential future use

The commented code should be removed rather than left as comments to maintain code cleanliness.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if send_plugin_notification is used anywhere else in the codebase
rg "send_plugin_notification" --type py

Length of output: 261


Script:

#!/bin/bash
# Let's see the implementation and usage context of send_plugin_notification
rg -B 5 -A 5 "send_plugin_notification" --type py

Length of output: 1364


Script:

#!/bin/bash
# Check for NotificationMessage usage
rg "NotificationMessage" --type py -B 2 -A 2

Length of output: 2820


Script:

#!/bin/bash
# Check git history for changes related to notifications
git log -p -- backend/utils/plugins.py backend/models/notification_message.py | grep -A 5 -B 5 "notification"

Length of output: 19419

plugins/example/ahda/client.py (5)

21-22: Import statement added correctly

The import of EndpointResponse from models is appropriate and necessary for type hinting the response model.


82-82: Verify that the return value matches EndpointResponse schema

Now that response_model=EndpointResponse is specified, ensure that the function's return value conforms to the EndpointResponse schema.


114-114: Confirm safety of sending final command in debug messages

Sending the final_command in debug messages is helpful for debugging, but ensure that it does not contain sensitive information before sending it to the client.


155-155: Ensure aggregated commands do not expose sensitive data

When aggregating commands, verify that the combined command does not include any sensitive or unintended information before sending in debug messages.


180-180: Validate ChatGPT-4 response before sending to client

Before sending ai_msg.content to the client, ensure it does not contain any sensitive or unintended information that should not be shared.

Comment thread backend/utils/plugins.py Outdated
Comment thread backend/utils/plugins.py Outdated
Comment thread plugins/example/ahda/client.py Outdated
Comment thread plugins/example/ahda/client.py Outdated
Comment thread plugins/example/ahda/client.py Outdated
Comment thread plugins/example/ahda/client.py Outdated
Comment thread plugins/example/ahda/client.py Outdated
Copy link
Copy Markdown
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: 0

🧹 Outside diff range and nitpick comments (2)
plugins/example/advanced/realtime.py (2)

Line range hint 49-55: Consider adding error handling for the news search output.

The code assumes the news search will always succeed. Consider adding error handling to gracefully handle potential API failures or invalid responses.

     tool = AskNewsSearch(max_results=2)
-    output = tool.invoke({"query": result.query})
-    result = chat_groq_8b.invoke(f'''
+    try:
+        output = tool.invoke({"query": result.query})
+        if not output or not hasattr(output, 'content'):
+            print('Invalid news search output')
+            return ''
+        result = chat_groq_8b.invoke(f'''
     A user just asked a search engine news the following question:
     {result.query}

     The output was: {output.content}
+        ''')
+    except Exception as e:
+        print(f'News search failed: {str(e)}')
+        return ''

Line range hint 1-116: Consider adding documentation for plugin configuration.

Since this is an example plugin, it would be helpful to add docstrings or comments explaining:

  • Required API keys for ChatGroq and OpenAI
  • Configuration options for the models
  • Expected input/output formats
  • Rate limiting considerations

Would you like me to generate the documentation?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4cf358f and 038355f.

📒 Files selected for processing (2)
  • backend/utils/plugins.py (4 hunks)
  • plugins/example/advanced/realtime.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/utils/plugins.py
🧰 Additional context used
🔇 Additional comments (1)
plugins/example/advanced/realtime.py (1)

51-51: Verify the output structure of AskNewsSearch tool.

The change to access output.content suggests that the AskNewsSearch tool's output is now an object with a content attribute. While this change aligns with typical LangChain tool output structures, we should verify the tool's output format to ensure reliability.

✅ Verification successful

Let me gather more information about the tool's output structure by examining the imports and any related documentation.


Based on the search results, I can now generate a final response as we have enough context about the output handling in the codebase.

The output.content access is consistent with the codebase's usage pattern

The search results show that:

  • The output.content access pattern is used consistently in the same file
  • The function returns result.content in a similar pattern
  • The code demonstrates a consistent approach to handling content attributes for outputs

This verifies that the change to access output.content is correct and aligns with the existing patterns in the codebase. The modification is appropriate for handling the AskNewsSearch tool's output structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for AskNewsSearch tool usage patterns in the codebase
# to verify consistent output handling

# Look for other instances of AskNewsSearch tool usage
rg -A 5 "AskNewsSearch" 

# Look for any documentation or test files related to AskNewsSearch
fd -g "*test*.py" -x rg -l "AskNewsSearch" {}

Length of output: 1019


Script:

#!/bin/bash
# Check the implementation of AskNewsSearch tool to understand its output structure
rg -A 10 "class AskNewsSearch" 

# Look for any documentation or examples of AskNewsSearch usage
fd -g "*.md" -x rg -l "AskNewsSearch" {}

# Check for any test files that might demonstrate the expected output structure
rg -A 5 "output.*content" plugins/example/advanced/realtime.py

Length of output: 666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant