Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve clickable text with sentence content #388

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

Bran18
Copy link
Contributor

@Bran18 Bran18 commented Feb 24, 2025

Preview:

Screen.Recording.2025-02-24.at.1.35.06.PM.mov
Screen.Recording.2025-02-24.at.1.36.22.PM.mov

Sidenote: We need to rethink if we are going to make such a heavy follow-up question, they might affect the generation at some point

Summary by Sourcery

This pull request enhances the clickable text feature by providing the full sentence context to the AI when a user clicks on a text element. This allows the AI to generate more detailed and relevant responses.

New Features:

  • Improves the clickable text functionality by sending the full sentence context to the follow-up question, enhancing the AI's understanding and response generation.

Enhancements:

  • Updates the parseClickableText function to return the full context of the clickable text, which is then used to provide more detailed information in the follow-up question.
  • Modifies the click handler to include the full context when sending messages, ensuring that the AI has enough information to provide a comprehensive response.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced clickable text interactions by incorporating additional contextual information for more relevant messaging.
    • Introduced a new interface for parsed text that includes fullContext alongside clickableText and restText.
  • Refactor
    • Improved text parsing and context propagation to streamline the display and behavior of clickable text elements.
  • Bug Fixes
    • Removed outdated interface definitions to simplify the code structure.

@Bran18 Bran18 added the enhancement New feature or request label Feb 24, 2025
@Bran18 Bran18 self-assigned this Feb 24, 2025
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

This pull request updates the clickable text functionality by introducing a new fullContext parameter to enhance context handling. The changes propagate through the ClickableText component and related utilities by updating method signatures in the chat component, revising the return structure of the text parsing functions, and adjusting interface declarations. These modifications ensure that context-rich, detailed messages are sent on text interactions.

Changes

File(s) Change Summary
.../components/routes/chat/chat-clickable-text.tsx Updated createClickHandler and renderClickableContent to accept an additional fullContext parameter. Updated calls to parseClickableText to extract fullContext alongside clickableText and restText.
.../lib/clickable-results.ts Modified parseClickableText to return an object containing clickableText, restText, and fullContext. Removed the old ParsedText interface and updated URL, unique phrase, and title match handling.
.../lib/utils.ts Removed the ParsedText interface that previously defined clickableText and restText.
.../types/types.ts Added a new ParsedText interface with properties: clickableText, restText, and fullContext (all of type string).

Sequence Diagram(s)

sequenceDiagram
    participant UI as ClickableText Component
    participant Parser as parseClickableText
    participant Handler as createClickHandler
    participant Msg as sendMessageFromResponse

    UI->>Parser: Call parseClickableText(fullText)
    Parser-->>UI: Return {clickableText, restText, fullContext}
    UI->>Handler: Call createClickHandler(text, fullContext)
    Handler->>Msg: sendMessageFromResponse(fullContext or cleanedText)
Loading

Possibly related PRs

Suggested reviewers

  • AndlerRL

Poem

I hop through lines of code so light,
Enhancing text with context bright,
With every parameter, a new delight,
Clickable magic in the night,
A mindful rabbit sings: "Coding’s pure delight!" 🐇💻

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/masterbots.ai/lib/clickable-results.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/masterbots.ai/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Feb 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
masterbots ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2025 8:50pm

Copy link

sourcery-ai bot commented Feb 24, 2025

Reviewer's Guide by Sourcery

This pull request enhances the clickable text functionality by incorporating the full sentence context into follow-up questions. It modifies the createClickHandler function to utilize this context and updates the parseClickableText function to extract and return the full context. A fullContext property was added to the ParsedText interface.

Sequence diagram for Clickable Text Interaction

sequenceDiagram
    participant User
    participant ClickableText Component
    participant sendMessageFromResponse

    User->>ClickableText Component: Clicks on clickableText
    ClickableText Component->>ClickableText Component: createClickHandler(clickableText, fullContext)
    ClickableText Component->>sendMessageFromResponse: sendMessageFromResponse(`Explain more in-depth and in detail about ${contextToUse}`)
    sendMessageFromResponse-->>User: Displays detailed explanation
Loading

Updated class diagram for ParsedText

classDiagram
    class ParsedText {
      clickableText: string
      restText: string
      fullContext: string
    }
Loading

File-Level Changes

Change Details Files
Modified the createClickHandler function to accept and utilize the full sentence context when sending messages, enhancing the detail of follow-up questions.
  • Modified createClickHandler to accept a fullContext parameter.
  • Updated sendMessageFromResponse to use fullContext when available, otherwise falling back to the cleaned clickable text.
apps/masterbots.ai/components/routes/chat/chat-clickable-text.tsx
Enhanced the parseClickableText function to extract and return the full context of the clickable text, improving the accuracy and relevance of follow-up questions.
  • Modified parseClickableText to return a fullContext property in the ParsedText interface.
  • Updated the logic to store the full context when unique phrases are detected.
  • Adjusted the logic to include the full text as context when no specific title or phrase is matched.
apps/masterbots.ai/lib/clickable-results.ts
Added a fullContext property to the ParsedText interface to support the enhanced context handling for clickable text.
  • Added the fullContext property to the ParsedText interface definition.
apps/masterbots.ai/types/types.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Bran18 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a configuration option to control the verbosity of the follow-up questions.
  • The parseClickableText function could be simplified by extracting common logic into smaller, more focused functions.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
apps/masterbots.ai/lib/clickable-results.ts (2)

149-150: Improve variable naming for clarity.

The variable name restContent could be more descriptive to better reflect its purpose.

-      const restContent = rest.join(phrase);
+      const remainingContent = rest.join(phrase);

153-153: Maintain consistent comment style.

The comment style varies between lines using //* and //?. Standardize the comment style for better maintainability.

-        fullContext: phrase + restContent, //* Store the full context
+        fullContext: phrase + restContent, // Store the full context
-      fullContext: fullText, //? Stores the full context
+      fullContext: fullText, // Store the full context

Also applies to: 176-176

apps/masterbots.ai/components/routes/chat/chat-clickable-text.tsx (2)

29-32: Improve fallback logic clarity.

The fallback logic could be more explicit using nullish coalescing operator.

-      const contextToUse = fullContext || cleanedText
+      const contextToUse = fullContext ?? cleanedText
       sendMessageFromResponse(
-        `Explain more in-depth and in detail about ${contextToUse}`
+        `Please provide more detailed information about "${contextToUse}"`
       )

140-142: Standardize fallback pattern usage.

The fallback pattern here differs from the one used in contextToUse. Consider standardizing the approach.

-                  fullContext || strongContent
+                  fullContext ?? strongContent
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 790a9b0 and 276273c.

📒 Files selected for processing (4)
  • apps/masterbots.ai/components/routes/chat/chat-clickable-text.tsx (8 hunks)
  • apps/masterbots.ai/lib/clickable-results.ts (3 hunks)
  • apps/masterbots.ai/lib/utils.ts (0 hunks)
  • apps/masterbots.ai/types/types.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/masterbots.ai/lib/utils.ts
🔇 Additional comments (1)
apps/masterbots.ai/types/types.ts (1)

359-363: Well-structured interface with clear documentation!

The ParsedText interface is well-defined with clear property descriptions that align with the feature's requirements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
apps/masterbots.ai/lib/clickable-results.ts (1)

135-196: Improve code maintainability and documentation.

Consider the following improvements:

  1. Extract the sentence extraction logic into a reusable function
  2. Add input validation
  3. Add JSDoc comments

Here's a suggested refactor:

+/**
+ * Extracts the first sentence from a text.
+ * @param text The text to extract from
+ * @returns The first sentence or the entire text if no sentence boundary is found
+ */
+function extractFirstSentence(text: string): string {
+  const match = text.match(/^(.+?\.)(?:\s|$)/);
+  return match ? match[1] : text;
+}
+
+/**
+ * Parses text to extract clickable segments and their context.
+ * @param fullText The text to parse
+ * @returns Object containing clickable text, rest of the text, and full context
+ * @throws {Error} If fullText is null or undefined
+ */
 export function parseClickableText(fullText: string): ParsedText {
+  if (!fullText) {
+    throw new Error('fullText cannot be null or undefined');
+  }
+
   if (typeof fullText === 'string' && fullText.match(/https?:\/\/[^\s]+/)) {
     // ... rest of the function
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 276273c and 5e34e0d.

📒 Files selected for processing (1)
  • apps/masterbots.ai/lib/clickable-results.ts (3 hunks)
🔇 Additional comments (1)
apps/masterbots.ai/lib/clickable-results.ts (1)

1-1: LGTM! Good architectural change.

Moving the ParsedText interface to a centralized types file improves maintainability and reduces duplication.

Copy link
Member

@AndlerRL AndlerRL left a comment

Choose a reason for hiding this comment

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

LGTM! The refactor might help to improve the Ai context and response quality with the followingQuestions feature. I added a new audit issue to track this update and audit potential improvements. Merging for tests!

@Bran18
Copy link
Contributor Author

Bran18 commented Feb 24, 2025

Preview after changes

Screenshot 2025-02-24 at 2 41 47 PM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/masterbots.ai/lib/clickable-results.ts (3)

144-161: Enhance sentence extraction pattern for better coverage.

The current regex pattern only handles periods. Consider expanding it to handle other sentence-ending punctuation marks.

-      const firstSentenceMatch = (phrase + restContent).match(/^(.+?\.)(?:\s|$)/)
+      const firstSentenceMatch = (phrase + restContent).match(/^(.+?[.!?])(?:\s|$)/)

178-183: Enhance title sentence extraction pattern.

Similar to the unique phrases section, expand the pattern to handle more sentence endings.

-    const firstSentenceMatch = content.match(/^(.+?\.)(?:\s|$)/);
+    const firstSentenceMatch = content.match(/^(.+?[.!?])(?:\s|$)/);

178-188: Improve code organization and readability.

Consider extracting the sentence extraction logic into a reusable function since it's used in multiple places.

+function extractFirstSentence(text: string): string {
+  const match = text.match(/^(.+?[.!?])(?:\s|$)/);
+  return match ? match[1] : text;
+}

 // In the title handling section:
-    const firstSentenceMatch = content.match(/^(.+?\.)(?:\s|$)/);
-    const firstSentence = firstSentenceMatch 
-      ? title + ': ' + firstSentenceMatch[1] 
-      : title + ': ' + content;
+    const firstSentence = title + ': ' + extractFirstSentence(content);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e34e0d and 33725b3.

📒 Files selected for processing (1)
  • apps/masterbots.ai/lib/clickable-results.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/masterbots.ai/lib/clickable-results.ts (2)
Learnt from: AndlerRL
PR: bitcashorg/masterbots#388
File: apps/masterbots.ai/lib/clickable-results.ts:148-149
Timestamp: 2025-02-24T20:46:17.229Z
Learning: Issue #389 is being used to track items for a code audit in the masterbots project.
Learnt from: AndlerRL
PR: bitcashorg/masterbots#388
File: apps/masterbots.ai/lib/clickable-results.ts:148-149
Timestamp: 2025-02-24T20:46:17.229Z
Learning: Issue #389 is tracking potential improvements and refactoring needs for the ClickableText component, including the evaluation of using context objects instead of multiple parameters.
🔇 Additional comments (2)
apps/masterbots.ai/lib/clickable-results.ts (2)

1-4: LGTM! Clean import organization.

The import changes properly separate type imports from runtime imports.


136-142: LGTM! Proper URL handling with context.

The URL handling logic correctly preserves the full text as context while maintaining existing behavior.

@AndlerRL AndlerRL merged commit 7adcf33 into develop Feb 24, 2025
2 checks passed
@AndlerRL AndlerRL deleted the refactor-clickable-results branch February 24, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants