Skip to content

feature/ CG-71: Designed connection between extension and Added route, and api 'prompt', integration @xenova/transformers#10

Open
dithiane wants to merge 1 commit into
mainfrom
feature/CG-71
Open

feature/ CG-71: Designed connection between extension and Added route, and api 'prompt', integration @xenova/transformers#10
dithiane wants to merge 1 commit into
mainfrom
feature/CG-71

Conversation

@dithiane
Copy link
Copy Markdown
Member

Description

Implemented the connection between the extension and added a route and API for 'prompt' integration using @xenova/transformers.

Changes

  • Designed connection between the extension and welcome page (still in progress)
  • Integrated @xenova/transformers for prompt functionality

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2024

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

Name Status Preview Comments Updated (UTC)
base ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2024 4:01pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2024

Walkthrough

The project has undergone significant changes, including the addition of new components, updates to existing configurations, and enhancements to the Chrome extension. Notable updates include handling messages from a Chrome extension in React components, refining authentication middleware, and configuring webpack for development. The Chrome extension "CogniFusion" has been enriched with new features and dependencies.

Changes

Files/Directories Change Summary
app/(root)/page.tsx Added useEffect hook to handle messages from a Chrome extension.
app/(root)/prompt/page.tsx Introduced a new React component Prompt that renders a simple <div> element.
app/api/auth.ts Changed import statement for auth to reflect a new source.
app/api/prompt/route.ts Introduced GET and POST functions for handling API requests.
extention/.gitignore Added exclusion for /node_modules directory.
extention/build/... Updated multiple files (content.js, manifest.json, popup.html, popup.js) for Chrome extension.
extention/package.json Added scripts and dependencies for building and development using webpack.
extention/public/manifest.json Defined configuration settings for the "CogniFusion" extension.
extention/src/... Added and updated multiple files (background.js, content.js, popup.html, popup.js) for extension.
extention/webpack.config.js Configured webpack for development, including entry points and plugins.
middleware.ts Replaced authMiddleware with clerkMiddleware from @clerk/nextjs.
next.config.js Modified webpack configuration to add module resolution aliases.
package.json Updated and added dependencies, including @clerk/nextjs, @xenova/transformers, openai, and others.

In code we trust, with lines we weave,
New features bloom, like springtime leaves.
Extensions grow, components thrive,
In this vast sea, our app's alive.
With webpack's might and Clerk's embrace,
We build our dreams, a digital space.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@dithiane dithiane requested review from Foursharks and Hikky26 May 16, 2024 16:01
Copy link
Copy Markdown

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between df74169 and f09e76e.
Files ignored due to path filters (5)
  • extention/build/icons/icon-32.png is excluded by !**/*.png
  • extention/package-lock.json is excluded by !**/package-lock.json
  • extention/public/icons/icon-32.png is excluded by !**/*.png
  • package-lock.json is excluded by !**/package-lock.json
  • yarn.lock is excluded by !**/*.lock
Files selected for processing (19)
  • app/(root)/page.tsx (1 hunks)
  • app/(root)/prompt/page.tsx (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/prompt/route.ts (1 hunks)
  • extention/.gitignore (1 hunks)
  • extention/build/content.js (1 hunks)
  • extention/build/manifest.json (1 hunks)
  • extention/build/popup.html (1 hunks)
  • extention/build/popup.js (1 hunks)
  • extention/package.json (1 hunks)
  • extention/public/manifest.json (1 hunks)
  • extention/src/background.js (1 hunks)
  • extention/src/content.js (1 hunks)
  • extention/src/popup.html (1 hunks)
  • extention/src/popup.js (1 hunks)
  • extention/webpack.config.js (1 hunks)
  • middleware.ts (1 hunks)
  • next.config.js (1 hunks)
  • package.json (3 hunks)
Files skipped from review due to trivial changes (13)
  • app/(root)/prompt/page.tsx
  • extention/.gitignore
  • extention/build/content.js
  • extention/build/manifest.json
  • extention/build/popup.html
  • extention/build/popup.js
  • extention/package.json
  • extention/public/manifest.json
  • extention/src/content.js
  • extention/src/popup.html
  • extention/src/popup.js
  • middleware.ts
  • package.json
Additional comments not posted (12)
app/api/auth.ts (2)

3-3: Ensure the import change is correct.

Verification successful

Import change verified successfully

The import statement import { auth } from "@clerk/nextjs/server"; is correctly present in the app/api/auth.ts file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the import change from `@clerk/nextjs` to `@clerk/nextjs/server`.

# Test: Search for the import statement. Expect: Only occurances of the new import.
rg --type typescript $'import { auth } from "@clerk/nextjs/server"'

Length of output: 203



Script:

#!/bin/bash
# Description: Verify the import change from `@clerk/nextjs` to `@clerk/nextjs/server`.

# Test: Search for the import statement. Expect: Only occurrences of the new import.
rg --type typescript $'import \\{ auth \\} from "@clerk/nextjs/server"'

Length of output: 105



Script:

#!/bin/bash
# Description: Verify the import change from `@clerk/nextjs` to `@clerk/nextjs/server`.

# Test: Search for the import statement. Expect: Only occurrences of the new import.
rg --type ts $'import \\{ auth \\} from "@clerk/nextjs/server"'

Length of output: 123


3-3: LGTM! The import change aligns with the usage in the function.

app/api/prompt/route.ts (3)

3-5: Ensure the JSON response is correctly handled.


7-10: Ensure the prompt is correctly logged and returned.

Verification successful

The provided snippet of the POST function in app/api/prompt/route.ts correctly logs and returns the prompt. Here is the analysis:

  • The function extracts the prompt from the request body using await req.json().
  • It logs the prompt using console.log(prompt).
  • It returns the prompt in the response using new Response(prompt).

Therefore, the prompt is correctly logged and returned.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the prompt handling in the POST function.

# Test: Search for the POST function usage. Expect: Correct prompt handling.
rg --type typescript $'export async function POST'

Length of output: 86



Script:

#!/bin/bash
# Description: Verify the prompt handling in the POST function.

# Test: Search for the POST function usage. Expect: Correct prompt handling.
rg --type ts $'export async function POST'

Length of output: 110


3-10: LGTM! The response handling and logging are correct.

next.config.js (2)

23-31: Ensure the webpack configuration changes are correct.

Verification successful

Ensure the webpack configuration changes are correct.

The next.config.js file contains the following webpack configuration:

webpack: (config) => {
    // See https://webpack.js.org/configuration/resolve/#resolvealias
    config.resolve.alias = {
        ...config.resolve.alias,
        "sharp$": false,
        "onnxruntime-node$": false,
    }
    return config;
},

This configuration correctly sets the aliases for "sharp$" and "onnxruntime-node$" to false.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the webpack configuration changes.

# Test: Search for the webpack configuration. Expect: Correct alias settings.
rg --type javascript $'webpack: (config) =>'

Length of output: 80



Script:

#!/bin/bash
# Description: Verify the webpack configuration changes in next.config.js.

# Test: Search for the webpack configuration in next.config.js. Expect: Correct alias settings.
rg 'webpack: (config) =>' next.config.js

Length of output: 42



Script:

#!/bin/bash
# Description: Verify the webpack configuration changes in next.config.js.

# Test: Search for the webpack keyword in next.config.js. Expect: Correct alias settings.
rg 'webpack' next.config.js

Length of output: 128



Script:

#!/bin/bash
# Description: Extract and display the webpack configuration block from next.config.js to verify alias settings.

# Test: Extract the webpack configuration block. Expect: Correct alias settings.
rg -A 5 'webpack: (config) =>' next.config.js

Length of output: 47



Script:

#!/bin/bash
# Description: Extract and display the webpack configuration block from next.config.js to verify alias settings.

# Test: Extract the webpack configuration block with a larger context. Expect: Correct alias settings.
rg -A 10 'webpack: (config) =>' next.config.js

Length of output: 48



Script:

#!/bin/bash
# Description: Extract and display the webpack configuration block from next.config.js to verify alias settings.

# Test: Extract the webpack configuration block with an even larger context. Expect: Correct alias settings.
rg -A 20 'webpack: (config) =>' next.config.js

Length of output: 48



Script:

#!/bin/bash
# Description: Extract and display the entire content of next.config.js to verify webpack alias settings.

# Test: Extract the entire content of next.config.js. Expect: Correct alias settings.
cat next.config.js

Length of output: 885


23-31: LGTM! The webpack configuration changes are correct.

extention/webpack.config.js (2)

1-40: Ensure the webpack configuration is correct.


1-40: LGTM! The webpack configuration is correct.

app/(root)/page.tsx (3)

Line range hint 53-55: LGTM!


Line range hint 57-59: LGTM!


Line range hint 61-63: LGTM!

Comment on lines +5 to +18
class PipelineSingleton {
static task = 'text2text-generation';
static model = 'Xenova/LaMini-Flan-T5-783M';
static instance = null;

static async getInstance(progress_callback = null) {
if (this.instance === null) {
env.cacheDir = './.cache';
this.instance = await pipeline(this.task, this.model, { progress_callback });
}

return this.instance;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add error handling and comments for clarity.

Consider adding error handling to the getInstance method to handle potential issues with loading the model. Additionally, adding comments to explain the purpose of the class and its methods would improve readability.

class PipelineSingleton {
    static task = 'text2text-generation';
    static model = 'Xenova/LaMini-Flan-T5-783M';
    static instance = null;

    /**
     * Get the singleton instance of the pipeline.
     * @param {Function} progress_callback - Optional callback for progress updates.
     * @returns {Promise<Object>} The pipeline instance.
     */
    static async getInstance(progress_callback = null) {
        if (this.instance === null) {
            try {
                env.cacheDir = './.cache';
                this.instance = await pipeline(this.task, this.model, { progress_callback });
            } catch (error) {
                console.error("Error loading the model:", error);
                throw error;
            }
        }
        return this.instance;
    }
}

Comment on lines +20 to +28
const generate = async (text) => {
// Get the pipeline instance. This will load and build the model when run for the first time.

let model = await PipelineSingleton.getInstance();
// Actually run the model on the input text
let result = await model(text, { max_new_tokens: 100 });

return result
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add error handling and logging.

Consider adding error handling to the generate function to handle potential issues with the model. Additionally, adding logging would improve traceability.

const generate = async (text) => {
    try {
        // Get the pipeline instance. This will load and build the model when run for the first time.
        let model = await PipelineSingleton.getInstance();
        // Actually run the model on the input text
        let result = await model(text, { max_new_tokens: 100 });
        console.log("Generated result:", result);
        return result;
    } catch (error) {
        console.error("Error generating text:", error);
        throw error;
    }
};

Comment on lines +30 to +40
chrome.runtime.onMessage.addListener((message,
sender, sendResponse) => {
console.log(message)
if (message.action !== 'generate') return;
(async function () {

const result = await generate(message.text)
sendResponse(result);
})();
return true;
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add error handling and logging.

Consider adding error handling to the message listener to handle potential issues with message processing. Additionally, adding logging would improve traceability.

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    console.log("Message received:", message);
    if (message.action !== 'generate') return;
    (async function () {
        try {
            const result = await generate(message.text);
            sendResponse(result);
        } catch (error) {
            console.error("Error processing message:", error);
            sendResponse({ error: error.message });
        }
    })();
    return true;
});

Comment thread app/(root)/page.tsx
Comment on lines +71 to +88
useEffect(() => {
const handleMessage = (message: { data: any; }) => {
// Process the message received from the Chrome extension
console.log("Message received :", message.data);

// You can generate text and image based on the message here
};

window.addEventListener('message', (event) => {
if (event.source === window && event.data && event.data.from === 'ChromeExtension') {
handleMessage(event.data);
}
});

return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix the removal of the event listener.

The handleMessage function should be wrapped in an event listener function to ensure it is correctly removed in the cleanup function.

useEffect(() => {
    const handleMessage = (message: { data: any; }) => {
        // Process the message received from the Chrome extension
        console.log("Message received :", message.data);

        // You can generate text and image based on the message here
    };

    const eventListener = (event) => {
        if (event.source === window && event.data && event.data.from === 'ChromeExtension') {
            handleMessage(event.data);
        }
    };

    window.addEventListener('message', eventListener);

    return () => {
        window.removeEventListener('message', eventListener);
    };
}, []);

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.

Suggested change
useEffect(() => {
const handleMessage = (message: { data: any; }) => {
// Process the message received from the Chrome extension
console.log("Message received :", message.data);
// You can generate text and image based on the message here
};
window.addEventListener('message', (event) => {
if (event.source === window && event.data && event.data.from === 'ChromeExtension') {
handleMessage(event.data);
}
});
return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
useEffect(() => {
const handleMessage = (message: { data: any; }) => {
// Process the message received from the Chrome extension
console.log("Message received :", message.data);
// You can generate text and image based on the message here
};
const eventListener = (event) => {
if (event.source === window && event.data && event.data.from === 'ChromeExtension') {
handleMessage(event.data);
}
};
window.addEventListener('message', eventListener);
return () => {
window.removeEventListener('message', eventListener);
};
}, []);

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant