Active User & Configuring Model & voice from Query Strings #7

Merged
russellballestrini merged 9 commits from user-list into main 2024-11-23 12:18:17 -05:00
russellballestrini commented 2024-11-22 16:31:07 -05:00 (Migrated from git2.unturf.com)

Created by: russellballestrini

modified:   templates/base.html
modified:   templates/chat.html

Summary by CodeRabbit

  • New Features

    • Updated layout and styling for improved user interface in the chat application.
    • Redesigned presentation of download links for chat history, now labeled as "History."
    • Introduced dropdowns for selecting a model and a voice.
    • Added a section for displaying active users.
    • Enhanced message sending functionality to include selected model in messages.
    • Improved feedback mechanism by signaling message processing completion.
  • Bug Fixes

    • Adjusted padding and grid layout for better visual organization of chat elements.
    • Enhanced dynamic management of active users in chat rooms.
    • Streamlined user session tracking and management.
*Created by: russellballestrini* modified: templates/base.html modified: templates/chat.html <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Updated layout and styling for improved user interface in the chat application. - Redesigned presentation of download links for chat history, now labeled as "History." - Introduced dropdowns for selecting a model and a voice. - Added a section for displaying active users. - Enhanced message sending functionality to include selected model in messages. - Improved feedback mechanism by signaling message processing completion. - **Bug Fixes** - Adjusted padding and grid layout for better visual organization of chat elements. - Enhanced dynamic management of active users in chat rooms. - Streamlined user session tracking and management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
russellballestrini commented 2024-11-22 16:31:14 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Walkthrough

The changes involve modifications to the base.html and chat.html templates, focusing on layout and style adjustments. In base.html, padding for the chat element has been altered, and the grid layout has been updated to create a new column distribution. The .download-links class has been restructured for a more centered appearance. In chat.html, the structure of the download links has been revised, replacing the previous block with a new layout under the label "History," while maintaining the same functionality. Additionally, the Flask application has switched its SocketIO async mode to "gevent," enhancing message processing feedback and user management.

Changes

File Change Summary
templates/base.html Adjusted padding for #chat; updated .main-container grid layout from 20% 80% to 15% 70% 15%; modified .download-links for centered text alignment and added .utility-belt class.
templates/chat.html Removed old <div class="download-links">; replaced with a new <div class="utility-belt"> under the label "History"; added dropdowns for model and voice selection, and a section for active users.
app.py Changed SocketIO async mode from "eventlet" to "gevent"; added is_complete flag in message emissions; removed commented-out eventlet code; updated method signatures for chat functions; added methods to manage active users and user sessions.
migrations/versions/38a330686a17_room_active_users.py Introduced active_users column in the room table; added upgrade and downgrade functions for the migration.
migrations/versions/1ac5a8e0f577_user_session_table.py Created user_session table with columns for session management; included upgrade and downgrade functions for the migration.

Poem

In the chat where bunnies play,
Layouts shift in a charming way.
Links now dance with centered grace,
A cozy spot, a friendly space.
With every hop, the style's anew,
Hooray for changes, bright and true! 🐇


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.
*Created by: coderabbitai[bot]* <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The changes involve modifications to the `base.html` and `chat.html` templates, focusing on layout and style adjustments. In `base.html`, padding for the chat element has been altered, and the grid layout has been updated to create a new column distribution. The `.download-links` class has been restructured for a more centered appearance. In `chat.html`, the structure of the download links has been revised, replacing the previous block with a new layout under the label "History," while maintaining the same functionality. Additionally, the Flask application has switched its SocketIO async mode to "gevent," enhancing message processing feedback and user management. ## Changes | File | Change Summary | |---------------------------------------|-----------------------------------------------------------------------------------------------------| | templates/base.html | Adjusted padding for `#chat`; updated `.main-container` grid layout from `20% 80%` to `15% 70% 15%`; modified `.download-links` for centered text alignment and added `.utility-belt` class. | | templates/chat.html | Removed old `<div class="download-links">`; replaced with a new `<div class="utility-belt">` under the label "History"; added dropdowns for model and voice selection, and a section for active users. | | app.py | Changed SocketIO async mode from "eventlet" to "gevent"; added `is_complete` flag in message emissions; removed commented-out eventlet code; updated method signatures for chat functions; added methods to manage active users and user sessions. | | migrations/versions/38a330686a17_room_active_users.py | Introduced `active_users` column in the `room` table; added upgrade and downgrade functions for the migration. | | migrations/versions/1ac5a8e0f577_user_session_table.py | Created `user_session` table with columns for session management; included upgrade and downgrade functions for the migration. | ## Poem > In the chat where bunnies play, > Layouts shift in a charming way. > Links now dance with centered grace, > A cozy spot, a friendly space. > With every hop, the style's anew, > Hooray for changes, bright and true! 🐇✨ <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACImQNovEipERhYfZxwAM0IBKkI2aFxkamgfFHxY6AB3DFRkXCFWTTpGBQj4LxKyqhLSvyEMPzDUrEQtaABJcPQ0zkRsxBj67z8A4NDkcKxnITKAdkwsdOxofcwmJllSxlpOr1y/QhrELBJoAFVbABkeAG14Ph8LxkFwAPTgkiaeBNLQsVjgvrIAY+IYjbZjRDgwi8CgI3jRSSELDg3i+Hzgg4AXQAFECQWDIdD8LChPC2Ej+mRBsNopi3tjcfi2ISyMTSeS/FSAJRaDxdaAqZAJRC8CWCbIPNb+QIhMJoE6IJhJVCs+6sZSLY20RAk1A1aheVgYFQRQgRGoepb8ngAAzorEJpvBQ1KWiBrB8fuOjADZCDPhDTHgtAj+CjfsmAAkXmQZFQADTQLDe3BUVllFT4XQ+VCBEiuehvD6V6DIPFMa1MZip96yQQCNvkqi8QilTUPCeW5tLE0S1CuLz8QhSeaMN7a5Wq9V2rDy4CWaAAYTYHCw+FQThcbmMUxwbYR58v7fEGsIWuHFI2+u2xZ6+TcryGL4FiP5bG0mAopU2DXNA2QFKw2pCIQ4R+iwKg0Oomi6DGRDMIkdCYNAHBUOQajRO2uAkOQ2x7vBhBMD0jAknwgQyBeLaGmIEj0VIviUFhiAVJIA6bo+5aBBeSgqJMd44IEHb2mQxbocoqjYTWiAxiua4qIwp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oxQxRMAHBagTpnrQAKJ/zFx/xB9T0YBEvwcHDh/ZDZKVzZLx/srsrB8qCVx/wS9MCVz0AJ/B+p8npK9QDMDR9MBCDZJMB/xCDZBvvXAxR/zR+EtCAS/0Dd/XAKI6bsoQd5/0AHCN+Vwu/p/0BT159CCe8YB+9T0Qe+8xRkBCBT3ZJkCMwS/R9T/srPOb9T2h86ZF89hp/K+Vzb9+9Z8KJvM3/ZK//2YYAKIfC7vAfmXw34YAp6+wIuNcCYBQc1+yvbIFPWyAHAY+DmK4BgA+YMAYOI/A4Pn3f4QDp6y/RmPZm77spR+cAjvq7iEDj0hg2SHTPQDr478VAGAMgAonoCVw9+f8JvnP0QHz8XYjfOPuQJgDZJsgSfZAfZmebiBsgf8N9n/CnoxRsk0gsgOynoFT0l+TAZrIzAwB19z+BwZ/m33T4wd2UjMQlrPx/5v8J6ofbIJXDIC/8mAjMBPhgDdzQddB7KCfk33ZSCCM+rudgeZE36J8i4g/cPn/Hswl9XBmfJgZH2yT2CcBLAg4H/Bd7t8YAlvMCmkFt75hlgjoegMShnSGAgAA== --> <!-- internal state end --> <!-- tips_start --> --- 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? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
russellballestrini commented 2024-11-22 16:32:18 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Review: Commented

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
templates/base.html (1)

115-115: Review the three-column layout distribution

The grid layout has been modified to introduce a third column, with the following changes:

  • Rooms list reduced from 20% to 15%
  • Main content area reduced from 80% to 70%
  • New 15% column added on the right

Consider the following suggestions:

  1. Document the purpose of the new right column in a comment
  2. Consider using CSS custom properties for the column widths to make future adjustments easier:
-        grid-template-columns: 15% 70% 15%;
+        --sidebar-width: 15%;
+        --main-content-width: 70%;
+        grid-template-columns: var(--sidebar-width) var(--main-content-width) var(--sidebar-width);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 46d760cdf5 and 7935a2bbb7178a3013f0b5865682da6a5b811c7f.

📒 Files selected for processing (2)
  • templates/base.html (3 hunks)
  • templates/chat.html (1 hunks)
Files skipped from review due to trivial changes (1)
  • templates/chat.html
🔇 Additional comments (2)
templates/base.html (2)

65-65: Verify the visual impact of reduced padding

The change from padding: 10px; to padding-left: 10px; removes padding from the top, right, and bottom sides of the chat area. Please ensure this doesn't cause content to appear too close to the borders.

Consider using padding on all sides for consistent spacing:

-        padding-left: 10px;
+        padding: 10px 10px 10px 10px;

177-177: LGTM: Simplified download links styling

The change to use text-align: center is a cleaner approach compared to the previous absolute positioning and flex display. This should be more maintainable and less prone to positioning issues.

*Created by: coderabbitai[bot]* **Review:** Commented **Actionable comments posted: 0** <details> <summary>🧹 Outside diff range and nitpick comments (1)</summary><blockquote> <details> <summary>templates/base.html (1)</summary><blockquote> `115-115`: **Review the three-column layout distribution** The grid layout has been modified to introduce a third column, with the following changes: - Rooms list reduced from 20% to 15% - Main content area reduced from 80% to 70% - New 15% column added on the right Consider the following suggestions: 1. Document the purpose of the new right column in a comment 2. Consider using CSS custom properties for the column widths to make future adjustments easier: ```diff - grid-template-columns: 15% 70% 15%; + --sidebar-width: 15%; + --main-content-width: 70%; + grid-template-columns: var(--sidebar-width) var(--main-content-width) var(--sidebar-width); ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 46d760cdf5caad0995adbeca95d8b1aa7cb24827 and 7935a2bbb7178a3013f0b5865682da6a5b811c7f. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `templates/base.html` (3 hunks) * `templates/chat.html` (1 hunks) </details> <details> <summary>✅ Files skipped from review due to trivial changes (1)</summary> * templates/chat.html </details> <details> <summary>🔇 Additional comments (2)</summary> <details> <summary>templates/base.html (2)</summary> `65-65`: **Verify the visual impact of reduced padding** The change from `padding: 10px;` to `padding-left: 10px;` removes padding from the top, right, and bottom sides of the chat area. Please ensure this doesn't cause content to appear too close to the borders. Consider using padding on all sides for consistent spacing: ```diff - padding-left: 10px; + padding: 10px 10px 10px 10px; ``` --- `177-177`: **LGTM: Simplified download links styling** The change to use `text-align: center` is a cleaner approach compared to the previous absolute positioning and flex display. This should be more maintainable and less prone to positioning issues. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
russellballestrini commented 2024-11-23 08:36:49 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

⚠️ Potential issue

Add input validation and improve message formatting.

The current implementation lacks input validation and could be vulnerable to XSS. Also, the model prefix should be clearly separated from the message.

     const model = document.getElementById("model-select").value;
+    // Validate model against known values
+    const validModels = new Set(['None', 'gemini-flash', 'gemini-pro', /* ... */]);
+    if (!validModels.has(model)) {
+        console.error('Invalid model selected');
+        return;
+    }
     let messageToSend = message.trim();

     if (model !== "None") {
-        messageToSend = `${model} ${messageToSend}`;
+        // Use a clear separator and escape any HTML in the model name
+        const escapedModel = model.replace(/[<>]/g, '');
+        messageToSend = `[${escapedModel}] ${messageToSend}`;
     }

Committable suggestion skipped: line range outside the PR's diff.

*Created by: coderabbitai[bot]* _:warning: Potential issue_ **Add input validation and improve message formatting.** The current implementation lacks input validation and could be vulnerable to XSS. Also, the model prefix should be clearly separated from the message. ```diff const model = document.getElementById("model-select").value; + // Validate model against known values + const validModels = new Set(['None', 'gemini-flash', 'gemini-pro', /* ... */]); + if (!validModels.has(model)) { + console.error('Invalid model selected'); + return; + } let messageToSend = message.trim(); if (model !== "None") { - messageToSend = `${model} ${messageToSend}`; + // Use a clear separator and escape any HTML in the model name + const escapedModel = model.replace(/[<>]/g, ''); + messageToSend = `[${escapedModel}] ${messageToSend}`; } ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated reply by CodeRabbit -->
russellballestrini commented 2024-11-23 08:36:49 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Review: Commented

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
templates/chat.html (4)

53-56: Add ARIA attributes for accessibility.

The active users section should include proper ARIA attributes to improve accessibility for screen readers.

-            <h3>Active Users</h3>
-            <ul id="active-users">
+            <h3 id="active-users-heading">Active Users</h3>
+            <ul id="active-users" aria-labelledby="active-users-heading" role="list">

24-39: Group model options by provider for better organization.

The model selector would be more user-friendly with options grouped by provider (OpenAI, Anthropic, etc.).

-            <select id="model-select">
-                <option value="None">None</option>
-                <option value="gemini-flash">gemini-flash</option>
-                <option value="gemini-flash-8b">gemini-flash-8b</option>
-                <option value="gemini-pro">gemini-pro</option>
-                <option value="grok-beta">grok-beta</option>
-                <option value="vllm/hermes-llama-3">vllm/hermes-llama-3</option>
-                <option value="gpt-4">gpt-4</option>
-                <option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option>
-                <option value="gpt-mini">gpt-mini</option>
-                <option value="gpt-o1-mini">gpt-o1-mini</option>
-                <option value="claude-haiku">claude-haiku</option>
-                <option value="claude-sonnet">claude-sonnet</option>
-                <option value="claude-opus">claude-opus</option>
+            <select id="model-select" aria-label="Select AI Model">
+                <option value="None">None</option>
+                <optgroup label="Google">
+                    <option value="gemini-flash">gemini-flash</option>
+                    <option value="gemini-flash-8b">gemini-flash-8b</option>
+                    <option value="gemini-pro">gemini-pro</option>
+                </optgroup>
+                <optgroup label="OpenAI">
+                    <option value="gpt-4">gpt-4</option>
+                    <option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option>
+                    <option value="gpt-mini">gpt-mini</option>
+                    <option value="gpt-o1-mini">gpt-o1-mini</option>
+                </optgroup>
+                <optgroup label="Anthropic">
+                    <option value="claude-haiku">claude-haiku</option>
+                    <option value="claude-sonnet">claude-sonnet</option>
+                    <option value="claude-opus">claude-opus</option>
+                </optgroup>
+                <optgroup label="Other">
+                    <option value="grok-beta">grok-beta</option>
+                    <option value="vllm/hermes-llama-3">vllm/hermes-llama-3</option>
+                </optgroup>

Line range hint 171-213: Improve TTS implementation security and error handling.

Several improvements are needed for the TTS implementation:

  1. The API key should not be hardcoded
  2. Text cleaning is too aggressive
  3. Error handling should be user-friendly
-const API_KEY = "dummy-api-key";
+// API key should be injected from server-side
+const API_KEY = document.querySelector('meta[name="tts-api-key"]').content;

 async function speakText(text, playButton, messageId) {
     const voice = document.getElementById("voice-select").value;
     const cacheKey = `${messageId}-${voice}`;

-    // Clean the text to include only alphanumeric characters, spaces, and key punctuation
-    const cleanText = text.replace(/[^a-zA-Z0-9\s.,!?]/g, '');
+    // Preserve more characters for better TTS quality
+    const cleanText = text.replace(/[<>{}]/g, '');

     try {
         // ... existing code ...
     } catch (error) {
         console.error('Error in TTS:', error);
-        playButton.textContent = "Play";
-        playButton.disabled = false;
+        playButton.textContent = "Error";
+        playButton.disabled = true;
+        // Show error message to user
+        const errorMsg = document.createElement('span');
+        errorMsg.className = 'tts-error';
+        errorMsg.textContent = 'TTS failed. Please try again later.';
+        playButton.parentNode.appendChild(errorMsg);
+        setTimeout(() => {
+            errorMsg.remove();
+            playButton.textContent = "Play";
+            playButton.disabled = false;
+        }, 3000);
     }
 }

Line range hint 404-478: Address potential memory leaks and race conditions.

The message chunk handling implementation has several issues that need attention:

  1. Message buffers are never cleaned up
  2. Race conditions could occur during rapid chunk processing
  3. Event listeners are not properly cleaned up
 const messageBuffers = {};
+const MAX_BUFFER_AGE = 5 * 60 * 1000; // 5 minutes

+// Cleanup old message buffers periodically
+setInterval(() => {
+    const now = Date.now();
+    Object.entries(messageBuffers).forEach(([id, buffer]) => {
+        if (buffer.timestamp < now - MAX_BUFFER_AGE) {
+            delete messageBuffers[id];
+        }
+    });
+}, 60000);

 socket.on("message_chunk", (data) => {
+    // Add timestamp to new buffers
     if (!messageBuffers[data.id]) {
-        messageBuffers[data.id] = "";
+        messageBuffers[data.id] = {
+            content: "",
+            timestamp: Date.now()
+        };
     }

-    messageBuffers[data.id] += data.content;
+    messageBuffers[data.id].content += data.content;

     // ... existing code ...

     if (data.is_complete) {
         // ... existing code ...
+        // Clean up the message buffer
+        delete messageBuffers[data.id];
+        
+        // Clean up old event listeners
+        const oldButtons = messageWrapper.querySelectorAll('button');
+        oldButtons.forEach(button => {
+            button.replaceWith(button.cloneNode(true));
+        });
     }
 });
app.py (1)

1020-1024: LGTM! Consider extracting the completion status emission into a helper function.

The addition of completion status improves the handling of streamed responses. However, this pattern is duplicated across multiple chat functions.

Consider extracting this into a helper function to reduce code duplication:

+def emit_completion_status(msg_id, room_name):
+    socketio.emit(
+        "message_chunk",
+        {"id": msg_id, "content": "", "is_complete": True},
+        room=room_name,
+    )

Then use it in all chat functions:

-    socketio.emit(
-        "message_chunk",
-        {"id": msg_id, "content": "", "is_complete": True},
-        room=room.name,
-    )
+    emit_completion_status(msg_id, room.name)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d99ab35a71 and 3b3714f527.

📒 Files selected for processing (2)
  • app.py (6 hunks)
  • templates/chat.html (7 hunks)
🔇 Additional comments (4)
app.py (4)

1172-1176: Duplicate completion status emission in chat_gpt.

The same completion status emission pattern is used here. Apply the suggested helper function refactor.


1284-1288: Duplicate completion status emission in chat_mistral.

The same completion status emission pattern is used here. Apply the suggested helper function refactor.


1414-1418: Duplicate completion status emission in chat_together.

The same completion status emission pattern is used here. Apply the suggested helper function refactor.


1526-1530: Duplicate completion status emission in chat_groq.

The same completion status emission pattern is used here. Apply the suggested helper function refactor.

*Created by: coderabbitai[bot]* **Review:** Commented **Actionable comments posted: 1** <details> <summary>🧹 Outside diff range and nitpick comments (5)</summary><blockquote> <details> <summary>templates/chat.html (4)</summary><blockquote> `53-56`: **Add ARIA attributes for accessibility.** The active users section should include proper ARIA attributes to improve accessibility for screen readers. ```diff - <h3>Active Users</h3> - <ul id="active-users"> + <h3 id="active-users-heading">Active Users</h3> + <ul id="active-users" aria-labelledby="active-users-heading" role="list"> ``` --- `24-39`: **Group model options by provider for better organization.** The model selector would be more user-friendly with options grouped by provider (OpenAI, Anthropic, etc.). ```diff - <select id="model-select"> - <option value="None">None</option> - <option value="gemini-flash">gemini-flash</option> - <option value="gemini-flash-8b">gemini-flash-8b</option> - <option value="gemini-pro">gemini-pro</option> - <option value="grok-beta">grok-beta</option> - <option value="vllm/hermes-llama-3">vllm/hermes-llama-3</option> - <option value="gpt-4">gpt-4</option> - <option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option> - <option value="gpt-mini">gpt-mini</option> - <option value="gpt-o1-mini">gpt-o1-mini</option> - <option value="claude-haiku">claude-haiku</option> - <option value="claude-sonnet">claude-sonnet</option> - <option value="claude-opus">claude-opus</option> + <select id="model-select" aria-label="Select AI Model"> + <option value="None">None</option> + <optgroup label="Google"> + <option value="gemini-flash">gemini-flash</option> + <option value="gemini-flash-8b">gemini-flash-8b</option> + <option value="gemini-pro">gemini-pro</option> + </optgroup> + <optgroup label="OpenAI"> + <option value="gpt-4">gpt-4</option> + <option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option> + <option value="gpt-mini">gpt-mini</option> + <option value="gpt-o1-mini">gpt-o1-mini</option> + </optgroup> + <optgroup label="Anthropic"> + <option value="claude-haiku">claude-haiku</option> + <option value="claude-sonnet">claude-sonnet</option> + <option value="claude-opus">claude-opus</option> + </optgroup> + <optgroup label="Other"> + <option value="grok-beta">grok-beta</option> + <option value="vllm/hermes-llama-3">vllm/hermes-llama-3</option> + </optgroup> ``` --- Line range hint `171-213`: **Improve TTS implementation security and error handling.** Several improvements are needed for the TTS implementation: 1. The API key should not be hardcoded 2. Text cleaning is too aggressive 3. Error handling should be user-friendly ```diff -const API_KEY = "dummy-api-key"; +// API key should be injected from server-side +const API_KEY = document.querySelector('meta[name="tts-api-key"]').content; async function speakText(text, playButton, messageId) { const voice = document.getElementById("voice-select").value; const cacheKey = `${messageId}-${voice}`; - // Clean the text to include only alphanumeric characters, spaces, and key punctuation - const cleanText = text.replace(/[^a-zA-Z0-9\s.,!?]/g, ''); + // Preserve more characters for better TTS quality + const cleanText = text.replace(/[<>{}]/g, ''); try { // ... existing code ... } catch (error) { console.error('Error in TTS:', error); - playButton.textContent = "Play"; - playButton.disabled = false; + playButton.textContent = "Error"; + playButton.disabled = true; + // Show error message to user + const errorMsg = document.createElement('span'); + errorMsg.className = 'tts-error'; + errorMsg.textContent = 'TTS failed. Please try again later.'; + playButton.parentNode.appendChild(errorMsg); + setTimeout(() => { + errorMsg.remove(); + playButton.textContent = "Play"; + playButton.disabled = false; + }, 3000); } } ``` --- Line range hint `404-478`: **Address potential memory leaks and race conditions.** The message chunk handling implementation has several issues that need attention: 1. Message buffers are never cleaned up 2. Race conditions could occur during rapid chunk processing 3. Event listeners are not properly cleaned up ```diff const messageBuffers = {}; +const MAX_BUFFER_AGE = 5 * 60 * 1000; // 5 minutes +// Cleanup old message buffers periodically +setInterval(() => { + const now = Date.now(); + Object.entries(messageBuffers).forEach(([id, buffer]) => { + if (buffer.timestamp < now - MAX_BUFFER_AGE) { + delete messageBuffers[id]; + } + }); +}, 60000); socket.on("message_chunk", (data) => { + // Add timestamp to new buffers if (!messageBuffers[data.id]) { - messageBuffers[data.id] = ""; + messageBuffers[data.id] = { + content: "", + timestamp: Date.now() + }; } - messageBuffers[data.id] += data.content; + messageBuffers[data.id].content += data.content; // ... existing code ... if (data.is_complete) { // ... existing code ... + // Clean up the message buffer + delete messageBuffers[data.id]; + + // Clean up old event listeners + const oldButtons = messageWrapper.querySelectorAll('button'); + oldButtons.forEach(button => { + button.replaceWith(button.cloneNode(true)); + }); } }); ``` </blockquote></details> <details> <summary>app.py (1)</summary><blockquote> `1020-1024`: **LGTM! Consider extracting the completion status emission into a helper function.** The addition of completion status improves the handling of streamed responses. However, this pattern is duplicated across multiple chat functions. Consider extracting this into a helper function to reduce code duplication: ```diff +def emit_completion_status(msg_id, room_name): + socketio.emit( + "message_chunk", + {"id": msg_id, "content": "", "is_complete": True}, + room=room_name, + ) ``` Then use it in all chat functions: ```diff - socketio.emit( - "message_chunk", - {"id": msg_id, "content": "", "is_complete": True}, - room=room.name, - ) + emit_completion_status(msg_id, room.name) ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d99ab35a7195ab71eb96e2c52ddc87b9990b075c and 3b3714f52787666efa5ee79bf36d9a9beafcec8e. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `app.py` (6 hunks) * `templates/chat.html` (7 hunks) </details> <details> <summary>🔇 Additional comments (4)</summary> <details> <summary>app.py (4)</summary> `1172-1176`: **Duplicate completion status emission in chat_gpt.** The same completion status emission pattern is used here. Apply the suggested helper function refactor. --- `1284-1288`: **Duplicate completion status emission in chat_mistral.** The same completion status emission pattern is used here. Apply the suggested helper function refactor. --- `1414-1418`: **Duplicate completion status emission in chat_together.** The same completion status emission pattern is used here. Apply the suggested helper function refactor. --- `1526-1530`: **Duplicate completion status emission in chat_groq.** The same completion status emission pattern is used here. Apply the suggested helper function refactor. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
russellballestrini commented 2024-11-23 08:55:25 -05:00 (Migrated from git2.unturf.com)

Created by: russellballestrini

@coderabbit None is valid. It means no llm please. Update memory & resolve

*Created by: russellballestrini* @coderabbit None is valid. It means no llm please. Update memory & resolve
russellballestrini commented 2024-11-23 08:55:50 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

@russellballestrini, understood. I've noted that None is a valid model selection and indicates that no LLM should be used. I've updated my memory accordingly. Resolving this comment.


✏️ Learnings added
Learnt from: russellballestrini
PR: russellballestrini/opencompletion#7
File: templates/chat.html:117-122
Timestamp: 2024-11-23T13:55:49.263Z
Learning: In the chat application, selecting `None` as the model means that no LLM should be used.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

*Created by: coderabbitai[bot]* @russellballestrini, understood. I've noted that `None` is a valid model selection and indicates that no LLM should be used. I've updated my memory accordingly. Resolving this comment. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: russellballestrini PR: russellballestrini/opencompletion#7 File: templates/chat.html:117-122 Timestamp: 2024-11-23T13:55:49.263Z Learning: In the chat application, selecting `None` as the model means that no LLM should be used. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> <!-- This is an auto-generated reply by CodeRabbit -->
russellballestrini commented 2024-11-23 09:41:40 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

⚠️ Potential issue

Sanitize usernames before displaying.

The code directly inserts usernames into the DOM without sanitization, which could lead to XSS vulnerabilities if usernames contain malicious HTML/JavaScript.

     for (const username in activeUsers) {
         const userItem = document.createElement("li");
-        userItem.textContent = username;
+        // Sanitize username to prevent XSS
+        userItem.textContent = DOMPurify.sanitize(username);
         userListElement.appendChild(userItem);
     }

Committable suggestion skipped: line range outside the PR's diff.

*Created by: coderabbitai[bot]* _:warning: Potential issue_ **Sanitize usernames before displaying.** The code directly inserts usernames into the DOM without sanitization, which could lead to XSS vulnerabilities if usernames contain malicious HTML/JavaScript. ```diff for (const username in activeUsers) { const userItem = document.createElement("li"); - userItem.textContent = username; + // Sanitize username to prevent XSS + userItem.textContent = DOMPurify.sanitize(username); userListElement.appendChild(userItem); } ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 09:41:40 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

⚠️ Potential issue

Add input validation for model and voice parameters.

The code accepts model and voice values from URL parameters without validation. This could potentially lead to XSS if these values are reflected elsewhere in the UI.

     const modelSelect = document.getElementById("model-select");
     const voiceSelect = document.getElementById("voice-select");
-    const initialModel = urlParams.get("model") || "None";
-    const initialVoice = urlParams.get("voice") || "onyx";
+    // Define valid options
+    const validModels = new Set(Array.from(modelSelect.options).map(opt => opt.value));
+    const validVoices = new Set(Array.from(voiceSelect.options).map(opt => opt.value));
+    
+    // Validate URL parameters
+    const modelParam = urlParams.get("model");
+    const voiceParam = urlParams.get("voice");
+    const initialModel = validModels.has(modelParam) ? modelParam : "None";
+    const initialVoice = validVoices.has(voiceParam) ? voiceParam : "onyx";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    // Set initial model and voice from query string
    const modelSelect = document.getElementById("model-select");
    const voiceSelect = document.getElementById("voice-select");
    // Define valid options
    const validModels = new Set(Array.from(modelSelect.options).map(opt => opt.value));
    const validVoices = new Set(Array.from(voiceSelect.options).map(opt => opt.value));
    
    // Validate URL parameters
    const modelParam = urlParams.get("model");
    const voiceParam = urlParams.get("voice");
    const initialModel = validModels.has(modelParam) ? modelParam : "None";
    const initialVoice = validVoices.has(voiceParam) ? voiceParam : "onyx";
    modelSelect.value = initialModel;
    voiceSelect.value = initialVoice;

    // Update query string when model or voice changes
    modelSelect.addEventListener("change", updateQueryString);
    voiceSelect.addEventListener("change", updateQueryString);
});

// Function to update the query string with model and voice
function updateQueryString() {
    const model = document.getElementById("model-select").value;
    const voice = document.getElementById("voice-select").value;
    const newUrl = new URL(window.location.href);
    newUrl.searchParams.set("model", model);
    newUrl.searchParams.set("voice", voice);
    window.history.replaceState({}, '', newUrl);
}
*Created by: coderabbitai[bot]* _:warning: Potential issue_ **Add input validation for model and voice parameters.** The code accepts model and voice values from URL parameters without validation. This could potentially lead to XSS if these values are reflected elsewhere in the UI. ```diff const modelSelect = document.getElementById("model-select"); const voiceSelect = document.getElementById("voice-select"); - const initialModel = urlParams.get("model") || "None"; - const initialVoice = urlParams.get("voice") || "onyx"; + // Define valid options + const validModels = new Set(Array.from(modelSelect.options).map(opt => opt.value)); + const validVoices = new Set(Array.from(voiceSelect.options).map(opt => opt.value)); + + // Validate URL parameters + const modelParam = urlParams.get("model"); + const voiceParam = urlParams.get("voice"); + const initialModel = validModels.has(modelParam) ? modelParam : "None"; + const initialVoice = validVoices.has(voiceParam) ? voiceParam : "onyx"; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion // Set initial model and voice from query string const modelSelect = document.getElementById("model-select"); const voiceSelect = document.getElementById("voice-select"); // Define valid options const validModels = new Set(Array.from(modelSelect.options).map(opt => opt.value)); const validVoices = new Set(Array.from(voiceSelect.options).map(opt => opt.value)); // Validate URL parameters const modelParam = urlParams.get("model"); const voiceParam = urlParams.get("voice"); const initialModel = validModels.has(modelParam) ? modelParam : "None"; const initialVoice = validVoices.has(voiceParam) ? voiceParam : "onyx"; modelSelect.value = initialModel; voiceSelect.value = initialVoice; // Update query string when model or voice changes modelSelect.addEventListener("change", updateQueryString); voiceSelect.addEventListener("change", updateQueryString); }); // Function to update the query string with model and voice function updateQueryString() { const model = document.getElementById("model-select").value; const voice = document.getElementById("voice-select").value; const newUrl = new URL(window.location.href); newUrl.searchParams.set("model", model); newUrl.searchParams.set("voice", voice); window.history.replaceState({}, '', newUrl); } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated reply by CodeRabbit -->
russellballestrini commented 2024-11-23 09:41:42 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Review: Commented

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
templates/chat.html (4)

16-58: LGTM! Consider adding ARIA labels for accessibility.

The utility belt section is well-structured and organized. However, to improve accessibility, consider adding ARIA labels to the selectors and lists.

-            <select id="model-select">
+            <select id="model-select" aria-label="Select AI model">

-            <select id="voice-select">
+            <select id="voice-select" aria-label="Select voice for text-to-speech">

-            <ul id="active-users">
+            <ul id="active-users" aria-label="List of active users in the chat">

154-159: Improve visual separation between model and message.

When the model is prepended to the message, there's no clear visual separation which could make it harder to distinguish the model from the actual message content.

     if (model !== "None") {
-        messageToSend = `${model} ${messageToSend}`;
+        messageToSend = `[${model}] ${messageToSend}`;
     }

Line range hint 208-250: Security concern: API key exposed in client-side code.

The TTS API key is hardcoded as "dummy-api-key" in the client-side code. Even if this is a placeholder, the architecture should be changed to proxy TTS requests through the backend to protect the real API key.

Consider implementing a backend endpoint that proxies the TTS requests and keeps the API key secure:

-    const response = await fetch(TTS_API_URL, {
+    const response = await fetch('/api/tts', {
         method: 'POST',
         headers: {
             'Content-Type': 'application/json',
-            'Authorization': `Bearer ${API_KEY}`
         },
         body: JSON.stringify({
             model: 'tts-1',
             voice: voice,
             input: cleanText
         })
     });

Line range hint 441-515: Handle potential race conditions in message buffer management.

The message buffer management could be susceptible to race conditions when multiple chunks arrive simultaneously or out of order. Consider implementing sequence numbers or timestamps to ensure correct message assembly.

     // If the message buffer for this ID doesn't exist, create it
     if (!messageBuffers[data.id]) {
-        messageBuffers[data.id] = "";
+        messageBuffers[data.id] = {
+            content: "",
+            lastSequence: -1
+        };
     }

+    // Skip if we receive an out-of-order chunk
+    if (data.sequence <= messageBuffers[data.id].lastSequence) {
+        console.warn(`Received out-of-order chunk for message ${data.id}`);
+        return;
+    }

     // Append the chunk to the buffer
-    messageBuffers[data.id] += data.content;
+    messageBuffers[data.id].content += data.content;
+    messageBuffers[data.id].lastSequence = data.sequence;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3b3714f527 and f9f7da6ffc.

📒 Files selected for processing (2)
  • app.py (7 hunks)
  • templates/chat.html (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app.py
🧰 Additional context used
📓 Learnings (1)
templates/chat.html (1)
Learnt from: russellballestrini
PR: russellballestrini/opencompletion#7
File: templates/chat.html:117-122
Timestamp: 2024-11-23T13:55:49.591Z
Learning: In the chat application, selecting `None` as the model means that no LLM should be used.
*Created by: coderabbitai[bot]* **Review:** Commented **Actionable comments posted: 2** <details> <summary>🧹 Outside diff range and nitpick comments (4)</summary><blockquote> <details> <summary>templates/chat.html (4)</summary><blockquote> `16-58`: **LGTM! Consider adding ARIA labels for accessibility.** The utility belt section is well-structured and organized. However, to improve accessibility, consider adding ARIA labels to the selectors and lists. ```diff - <select id="model-select"> + <select id="model-select" aria-label="Select AI model"> - <select id="voice-select"> + <select id="voice-select" aria-label="Select voice for text-to-speech"> - <ul id="active-users"> + <ul id="active-users" aria-label="List of active users in the chat"> ``` --- `154-159`: **Improve visual separation between model and message.** When the model is prepended to the message, there's no clear visual separation which could make it harder to distinguish the model from the actual message content. ```diff if (model !== "None") { - messageToSend = `${model} ${messageToSend}`; + messageToSend = `[${model}] ${messageToSend}`; } ``` --- Line range hint `208-250`: **Security concern: API key exposed in client-side code.** The TTS API key is hardcoded as "dummy-api-key" in the client-side code. Even if this is a placeholder, the architecture should be changed to proxy TTS requests through the backend to protect the real API key. Consider implementing a backend endpoint that proxies the TTS requests and keeps the API key secure: ```diff - const response = await fetch(TTS_API_URL, { + const response = await fetch('/api/tts', { method: 'POST', headers: { 'Content-Type': 'application/json', - 'Authorization': `Bearer ${API_KEY}` }, body: JSON.stringify({ model: 'tts-1', voice: voice, input: cleanText }) }); ``` --- Line range hint `441-515`: **Handle potential race conditions in message buffer management.** The message buffer management could be susceptible to race conditions when multiple chunks arrive simultaneously or out of order. Consider implementing sequence numbers or timestamps to ensure correct message assembly. ```diff // If the message buffer for this ID doesn't exist, create it if (!messageBuffers[data.id]) { - messageBuffers[data.id] = ""; + messageBuffers[data.id] = { + content: "", + lastSequence: -1 + }; } + // Skip if we receive an out-of-order chunk + if (data.sequence <= messageBuffers[data.id].lastSequence) { + console.warn(`Received out-of-order chunk for message ${data.id}`); + return; + } // Append the chunk to the buffer - messageBuffers[data.id] += data.content; + messageBuffers[data.id].content += data.content; + messageBuffers[data.id].lastSequence = data.sequence; ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 3b3714f52787666efa5ee79bf36d9a9beafcec8e and f9f7da6ffcca68ed0f147a0b379b29732efcb842. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `app.py` (7 hunks) * `templates/chat.html` (7 hunks) </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * app.py </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>📓 Learnings (1)</summary> <details> <summary>templates/chat.html (1)</summary> ``` Learnt from: russellballestrini PR: russellballestrini/opencompletion#7 File: templates/chat.html:117-122 Timestamp: 2024-11-23T13:55:49.591Z Learning: In the chat application, selecting `None` as the model means that no LLM should be used. ``` </details> </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
russellballestrini commented 2024-11-23 10:09:01 -05:00 (Migrated from git2.unturf.com)

Created by: russellballestrini

Could we refactor such that we have a list of valid voices? The valid voices are in the drop down.

*Created by: russellballestrini* Could we refactor such that we have a list of valid voices? The valid voices are in the drop down.
russellballestrini commented 2024-11-23 10:09:40 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

@russellballestrini, certainly! We can refactor the code to maintain a list of valid voices in the JavaScript code and use it both to populate the dropdown and to validate the URL parameters. Here's how we can do it:

// Define the list of valid voices
const validVoices = ["onyx", "alloy", "echo", "fable", "nova", "shimmer"];

// Populate the voice-select dropdown
const voiceSelect = document.getElementById("voice-select");
voiceSelect.innerHTML = ""; // Clear existing options
validVoices.forEach(voice => {
    const option = document.createElement("option");
    option.value = voice;
    option.textContent = capitalizeFirstLetter(voice);
    voiceSelect.appendChild(option);
});

// Helper function to capitalize the first letter
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

// Define the list of valid models
const validModels = [
    "None", "gemini-flash", "gemini-flash-8b", "gemini-pro", "grok-beta",
    "vllm/hermes-llama-3", "gpt-4", "gpt-4o-2024-08-06", "gpt-mini", "gpt-o1-mini",
    "claude-haiku", "claude-sonnet", "claude-opus"
];

// Populate the model-select dropdown
const modelSelect = document.getElementById("model-select");
modelSelect.innerHTML = ""; // Clear existing options
validModels.forEach(model => {
    const option = document.createElement("option");
    option.value = model;
    option.textContent = model; // Display the model name as-is
    modelSelect.appendChild(option);
});

// Get URL parameters
const urlParams = new URLSearchParams(window.location.search);
const modelParam = urlParams.get("model");
const voiceParam = urlParams.get("voice");

// Validate URL parameters
const initialModel = validModels.includes(modelParam) ? modelParam : "None";
const initialVoice = validVoices.includes(voiceParam) ? voiceParam : "onyx";

// Set the select values
modelSelect.value = initialModel;
voiceSelect.value = initialVoice;

// Update query string when model or voice changes
modelSelect.addEventListener("change", updateQueryString);
voiceSelect.addEventListener("change", updateQueryString);

// Function to update the query string with model and voice
function updateQueryString() {
    const model = modelSelect.value;
    const voice = voiceSelect.value;
    const newUrl = new URL(window.location.href);
    newUrl.searchParams.set("model", model);
    newUrl.searchParams.set("voice", voice);
    window.history.replaceState({}, '', newUrl);
}

This refactoring accomplishes the following:

  • Defines arrays of valid voices and models: The validVoices and validModels arrays hold the valid options.

  • Populates the dropdowns dynamically: The dropdowns for voices and models are populated based on these arrays, ensuring consistency between the lists and the validation logic.

  • Validates URL parameters: When retrieving the model and voice from the URL, we check against the arrays to ensure they are valid before using them.

  • Simplifies updates: If you need to add or remove voices or models in the future, you only need to update the arrays, and both the dropdown and validation logic will be updated accordingly.

Let me know if this approach works for you or if you'd like any further adjustments!

*Created by: coderabbitai[bot]* @russellballestrini, certainly! We can refactor the code to maintain a list of valid voices in the JavaScript code and use it both to populate the dropdown and to validate the URL parameters. Here's how we can do it: ```javascript // Define the list of valid voices const validVoices = ["onyx", "alloy", "echo", "fable", "nova", "shimmer"]; // Populate the voice-select dropdown const voiceSelect = document.getElementById("voice-select"); voiceSelect.innerHTML = ""; // Clear existing options validVoices.forEach(voice => { const option = document.createElement("option"); option.value = voice; option.textContent = capitalizeFirstLetter(voice); voiceSelect.appendChild(option); }); // Helper function to capitalize the first letter function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } // Define the list of valid models const validModels = [ "None", "gemini-flash", "gemini-flash-8b", "gemini-pro", "grok-beta", "vllm/hermes-llama-3", "gpt-4", "gpt-4o-2024-08-06", "gpt-mini", "gpt-o1-mini", "claude-haiku", "claude-sonnet", "claude-opus" ]; // Populate the model-select dropdown const modelSelect = document.getElementById("model-select"); modelSelect.innerHTML = ""; // Clear existing options validModels.forEach(model => { const option = document.createElement("option"); option.value = model; option.textContent = model; // Display the model name as-is modelSelect.appendChild(option); }); // Get URL parameters const urlParams = new URLSearchParams(window.location.search); const modelParam = urlParams.get("model"); const voiceParam = urlParams.get("voice"); // Validate URL parameters const initialModel = validModels.includes(modelParam) ? modelParam : "None"; const initialVoice = validVoices.includes(voiceParam) ? voiceParam : "onyx"; // Set the select values modelSelect.value = initialModel; voiceSelect.value = initialVoice; // Update query string when model or voice changes modelSelect.addEventListener("change", updateQueryString); voiceSelect.addEventListener("change", updateQueryString); // Function to update the query string with model and voice function updateQueryString() { const model = modelSelect.value; const voice = voiceSelect.value; const newUrl = new URL(window.location.href); newUrl.searchParams.set("model", model); newUrl.searchParams.set("voice", voice); window.history.replaceState({}, '', newUrl); } ``` This refactoring accomplishes the following: - **Defines arrays of valid voices and models**: The `validVoices` and `validModels` arrays hold the valid options. - **Populates the dropdowns dynamically**: The dropdowns for voices and models are populated based on these arrays, ensuring consistency between the lists and the validation logic. - **Validates URL parameters**: When retrieving the `model` and `voice` from the URL, we check against the arrays to ensure they are valid before using them. - **Simplifies updates**: If you need to add or remove voices or models in the future, you only need to update the arrays, and both the dropdown and validation logic will be updated accordingly. Let me know if this approach works for you or if you'd like any further adjustments! <!-- This is an auto-generated reply by CodeRabbit -->
russellballestrini commented 2024-11-23 10:10:43 -05:00 (Migrated from git2.unturf.com)

Created by: russellballestrini

Can we make a commitable change?

*Created by: russellballestrini* Can we make a commitable change?
russellballestrini commented 2024-11-23 10:11:17 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

@russellballestrini, certainly! Here's the updated code that you can apply:

// Define the list of valid voices
const validVoices = ["onyx", "alloy", "echo", "fable", "nova", "shimmer"];

// Populate the voice-select dropdown
const voiceSelect = document.getElementById("voice-select");
voiceSelect.innerHTML = ""; // Clear existing options
validVoices.forEach(voice => {
    const option = document.createElement("option");
    option.value = voice;
    option.textContent = capitalizeFirstLetter(voice);
    voiceSelect.appendChild(option);
});

// Helper function to capitalize the first letter
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

// Define the list of valid models
const validModels = [
    "None", "gemini-flash", "gemini-flash-8b", "gemini-pro", "grok-beta",
    "vllm/hermes-llama-3", "gpt-4", "gpt-4o-2024-08-06", "gpt-mini", "gpt-o1-mini",
    "claude-haiku", "claude-sonnet", "claude-opus"
];

// Populate the model-select dropdown
const modelSelect = document.getElementById("model-select");
modelSelect.innerHTML = ""; // Clear existing options
validModels.forEach(model => {
    const option = document.createElement("option");
    option.value = model;
    option.textContent = model; // Display the model name as-is
    modelSelect.appendChild(option);
});

// Get URL parameters
const urlParams = new URLSearchParams(window.location.search);
const modelParam = urlParams.get("model");
const voiceParam = urlParams.get("voice");

// Validate URL parameters
const initialModel = validModels.includes(modelParam) ? modelParam : "None";
const initialVoice = validVoices.includes(voiceParam) ? voiceParam : "onyx";

// Set the select values
modelSelect.value = initialModel;
voiceSelect.value = initialVoice;

// Update query string when model or voice changes
modelSelect.addEventListener("change", updateQueryString);
voiceSelect.addEventListener("change", updateQueryString);

// Function to update the query string with model and voice
function updateQueryString() {
    const model = modelSelect.value;
    const voice = voiceSelect.value;
    const newUrl = new URL(window.location.href);
    newUrl.searchParams.set("model", model);
    newUrl.searchParams.set("voice", voice);
    window.history.replaceState({}, '', newUrl);
}

// Ensure you include this script after the HTML elements or wrap it inside DOMContentLoaded
document.addEventListener('DOMContentLoaded', () => {
    // Existing code above...
});

Explanation:

  • Define Arrays of Valid Options:

    • The validVoices and validModels arrays contain all the valid options for voices and models.
  • Populate Dropdowns Dynamically:

    • The code clears any existing options in the dropdowns and repopulates them using the arrays.
    • This ensures that the options in the dropdowns are always consistent with the arrays of valid options.
  • Validate URL Parameters:

    • When retrieving the model and voice from the URL parameters, the code checks if they are included in the valid options arrays.
    • If the parameters are valid, they are used to set the initial value of the select elements; otherwise, default values are used.
  • Update Query String on Change:

    • Event listeners are added to the select elements to update the query string whenever the user changes the selection.
    • This keeps the URL in sync with the current selections.
  • Helper Function:

    • The capitalizeFirstLetter function is used to format the voice names in the dropdown.

Benefits:

  • Security:

    • Validating the URL parameters against the arrays of valid options prevents manipulation of the parameters and potential XSS vulnerabilities.
  • Maintainability:

    • Centralizing the valid options in arrays makes it easier to add, remove, or modify voices and models in the future.
    • Since the dropdowns are populated dynamically, changes only need to be made in one place.
  • User Experience:

    • The dropdowns will always display the correct options, and users cannot select invalid options.
    • The query string reflects the current selections, allowing users to share URLs with specific settings.

Let me know if this works for you or if you'd like any further adjustments!

*Created by: coderabbitai[bot]* @russellballestrini, certainly! Here's the updated code that you can apply: ```javascript // Define the list of valid voices const validVoices = ["onyx", "alloy", "echo", "fable", "nova", "shimmer"]; // Populate the voice-select dropdown const voiceSelect = document.getElementById("voice-select"); voiceSelect.innerHTML = ""; // Clear existing options validVoices.forEach(voice => { const option = document.createElement("option"); option.value = voice; option.textContent = capitalizeFirstLetter(voice); voiceSelect.appendChild(option); }); // Helper function to capitalize the first letter function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } // Define the list of valid models const validModels = [ "None", "gemini-flash", "gemini-flash-8b", "gemini-pro", "grok-beta", "vllm/hermes-llama-3", "gpt-4", "gpt-4o-2024-08-06", "gpt-mini", "gpt-o1-mini", "claude-haiku", "claude-sonnet", "claude-opus" ]; // Populate the model-select dropdown const modelSelect = document.getElementById("model-select"); modelSelect.innerHTML = ""; // Clear existing options validModels.forEach(model => { const option = document.createElement("option"); option.value = model; option.textContent = model; // Display the model name as-is modelSelect.appendChild(option); }); // Get URL parameters const urlParams = new URLSearchParams(window.location.search); const modelParam = urlParams.get("model"); const voiceParam = urlParams.get("voice"); // Validate URL parameters const initialModel = validModels.includes(modelParam) ? modelParam : "None"; const initialVoice = validVoices.includes(voiceParam) ? voiceParam : "onyx"; // Set the select values modelSelect.value = initialModel; voiceSelect.value = initialVoice; // Update query string when model or voice changes modelSelect.addEventListener("change", updateQueryString); voiceSelect.addEventListener("change", updateQueryString); // Function to update the query string with model and voice function updateQueryString() { const model = modelSelect.value; const voice = voiceSelect.value; const newUrl = new URL(window.location.href); newUrl.searchParams.set("model", model); newUrl.searchParams.set("voice", voice); window.history.replaceState({}, '', newUrl); } // Ensure you include this script after the HTML elements or wrap it inside DOMContentLoaded document.addEventListener('DOMContentLoaded', () => { // Existing code above... }); ``` **Explanation:** - **Define Arrays of Valid Options:** - The `validVoices` and `validModels` arrays contain all the valid options for voices and models. - **Populate Dropdowns Dynamically:** - The code clears any existing options in the dropdowns and repopulates them using the arrays. - This ensures that the options in the dropdowns are always consistent with the arrays of valid options. - **Validate URL Parameters:** - When retrieving the `model` and `voice` from the URL parameters, the code checks if they are included in the valid options arrays. - If the parameters are valid, they are used to set the initial value of the select elements; otherwise, default values are used. - **Update Query String on Change:** - Event listeners are added to the select elements to update the query string whenever the user changes the selection. - This keeps the URL in sync with the current selections. - **Helper Function:** - The `capitalizeFirstLetter` function is used to format the voice names in the dropdown. **Benefits:** - **Security:** - Validating the URL parameters against the arrays of valid options prevents manipulation of the parameters and potential XSS vulnerabilities. - **Maintainability:** - Centralizing the valid options in arrays makes it easier to add, remove, or modify voices and models in the future. - Since the dropdowns are populated dynamically, changes only need to be made in one place. - **User Experience:** - The dropdowns will always display the correct options, and users cannot select invalid options. - The query string reflects the current selections, allowing users to share URLs with specific settings. Let me know if this works for you or if you'd like any further adjustments! <!-- This is an auto-generated reply by CodeRabbit -->
russellballestrini commented 2024-11-23 10:48:18 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Review: Commented

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
migrations/versions/38a330686a17_room_active_users.py (2)

10-10: Remove unused import

The sqlite dialect is imported but never used in this migration.

-from sqlalchemy.dialects import sqlite
🧰 Tools
🪛 Ruff (0.7.0)

10-10: sqlalchemy.dialects.sqlite imported but unused

Remove unused import: sqlalchemy.dialects.sqlite

(F401)


20-21: Consider using a more structured data type for active_users

Using a Text column with comma-separated values for active users could lead to data integrity issues:

  • Difficult to validate user IDs
  • Potential parsing errors with usernames containing commas
  • Inefficient for querying specific active users

Consider one of these alternatives:

  1. Create a junction table for room_active_users (preferred)
  2. Use a JSON/JSONB column type if supported by your database

Would you like me to help design a more robust schema for tracking active users?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fab40ba60d and 6f1c7def7b.

📒 Files selected for processing (1)
  • migrations/versions/38a330686a17_room_active_users.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
migrations/versions/38a330686a17_room_active_users.py

10-10: sqlalchemy.dialects.sqlite imported but unused

Remove unused import: sqlalchemy.dialects.sqlite

(F401)

🔇 Additional comments (1)
migrations/versions/38a330686a17_room_active_users.py (1)

19-25: LGTM - Migration structure is correct

The migration follows best practices:

  • Uses batch operations for SQLite compatibility
  • Includes both upgrade and downgrade paths
  • Properly handles nullable column for existing data
*Created by: coderabbitai[bot]* **Review:** Commented **Actionable comments posted: 0** <details> <summary>🧹 Outside diff range and nitpick comments (2)</summary><blockquote> <details> <summary>migrations/versions/38a330686a17_room_active_users.py (2)</summary><blockquote> `10-10`: **Remove unused import** The `sqlite` dialect is imported but never used in this migration. ```diff -from sqlalchemy.dialects import sqlite ``` <details> <summary>🧰 Tools</summary> <details> <summary>🪛 Ruff (0.7.0)</summary> 10-10: `sqlalchemy.dialects.sqlite` imported but unused Remove unused import: `sqlalchemy.dialects.sqlite` (F401) </details> </details> --- `20-21`: **Consider using a more structured data type for active_users** Using a Text column with comma-separated values for active users could lead to data integrity issues: - Difficult to validate user IDs - Potential parsing errors with usernames containing commas - Inefficient for querying specific active users Consider one of these alternatives: 1. Create a junction table for room_active_users (preferred) 2. Use a JSON/JSONB column type if supported by your database Would you like me to help design a more robust schema for tracking active users? </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between fab40ba60d4c35adeae5d37194d8089f85ac3d5b and 6f1c7def7becf486491648e8d49d7c152a4ce27c. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `migrations/versions/38a330686a17_room_active_users.py` (1 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 Ruff (0.7.0)</summary> <details> <summary>migrations/versions/38a330686a17_room_active_users.py</summary> 10-10: `sqlalchemy.dialects.sqlite` imported but unused Remove unused import: `sqlalchemy.dialects.sqlite` (F401) </details> </details> </details> <details> <summary>🔇 Additional comments (1)</summary> <details> <summary>migrations/versions/38a330686a17_room_active_users.py (1)</summary> `19-25`: **LGTM - Migration structure is correct** The migration follows best practices: - Uses batch operations for SQLite compatibility - Includes both upgrade and downgrade paths - Properly handles nullable column for existing data </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
russellballestrini commented 2024-11-23 11:36:04 -05:00 (Migrated from git2.unturf.com)

Created by: russellballestrini

@coderabbit can you create a mergable suggestion based on the current state of the code? particularly things to prevent injection

*Created by: russellballestrini* @coderabbit can you create a mergable suggestion based on the current state of the code? particularly things to prevent injection
russellballestrini commented 2024-11-23 11:36:40 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Tip

For best results, initiate chat on the files or code changes.

@russellballestrini

Based on the current state of your code and focusing on preventing injection vulnerabilities, I have a few recommendations:

  1. Sanitize User Inputs

    In app.py, you introduced methods add_user, remove_user, and get_active_users in the Room model, where active_users is stored as a comma-separated string. Storing usernames in this manner can lead to injection attacks if usernames contain special characters like commas.

    Recommendation:

    • Use a Many-to-Many Relationship:
      Instead of storing active_users as a comma-separated string, consider using a many-to-many relationship between Room and User models. This approach leverages SQLAlchemy's relationship capabilities, ensuring data integrity and security.

      Example:

      # app.py
      
      room_active_users = db.Table('room_active_users',
          db.Column('room_id', db.Integer, db.ForeignKey('room.id'), primary_key=True),
          db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)
      )
      
      class Room(db.Model):
          __tablename__ = 'room'
          id = db.Column(db.Integer, primary_key=True)
          name = db.Column(db.String(100), nullable=False, unique=True)
          messages = db.relationship('Message', backref='room', lazy=True)
          active_users = db.relationship('User', secondary=room_active_users, backref='rooms')
      

      Update your methods:

      def add_user(self, user):
          if user not in self.active_users:
              self.active_users.append(user)
              db.session.commit()
      
      def remove_user(self, user):
          if user in self.active_users:
              self.active_users.remove(user)
              db.session.commit()
      
      def get_active_users(self):
          return [user.username for user in self.active_users]
      

      Adjust your event handlers accordingly:

      @socketio.on('join')
      def on_join(data):
          username = data['username']
          room_name = data['room']
          room = Room.query.filter_by(name=room_name).first()
          user = User.query.filter_by(username=username).first()
          if room and user:
              join_room(room_name)
              room.add_user(user)
              active_users = room.get_active_users()
              socketio.emit('active_users', {'active_users': active_users}, room=room_name)
      
  2. Escape Output in Templates

    In your templates/chat.html, ensure that any user-generated content is properly escaped to prevent XSS attacks.

    Recommendation:

    • Use Jinja2's automatic escaping for variables.
    • If you need to render raw HTML, use the |safe filter judiciously.

    Example:

    <!-- templates/chat.html -->
    
    <ul id="users">
        {% for user in active_users %}
            <li>{{ user }}</li>
        {% endfor %}
    </ul>
    
  3. Avoid Using eval or exec

    Ensure that you are not using Python's eval() or exec() functions with user-supplied input, as this can lead to code injection.

  4. Validate and Sanitize Inputs

    Implement server-side validation for all user inputs.

    Recommendation:

    • Use WTForms or similar libraries to validate form data.
    • Sanitize inputs to remove or escape special characters that could be used maliciously.
  5. Use Parameterized Queries

    If you use raw SQL queries, always use parameterized queries to prevent SQL injection.

    Example:

    # Avoid this
    result = db.engine.execute("SELECT * FROM users WHERE username = '%s'" % username)
    
    # Use this
    result = db.engine.execute("SELECT * FROM users WHERE username = :username", {'username': username})
    
  6. Protect Against Cross-Site Request Forgery (CSRF)

    Ensure that your forms and AJAX requests are protected against CSRF.

    Recommendation:

    • Enable CSRF protection in Flask by using Flask-WTF.

    Example:

    from flask_wtf.csrf import CSRFProtect
    
    csrf = CSRFProtect(app)
    
  7. Handle User Sessions Securely

    Manage user sessions carefully to prevent session hijacking.

    Recommendation:

    • Use secure cookies (session_cookie_secure = True).
    • Set SESSION_COOKIE_HTTPONLY to prevent client-side scripts from accessing the session cookie.
  8. Sanitize Data in JavaScript

    In chat.html, when manipulating the DOM with JavaScript, ensure that you are not inserting raw user input into the DOM.

    Recommendation:

    • Use textContent or innerText instead of innerHTML.

    Example:

    // Instead of this
    messageElement.innerHTML = message;
    
    // Use this
    messageElement.innerText = message;
    

By implementing these recommendations, you can enhance the security of your application and mitigate injection risks.

Let me know if you need further assistance or clarification.

*Created by: coderabbitai[bot]* <!-- This is an auto-generated reply by CodeRabbit --> > [!TIP] > For best results, initiate chat on the files or code changes. @russellballestrini Based on the current state of your code and focusing on preventing injection vulnerabilities, I have a few recommendations: 1. **Sanitize User Inputs** In `app.py`, you introduced methods `add_user`, `remove_user`, and `get_active_users` in the `Room` model, where `active_users` is stored as a comma-separated string. Storing usernames in this manner can lead to injection attacks if usernames contain special characters like commas. **Recommendation:** - **Use a Many-to-Many Relationship:** Instead of storing `active_users` as a comma-separated string, consider using a many-to-many relationship between `Room` and `User` models. This approach leverages SQLAlchemy's relationship capabilities, ensuring data integrity and security. **Example:** ```python # app.py room_active_users = db.Table('room_active_users', db.Column('room_id', db.Integer, db.ForeignKey('room.id'), primary_key=True), db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True) ) class Room(db.Model): __tablename__ = 'room' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False, unique=True) messages = db.relationship('Message', backref='room', lazy=True) active_users = db.relationship('User', secondary=room_active_users, backref='rooms') ``` **Update your methods:** ```python def add_user(self, user): if user not in self.active_users: self.active_users.append(user) db.session.commit() def remove_user(self, user): if user in self.active_users: self.active_users.remove(user) db.session.commit() def get_active_users(self): return [user.username for user in self.active_users] ``` **Adjust your event handlers accordingly:** ```python @socketio.on('join') def on_join(data): username = data['username'] room_name = data['room'] room = Room.query.filter_by(name=room_name).first() user = User.query.filter_by(username=username).first() if room and user: join_room(room_name) room.add_user(user) active_users = room.get_active_users() socketio.emit('active_users', {'active_users': active_users}, room=room_name) ``` 2. **Escape Output in Templates** In your `templates/chat.html`, ensure that any user-generated content is properly escaped to prevent XSS attacks. **Recommendation:** - Use Jinja2's automatic escaping for variables. - If you need to render raw HTML, use the `|safe` filter judiciously. **Example:** ```html <!-- templates/chat.html --> <ul id="users"> {% for user in active_users %} <li>{{ user }}</li> {% endfor %} </ul> ``` 3. **Avoid Using `eval` or `exec`** Ensure that you are not using Python's `eval()` or `exec()` functions with user-supplied input, as this can lead to code injection. 4. **Validate and Sanitize Inputs** Implement server-side validation for all user inputs. **Recommendation:** - Use WTForms or similar libraries to validate form data. - Sanitize inputs to remove or escape special characters that could be used maliciously. 5. **Use Parameterized Queries** If you use raw SQL queries, always use parameterized queries to prevent SQL injection. **Example:** ```python # Avoid this result = db.engine.execute("SELECT * FROM users WHERE username = '%s'" % username) # Use this result = db.engine.execute("SELECT * FROM users WHERE username = :username", {'username': username}) ``` 6. **Protect Against Cross-Site Request Forgery (CSRF)** Ensure that your forms and AJAX requests are protected against CSRF. **Recommendation:** - Enable CSRF protection in Flask by using `Flask-WTF`. **Example:** ```python from flask_wtf.csrf import CSRFProtect csrf = CSRFProtect(app) ``` 7. **Handle User Sessions Securely** Manage user sessions carefully to prevent session hijacking. **Recommendation:** - Use secure cookies (`session_cookie_secure = True`). - Set `SESSION_COOKIE_HTTPONLY` to prevent client-side scripts from accessing the session cookie. 8. **Sanitize Data in JavaScript** In `chat.html`, when manipulating the DOM with JavaScript, ensure that you are not inserting raw user input into the DOM. **Recommendation:** - Use `textContent` or `innerText` instead of `innerHTML`. **Example:** ```javascript // Instead of this messageElement.innerHTML = message; // Use this messageElement.innerText = message; ``` By implementing these recommendations, you can enhance the security of your application and mitigate injection risks. Let me know if you need further assistance or clarification.
russellballestrini commented 2024-11-23 12:03:54 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

🛠️ Refactor suggestion

Reconsider storing active_users as a comma-separated string

Storing active_users as a comma-separated string in the database can lead to inefficiencies and makes querying more complex. It is advisable to normalize this data by creating a separate association table or using a many-to-many relationship between Room and User models. This approach enhances scalability, data integrity, and simplifies querying active users.

*Created by: coderabbitai[bot]* _:hammer_and_wrench: Refactor suggestion_ **Reconsider storing `active_users` as a comma-separated string** Storing `active_users` as a comma-separated string in the database can lead to inefficiencies and makes querying more complex. It is advisable to normalize this data by creating a separate association table or using a many-to-many relationship between `Room` and `User` models. This approach enhances scalability, data integrity, and simplifies querying active users. <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:03:54 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

🛠️ Refactor suggestion

Consider adding a foreign key constraint for room_id

The room_id column appears to reference rooms but lacks a foreign key constraint. This could lead to data integrity issues where room_id values don't correspond to actual rooms.

 def upgrade():
     op.create_table('user_session',
     sa.Column('id', sa.Integer(), nullable=False),
     sa.Column('session_id', sa.String(length=128), nullable=False),
     sa.Column('username', sa.String(length=128), nullable=True),
     sa.Column('room_name', sa.String(length=128), nullable=True),
     sa.Column('room_id', sa.Integer(), nullable=True),
     sa.PrimaryKeyConstraint('id'),
-    sa.UniqueConstraint('session_id')
+    sa.UniqueConstraint('session_id'),
+    sa.ForeignKeyConstraint(['room_id'], ['room.id'], ondelete='SET NULL')
     )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    op.create_table('user_session',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('session_id', sa.String(length=128), nullable=False),
    sa.Column('username', sa.String(length=128), nullable=True),
    sa.Column('room_name', sa.String(length=128), nullable=True),
    sa.Column('room_id', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('session_id'),
    sa.ForeignKeyConstraint(['room_id'], ['room.id'], ondelete='SET NULL')
    )
*Created by: coderabbitai[bot]* _:hammer_and_wrench: Refactor suggestion_ **Consider adding a foreign key constraint for room_id** The `room_id` column appears to reference rooms but lacks a foreign key constraint. This could lead to data integrity issues where `room_id` values don't correspond to actual rooms. ```diff def upgrade(): op.create_table('user_session', sa.Column('id', sa.Integer(), nullable=False), sa.Column('session_id', sa.String(length=128), nullable=False), sa.Column('username', sa.String(length=128), nullable=True), sa.Column('room_name', sa.String(length=128), nullable=True), sa.Column('room_id', sa.Integer(), nullable=True), sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('session_id') + sa.UniqueConstraint('session_id'), + sa.ForeignKeyConstraint(['room_id'], ['room.id'], ondelete='SET NULL') ) ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion op.create_table('user_session', sa.Column('id', sa.Integer(), nullable=False), sa.Column('session_id', sa.String(length=128), nullable=False), sa.Column('username', sa.String(length=128), nullable=True), sa.Column('room_name', sa.String(length=128), nullable=True), sa.Column('room_id', sa.Integer(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('session_id'), sa.ForeignKeyConstraint(['room_id'], ['room.id'], ondelete='SET NULL') ) ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:03:55 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Review: Commented

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
migrations/versions/1ac5a8e0f577_user_session_table.py (1)

10-10: Remove unused import

The sqlite dialect import is not used in this migration.

-from sqlalchemy.dialects import sqlite
🧰 Tools
🪛 Ruff (0.7.0)

10-10: sqlalchemy.dialects.sqlite imported but unused

Remove unused import: sqlalchemy.dialects.sqlite

(F401)

app.py (3)

190-195: Utilize foreign key relationships in UserSession model

The UserSession model stores username, room_name, and room_id as plain fields. To improve data integrity and leverage ORM capabilities, consider establishing foreign key relationships to the Room model (and a User model if available). This change will ensure referential integrity and make querying session data more efficient.


Line range hint 453-516: Validate and sanitize username input to prevent security vulnerabilities

The username is obtained directly from data["username"], which can be manipulated by the client. Without proper validation and sanitization, this can lead to security issues such as Cross-Site Scripting (XSS) attacks when broadcasting messages like "{username} has joined the room.". Implement input validation and escaping mechanisms to ensure that username is safe before using it in messages or database operations.


1105-1107: Avoid passing unnecessary API keys

In the get_openai_client_and_model function, the api_key is passed when initializing the OpenAI client for the local ollama model endpoint, even though it's set to "not-needed". If the API key is not required for this local endpoint, consider omitting it to prevent confusion and potential security issues.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1c7def7b and 0f82305087.

📒 Files selected for processing (2)
  • app.py (12 hunks)
  • migrations/versions/1ac5a8e0f577_user_session_table.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
migrations/versions/1ac5a8e0f577_user_session_table.py

10-10: sqlalchemy.dialects.sqlite imported but unused

Remove unused import: sqlalchemy.dialects.sqlite

(F401)

🔇 Additional comments (6)
migrations/versions/1ac5a8e0f577_user_session_table.py (1)

19-32: LGTM! Well-structured table design

The table design effectively captures user session data with:

  • Proper primary key and unique constraints
  • Appropriate string lengths for identifiers
  • Nullable fields for flexibility
  • Clean downgrade path

Let's verify the referenced table and column exist:

Verification successful

Room table exists with proper id column - Foreign key relationship is valid

The room table exists and is properly structured with an id column as the primary key. The migration history shows:

  • room table was created with an id column (Integer, primary key)
  • Foreign key relationship between user_session.room_id and room.id is valid
  • Room table also maintains a unique constraint on the name column
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the 'room' table exists and has an 'id' column
# Expected: Find references to room table creation and id column

# Search for room table creation in migrations
rg -A 5 "create_table.*room" migrations/

Length of output: 42


Script:

#!/bin/bash
# Let's try a broader search for any table creation migrations
rg "create_table" migrations/

# Also search for any room-related tables or columns
rg -i "room" migrations/

# List all migration files to ensure we're searching in the right place
fd . migrations/

Length of output: 4989


Script:

#!/bin/bash
# Let's examine the room table creation migration to verify the id column
cat migrations/versions/a9e886c56482_create_room_table.py

Length of output: 4310

app.py (5)

1233-1238: Eliminate code duplication by creating a helper function

The code block emitting the message_chunk with is_complete flag and deleting the processing message is repeated here as well. Consider refactoring this into a helper function as suggested earlier to maintain consistency and reduce redundancy.


1345-1350: Eliminate code duplication by creating a helper function

Again, the same code pattern is repeated. Refactoring into a helper function will simplify the codebase and enhance readability.


1475-1480: Eliminate code duplication by creating a helper function

This repeated code can be consolidated into a helper function to adhere to best practices and improve code maintainability.


1587-1592: Eliminate code duplication by creating a helper function

Refactoring this repeated code into a helper function will reduce redundancy and potential errors across the codebase.


1701-1706: Eliminate code duplication by creating a helper function

As previously noted, this code block is repeated multiple times. Refactoring it into a helper function will improve the code structure.

*Created by: coderabbitai[bot]* **Review:** Commented **Actionable comments posted: 3** <details> <summary>🧹 Outside diff range and nitpick comments (4)</summary><blockquote> <details> <summary>migrations/versions/1ac5a8e0f577_user_session_table.py (1)</summary><blockquote> `10-10`: **Remove unused import** The `sqlite` dialect import is not used in this migration. ```diff -from sqlalchemy.dialects import sqlite ``` <details> <summary>🧰 Tools</summary> <details> <summary>🪛 Ruff (0.7.0)</summary> 10-10: `sqlalchemy.dialects.sqlite` imported but unused Remove unused import: `sqlalchemy.dialects.sqlite` (F401) </details> </details> </blockquote></details> <details> <summary>app.py (3)</summary><blockquote> `190-195`: **Utilize foreign key relationships in `UserSession` model** The `UserSession` model stores `username`, `room_name`, and `room_id` as plain fields. To improve data integrity and leverage ORM capabilities, consider establishing foreign key relationships to the `Room` model (and a `User` model if available). This change will ensure referential integrity and make querying session data more efficient. --- Line range hint `453-516`: **Validate and sanitize `username` input to prevent security vulnerabilities** The `username` is obtained directly from `data["username"]`, which can be manipulated by the client. Without proper validation and sanitization, this can lead to security issues such as Cross-Site Scripting (XSS) attacks when broadcasting messages like `"{username} has joined the room."`. Implement input validation and escaping mechanisms to ensure that `username` is safe before using it in messages or database operations. --- `1105-1107`: **Avoid passing unnecessary API keys** In the `get_openai_client_and_model` function, the `api_key` is passed when initializing the `OpenAI` client for the local `ollama` model endpoint, even though it's set to `"not-needed"`. If the API key is not required for this local endpoint, consider omitting it to prevent confusion and potential security issues. </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 6f1c7def7becf486491648e8d49d7c152a4ce27c and 0f8230508763b020bf3e66c281aacee07c8bcd88. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `app.py` (12 hunks) * `migrations/versions/1ac5a8e0f577_user_session_table.py` (1 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 Ruff (0.7.0)</summary> <details> <summary>migrations/versions/1ac5a8e0f577_user_session_table.py</summary> 10-10: `sqlalchemy.dialects.sqlite` imported but unused Remove unused import: `sqlalchemy.dialects.sqlite` (F401) </details> </details> </details> <details> <summary>🔇 Additional comments (6)</summary> <details> <summary>migrations/versions/1ac5a8e0f577_user_session_table.py (1)</summary> `19-32`: **LGTM! Well-structured table design** The table design effectively captures user session data with: - Proper primary key and unique constraints - Appropriate string lengths for identifiers - Nullable fields for flexibility - Clean downgrade path Let's verify the referenced table and column exist: <details> <summary>✅ Verification successful</summary> **Room table exists with proper id column - Foreign key relationship is valid** The `room` table exists and is properly structured with an `id` column as the primary key. The migration history shows: - `room` table was created with an `id` column (Integer, primary key) - Foreign key relationship between `user_session.room_id` and `room.id` is valid - Room table also maintains a unique constraint on the `name` column </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify that the 'room' table exists and has an 'id' column # Expected: Find references to room table creation and id column # Search for room table creation in migrations rg -A 5 "create_table.*room" migrations/ ``` Length of output: 42 --- Script: ```shell #!/bin/bash # Let's try a broader search for any table creation migrations rg "create_table" migrations/ # Also search for any room-related tables or columns rg -i "room" migrations/ # List all migration files to ensure we're searching in the right place fd . migrations/ ``` Length of output: 4989 --- Script: ```shell #!/bin/bash # Let's examine the room table creation migration to verify the id column cat migrations/versions/a9e886c56482_create_room_table.py ``` Length of output: 4310 </details> </details> <details> <summary>app.py (5)</summary> `1233-1238`: **Eliminate code duplication by creating a helper function** The code block emitting the `message_chunk` with `is_complete` flag and deleting the processing message is repeated here as well. Consider refactoring this into a helper function as suggested earlier to maintain consistency and reduce redundancy. --- `1345-1350`: **Eliminate code duplication by creating a helper function** Again, the same code pattern is repeated. Refactoring into a helper function will simplify the codebase and enhance readability. --- `1475-1480`: **Eliminate code duplication by creating a helper function** This repeated code can be consolidated into a helper function to adhere to best practices and improve code maintainability. --- `1587-1592`: **Eliminate code duplication by creating a helper function** Refactoring this repeated code into a helper function will reduce redundancy and potential errors across the codebase. --- `1701-1706`: **Eliminate code duplication by creating a helper function** As previously noted, this code block is repeated multiple times. Refactoring it into a helper function will improve the code structure. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
russellballestrini commented 2024-11-23 12:07:36 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

⚠️ Potential issue

Consider using a proper many-to-many relationship for active users

The current implementation of storing active users as a comma-separated string has several issues:

  1. Susceptible to injection if usernames contain commas
  2. Race conditions possible in add/remove operations
  3. Inefficient for querying and filtering
  4. No validation of username format

Consider using SQLAlchemy's association table pattern:

# Create an association table
active_room_users = db.Table('active_room_users',
    db.Column('room_id', db.Integer, db.ForeignKey('room.id'), primary_key=True),
    db.Column('username', db.String(128), primary_key=True)
)

class Room(db.Model):
    # ... existing fields ...
    active_users = db.relationship('UserSession', 
                                 secondary=active_room_users,
                                 backref='active_rooms')
    
    def add_user(self, username):
        if not self.is_user_active(username):
            db.session.execute(
                active_room_users.insert().values(
                    room_id=self.id, username=username
                )
            )
    
    def remove_user(self, username):
        db.session.execute(
            active_room_users.delete().where(
                db.and_(
                    active_room_users.c.room_id == self.id,
                    active_room_users.c.username == username
                )
            )
        )
    
    def get_active_users(self):
        result = db.session.execute(
            db.select([active_room_users.c.username]).where(
                active_room_users.c.room_id == self.id
            )
        )
        return [row[0] for row in result]
    
    def is_user_active(self, username):
        result = db.session.execute(
            db.select([active_room_users]).where(
                db.and_(
                    active_room_users.c.room_id == self.id,
                    active_room_users.c.username == username
                )
            )
        ).first()
        return result is not None
*Created by: coderabbitai[bot]* _:warning: Potential issue_ **Consider using a proper many-to-many relationship for active users** The current implementation of storing active users as a comma-separated string has several issues: 1. Susceptible to injection if usernames contain commas 2. Race conditions possible in add/remove operations 3. Inefficient for querying and filtering 4. No validation of username format Consider using SQLAlchemy's association table pattern: ```python # Create an association table active_room_users = db.Table('active_room_users', db.Column('room_id', db.Integer, db.ForeignKey('room.id'), primary_key=True), db.Column('username', db.String(128), primary_key=True) ) class Room(db.Model): # ... existing fields ... active_users = db.relationship('UserSession', secondary=active_room_users, backref='active_rooms') def add_user(self, username): if not self.is_user_active(username): db.session.execute( active_room_users.insert().values( room_id=self.id, username=username ) ) def remove_user(self, username): db.session.execute( active_room_users.delete().where( db.and_( active_room_users.c.room_id == self.id, active_room_users.c.username == username ) ) ) def get_active_users(self): result = db.session.execute( db.select([active_room_users.c.username]).where( active_room_users.c.room_id == self.id ) ) return [row[0] for row in result] def is_user_active(self, username): result = db.session.execute( db.select([active_room_users]).where( db.and_( active_room_users.c.room_id == self.id, active_room_users.c.username == username ) ) ).first() return result is not None ``` <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:07:36 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

⚠️ Potential issue

Security concern: CSV-based user storage needs improvement.

Storing user lists as CSV in the database is prone to injection attacks and parsing errors.

  1. Replace CSV storage with a proper many-to-many relationship:
# models.py
class RoomUser(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    room_id = db.Column(db.Integer, db.ForeignKey('room.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    joined_at = db.Column(db.DateTime, default=datetime.utcnow)

class Room(db.Model):
    # ...
    users = db.relationship('User', secondary='room_user')
  1. Enhance username sanitization:
 function sanitizeUsername(username) {
-    // Split the username on commas and take the first part.
-    // The backend denormalizes the user list in the room table via csv.
-    return username.split(',')[0].trim();
+    // Sanitize username to prevent XSS and ensure valid format
+    return username
+        .trim()
+        .replace(/[<>]/g, '') // Remove potential HTML
+        .replace(/[,;]/g, '') // Remove delimiters
+        .substring(0, 50);    // Limit length
 }
*Created by: coderabbitai[bot]* _:warning: Potential issue_ **Security concern: CSV-based user storage needs improvement.** Storing user lists as CSV in the database is prone to injection attacks and parsing errors. 1. Replace CSV storage with a proper many-to-many relationship: ```python # models.py class RoomUser(db.Model): id = db.Column(db.Integer, primary_key=True) room_id = db.Column(db.Integer, db.ForeignKey('room.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) joined_at = db.Column(db.DateTime, default=datetime.utcnow) class Room(db.Model): # ... users = db.relationship('User', secondary='room_user') ``` 2. Enhance username sanitization: ```diff function sanitizeUsername(username) { - // Split the username on commas and take the first part. - // The backend denormalizes the user list in the room table via csv. - return username.split(',')[0].trim(); + // Sanitize username to prevent XSS and ensure valid format + return username + .trim() + .replace(/[<>]/g, '') // Remove potential HTML + .replace(/[,;]/g, '') // Remove delimiters + .substring(0, 50); // Limit length } ``` <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:07:36 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

🛠️ Refactor suggestion

Add indexes and constraints to UserSession model

The UserSession model would benefit from additional database optimizations:

  1. Add an index on session_id for faster lookups
  2. Add foreign key constraints
  3. Add created_at timestamp for session management
class UserSession(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    session_id = db.Column(db.String(128), unique=True, nullable=False, index=True)
    username = db.Column(db.String(128), nullable=False)
    room_name = db.Column(db.String(128), nullable=False)
    room_id = db.Column(db.Integer, db.ForeignKey('room.id', ondelete='CASCADE'))
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
*Created by: coderabbitai[bot]* _:hammer_and_wrench: Refactor suggestion_ **Add indexes and constraints to UserSession model** The UserSession model would benefit from additional database optimizations: 1. Add an index on session_id for faster lookups 2. Add foreign key constraints 3. Add created_at timestamp for session management ```python class UserSession(db.Model): id = db.Column(db.Integer, primary_key=True) session_id = db.Column(db.String(128), unique=True, nullable=False, index=True) username = db.Column(db.String(128), nullable=False) room_name = db.Column(db.String(128), nullable=False) room_id = db.Column(db.Integer, db.ForeignKey('room.id', ondelete='CASCADE')) created_at = db.Column(db.DateTime, default=datetime.utcnow) ``` <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:07:36 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

⚠️ Potential issue

Add rate limiting and validation to socket events

The socket event handlers need additional security measures:

  1. No rate limiting on join/disconnect events
  2. No validation of username format or length
  3. No maximum limit on users per room

Implement rate limiting and validation:

from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

limiter = Limiter(
    app=app,
    key_func=get_remote_address,
    default_limits=["200 per day", "50 per hour"]
)

def validate_username(username):
    if not username or len(username) > 128:
        raise ValueError("Invalid username length")
    if not re.match(r'^[\w\-]+$', username):
        raise ValueError("Username contains invalid characters")
    return username

@socketio.on("join")
@limiter.limit("10/minute")
def on_join(data):
    try:
        room_name = data["room_name"]
        username = validate_username(data["username"])
        room = get_room(room_name)
        
        # Check room capacity
        if len(room.get_active_users()) >= 100:  # Configurable limit
            raise ValueError("Room is full")
            
        # ... rest of the join logic ...
    except ValueError as e:
        emit("error", {"message": str(e)}, room=request.sid)
        return

Also applies to: 533-550

*Created by: coderabbitai[bot]* _:warning: Potential issue_ **Add rate limiting and validation to socket events** The socket event handlers need additional security measures: 1. No rate limiting on join/disconnect events 2. No validation of username format or length 3. No maximum limit on users per room Implement rate limiting and validation: ```python from flask_limiter import Limiter from flask_limiter.util import get_remote_address limiter = Limiter( app=app, key_func=get_remote_address, default_limits=["200 per day", "50 per hour"] ) def validate_username(username): if not username or len(username) > 128: raise ValueError("Invalid username length") if not re.match(r'^[\w\-]+$', username): raise ValueError("Username contains invalid characters") return username @socketio.on("join") @limiter.limit("10/minute") def on_join(data): try: room_name = data["room_name"] username = validate_username(data["username"]) room = get_room(room_name) # Check room capacity if len(room.get_active_users()) >= 100: # Configurable limit raise ValueError("Room is full") # ... rest of the join logic ... except ValueError as e: emit("error", {"message": str(e)}, room=request.sid) return ``` Also applies to: 533-550 <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:07:36 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

🛠️ Refactor suggestion

Eliminate code duplication in message chunk handling

The code for emitting message completion status is duplicated across multiple chat functions (chat_claude, chat_gpt, chat_mistral, chat_together, chat_groq, chat_llama).

Create a helper function to handle message completion:

def emit_message_completion(msg_id: int, room_name: str):
    """Helper function to emit message completion status and cleanup."""
    socketio.emit(
        "message_chunk",
        {"id": msg_id, "content": "", "is_complete": True},
        room=room_name
    )
    socketio.emit("delete_processing_message", msg_id, room=room_name)

# Usage in chat functions:
def chat_claude(...):
    try:
        # ... existing chat logic ...
    finally:
        emit_message_completion(msg_id, room_name)

This refactor:

  1. Reduces code duplication
  2. Ensures consistent message completion handling
  3. Makes it easier to modify the completion logic in one place

Also applies to: 1233-1238, 1345-1350, 1475-1480, 1587-1592, 1701-1706

*Created by: coderabbitai[bot]* _:hammer_and_wrench: Refactor suggestion_ **Eliminate code duplication in message chunk handling** The code for emitting message completion status is duplicated across multiple chat functions (chat_claude, chat_gpt, chat_mistral, chat_together, chat_groq, chat_llama). Create a helper function to handle message completion: ```python def emit_message_completion(msg_id: int, room_name: str): """Helper function to emit message completion status and cleanup.""" socketio.emit( "message_chunk", {"id": msg_id, "content": "", "is_complete": True}, room=room_name ) socketio.emit("delete_processing_message", msg_id, room=room_name) # Usage in chat functions: def chat_claude(...): try: # ... existing chat logic ... finally: emit_message_completion(msg_id, room_name) ``` This refactor: 1. Reduces code duplication 2. Ensures consistent message completion handling 3. Makes it easier to modify the completion logic in one place Also applies to: 1233-1238, 1345-1350, 1475-1480, 1587-1592, 1701-1706 <!-- This is an auto-generated comment by CodeRabbit -->
russellballestrini commented 2024-11-23 12:07:37 -05:00 (Migrated from git2.unturf.com)

Created by: coderabbitai[bot]

Review: Commented

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (5)
templates/chat.html (4)

16-58: Enhance accessibility with ARIA labels and descriptive text.

The utility belt UI should be more accessible to screen readers.

Apply these improvements:

-    <div class="utility-belt">
+    <div class="utility-belt" role="toolbar" aria-label="Chat utilities">
         <div class="download-links">
-            History
+            <span id="download-label">Download Chat History:</span>
-            <a href="/download_chat_history?room_name={{ room_name }}" download="{{ room_name }}.json">JSON</a> or
-            <a href="/download_chat_history_md?room_name={{ room_name }}" download="{{ room_name }}.md">Markdown</a>
+            <a href="/download_chat_history?room_name={{ room_name }}" 
+               download="{{ room_name }}.json"
+               aria-labelledby="download-label">JSON Format</a> or
+            <a href="/download_chat_history_md?room_name={{ room_name }}" 
+               download="{{ room_name }}.md"
+               aria-labelledby="download-label">Markdown Format</a>
         </div>
         <div>
-            <label for="model-select">Model</label>
+            <label for="model-select">AI Model Selection</label>
             <select id="model-select" aria-label="Select AI model">

68-74: Consider moving constants to a configuration file and enhancing validation.

The validation constants are well-defined but could be more maintainable.

Consider:

  1. Moving these constants to a separate config.js file
  2. Adding version information to models
  3. Adding metadata like pricing tier, availability, etc.

Example structure:

// config.js
export const AI_MODELS = {
  'None': { type: 'none', description: 'No AI model' },
  'gemini-pro': { 
    type: 'google',
    version: '1.0',
    pricing: 'paid',
    description: 'Google's Gemini Pro model'
  },
  // ... other models
};

export const TTS_VOICES = {
  'onyx': { provider: 'openai', gender: 'male', language: 'en-US' },
  // ... other voices
};

Line range hint 221-264: Enhance TTS implementation with rate limiting and better text processing.

The TTS implementation needs additional safeguards and improvements.

Consider these enhancements:

 async function speakText(text, playButton, messageId) {
     const voice = document.getElementById("voice-select").value;
     const cacheKey = `${messageId}-${voice}`;
 
+    // Rate limiting
+    if (window.lastTTSRequest && Date.now() - window.lastTTSRequest < 1000) {
+        console.warn('Rate limit: Please wait before requesting more TTS');
+        return;
+    }
+
+    // Improved text cleaning
+    const cleanText = text
+        .replace(/<[^>]*>/g, '') // Remove HTML tags
+        .replace(/```[\s\S]*?```/g, '') // Remove code blocks
+        .replace(/[^\w\s.,!?-]/g, '') // Keep only basic punctuation
+        .trim()
+        .slice(0, 4000); // Limit length
 
     try {
+        window.lastTTSRequest = Date.now();
         if (audioCache[cacheKey]) {

Line range hint 454-528: Optimize message chunk handling and improve error recovery.

The current implementation could be more robust and efficient.

Consider these improvements:

+    // Track chunk processing state
+    const processingState = {
+        buffer: messageBuffers[data.id] || '',
+        retryCount: 0,
+        maxRetries: 3
+    };
+
     // If the message wrapper doesn't exist, create it
     if (!messageWrapper) {
         messageWrapper = document.createElement("div");
         messageWrapper.className = "message-wrapper";
         messageWrapper.id = wrapperId;
+        // Add loading state
+        messageWrapper.dataset.state = 'loading';
         document.getElementById("chat").appendChild(messageWrapper);
     }
 
+    try {
+        // Batch DOM updates
+        const fragment = document.createDocumentFragment();
         targetMessageElement = document.createElement("div");
         targetMessageElement.className = "message-content";
-        messageWrapper.appendChild(targetMessageElement);
+        fragment.appendChild(targetMessageElement);
+        messageWrapper.appendChild(fragment);
+    } catch (error) {
+        console.error('Error processing chunk:', error);
+        if (processingState.retryCount < processingState.maxRetries) {
+            processingState.retryCount++;
+            // Retry after delay
+            setTimeout(() => processChunk(data), 1000 * processingState.retryCount);
+        }
+    }
app.py (1)

462-467: Implement session cleanup and expiration

The current session management lacks cleanup mechanisms for orphaned sessions and session expiration.

Add a cleanup mechanism:

def cleanup_stale_sessions():
    """Cleanup sessions older than 24 hours"""
    with app.app_context():
        expiration = datetime.utcnow() - timedelta(hours=24)
        stale_sessions = UserSession.query.filter(
            UserSession.created_at < expiration
        ).all()
        
        for session in stale_sessions:
            room = Room.query.get(session.room_id)
            if room:
                room.remove_user(session.username)
            db.session.delete(session)
        
        db.session.commit()

# Call periodically using a scheduler or cron job

Also applies to: 536-548

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0f82305087 and 5fa37da991.

📒 Files selected for processing (3)
  • app.py (12 hunks)
  • templates/base.html (5 hunks)
  • templates/chat.html (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • templates/base.html
🧰 Additional context used
📓 Learnings (1)
templates/chat.html (1)
Learnt from: russellballestrini
PR: russellballestrini/opencompletion#7
File: templates/chat.html:117-122
Timestamp: 2024-11-23T13:55:49.591Z
Learning: In the chat application, selecting `None` as the model means that no LLM should be used.
🔇 Additional comments (1)
templates/chat.html (1)

156-164: 🛠️ Refactor suggestion

Improve message format and add model validation.

The current implementation lacks proper separation between model prefix and message content.

Apply these improvements:

     const model = document.getElementById("model-select").value;
+    // Validate model selection
+    if (!VALID_MODELS.includes(model)) {
+        console.error('Invalid model selected');
+        return;
+    }
     let messageToSend = message.trim();

     if (model !== "None") {
-        messageToSend = `${model} ${messageToSend}`;
+        // Use JSON structure to prevent parsing ambiguity
+        messageToSend = JSON.stringify({
+            model: model,
+            content: messageToSend
+        });
     }

Likely invalid or redundant comment.

*Created by: coderabbitai[bot]* **Review:** Commented **Actionable comments posted: 5** <details> <summary>🧹 Outside diff range and nitpick comments (5)</summary><blockquote> <details> <summary>templates/chat.html (4)</summary><blockquote> `16-58`: **Enhance accessibility with ARIA labels and descriptive text.** The utility belt UI should be more accessible to screen readers. Apply these improvements: ```diff - <div class="utility-belt"> + <div class="utility-belt" role="toolbar" aria-label="Chat utilities"> <div class="download-links"> - History + <span id="download-label">Download Chat History:</span> - <a href="/download_chat_history?room_name={{ room_name }}" download="{{ room_name }}.json">JSON</a> or - <a href="/download_chat_history_md?room_name={{ room_name }}" download="{{ room_name }}.md">Markdown</a> + <a href="/download_chat_history?room_name={{ room_name }}" + download="{{ room_name }}.json" + aria-labelledby="download-label">JSON Format</a> or + <a href="/download_chat_history_md?room_name={{ room_name }}" + download="{{ room_name }}.md" + aria-labelledby="download-label">Markdown Format</a> </div> <div> - <label for="model-select">Model</label> + <label for="model-select">AI Model Selection</label> <select id="model-select" aria-label="Select AI model"> ``` --- `68-74`: **Consider moving constants to a configuration file and enhancing validation.** The validation constants are well-defined but could be more maintainable. Consider: 1. Moving these constants to a separate `config.js` file 2. Adding version information to models 3. Adding metadata like pricing tier, availability, etc. Example structure: ```javascript // config.js export const AI_MODELS = { 'None': { type: 'none', description: 'No AI model' }, 'gemini-pro': { type: 'google', version: '1.0', pricing: 'paid', description: 'Google's Gemini Pro model' }, // ... other models }; export const TTS_VOICES = { 'onyx': { provider: 'openai', gender: 'male', language: 'en-US' }, // ... other voices }; ``` --- Line range hint `221-264`: **Enhance TTS implementation with rate limiting and better text processing.** The TTS implementation needs additional safeguards and improvements. Consider these enhancements: ```diff async function speakText(text, playButton, messageId) { const voice = document.getElementById("voice-select").value; const cacheKey = `${messageId}-${voice}`; + // Rate limiting + if (window.lastTTSRequest && Date.now() - window.lastTTSRequest < 1000) { + console.warn('Rate limit: Please wait before requesting more TTS'); + return; + } + + // Improved text cleaning + const cleanText = text + .replace(/<[^>]*>/g, '') // Remove HTML tags + .replace(/```[\s\S]*?```/g, '') // Remove code blocks + .replace(/[^\w\s.,!?-]/g, '') // Keep only basic punctuation + .trim() + .slice(0, 4000); // Limit length try { + window.lastTTSRequest = Date.now(); if (audioCache[cacheKey]) { ``` --- Line range hint `454-528`: **Optimize message chunk handling and improve error recovery.** The current implementation could be more robust and efficient. Consider these improvements: ```diff + // Track chunk processing state + const processingState = { + buffer: messageBuffers[data.id] || '', + retryCount: 0, + maxRetries: 3 + }; + // If the message wrapper doesn't exist, create it if (!messageWrapper) { messageWrapper = document.createElement("div"); messageWrapper.className = "message-wrapper"; messageWrapper.id = wrapperId; + // Add loading state + messageWrapper.dataset.state = 'loading'; document.getElementById("chat").appendChild(messageWrapper); } + try { + // Batch DOM updates + const fragment = document.createDocumentFragment(); targetMessageElement = document.createElement("div"); targetMessageElement.className = "message-content"; - messageWrapper.appendChild(targetMessageElement); + fragment.appendChild(targetMessageElement); + messageWrapper.appendChild(fragment); + } catch (error) { + console.error('Error processing chunk:', error); + if (processingState.retryCount < processingState.maxRetries) { + processingState.retryCount++; + // Retry after delay + setTimeout(() => processChunk(data), 1000 * processingState.retryCount); + } + } ``` </blockquote></details> <details> <summary>app.py (1)</summary><blockquote> `462-467`: **Implement session cleanup and expiration** The current session management lacks cleanup mechanisms for orphaned sessions and session expiration. Add a cleanup mechanism: ```python def cleanup_stale_sessions(): """Cleanup sessions older than 24 hours""" with app.app_context(): expiration = datetime.utcnow() - timedelta(hours=24) stale_sessions = UserSession.query.filter( UserSession.created_at < expiration ).all() for session in stale_sessions: room = Room.query.get(session.room_id) if room: room.remove_user(session.username) db.session.delete(session) db.session.commit() # Call periodically using a scheduler or cron job ``` Also applies to: 536-548 </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 0f8230508763b020bf3e66c281aacee07c8bcd88 and 5fa37da9911aff8584eff68b54dea566287ae574. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `app.py` (12 hunks) * `templates/base.html` (5 hunks) * `templates/chat.html` (8 hunks) </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * templates/base.html </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>📓 Learnings (1)</summary> <details> <summary>templates/chat.html (1)</summary> ``` Learnt from: russellballestrini PR: russellballestrini/opencompletion#7 File: templates/chat.html:117-122 Timestamp: 2024-11-23T13:55:49.591Z Learning: In the chat application, selecting `None` as the model means that no LLM should be used. ``` </details> </details> </details> <details> <summary>🔇 Additional comments (1)</summary> <details> <summary>templates/chat.html (1)</summary> `156-164`: _:hammer_and_wrench: Refactor suggestion_ **Improve message format and add model validation.** The current implementation lacks proper separation between model prefix and message content. Apply these improvements: ```diff const model = document.getElementById("model-select").value; + // Validate model selection + if (!VALID_MODELS.includes(model)) { + console.error('Invalid model selected'); + return; + } let messageToSend = message.trim(); if (model !== "None") { - messageToSend = `${model} ${messageToSend}`; + // Use JSON structure to prevent parsing ambiguity + messageToSend = JSON.stringify({ + model: model, + content: messageToSend + }); } ``` > Likely invalid or redundant comment. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
russellballestrini commented 2024-11-23 12:17:19 -05:00 (Migrated from git2.unturf.com)

changed title from {-create grid column for room user list-} to {+Active User & Configuring Model & voice from Query Strings+}

changed title from **{-create grid column for room user list-}** to **{+Active User & Configuring Model & voice from Query Strings+}**
russellballestrini commented 2024-11-23 12:18:17 -05:00 (Migrated from git2.unturf.com)

Merged by: russellballestrini at 2024-11-23 17:18:17 UTC

*Merged by: russellballestrini at 2024-11-23 17:18:17 UTC*
russellballestrini (Migrated from git2.unturf.com) closed this pull request 2024-11-23 12:18:17 -05:00
russellballestrini (Migrated from git2.unturf.com) merged commit into main 2024-11-23 12:18:17 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: engineering/opencompletion.com#7
No description provided.