Evaluate product reviews with AI  |  AI on Chrome  |  Chrome for Developers Skip to main content Docs Build with Chrome Learn how Chrome works, participate in origin trials, and build with Chrome everywhere. Web Platform Capabilities ChromeDriver Extensions Chrome Web Store Chromium Web on Android Origin trials Release notes Productivity Create the best experience for your users with the web's best tools. DevTools Lighthouse Chrome UX Report Accessibility Modern Web Guidance Get things done quicker and neater, with our ready-made libraries. Workbox Puppeteer Experience Design a beautiful and performant web with Chrome. AI Performance CSS and UI Identity Payments Privacy and security Resources More from Chrome and Google. All documentation Baseline web.dev PageSpeed Insights audit Isolated Web Apps (IWA) Case studies Blog New in Chrome / English Deutsch Español – América Latina Français Indonesia Italiano Nederlands Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어 Sign in Docs AI on Chrome Built-in AI Get started APIs and best practices Best practices WebMCP Learn Evals Accelerate compute AI in Chrome DevTools AI assistance AI in Extensions Docs More Built-in AI More WebMCP Learn Evals Accelerate compute AI in Chrome More Case studies Blog New in Chrome Built-in AI What is built-in AI? Get started Benefits of client-side AI Join the EPP Try the demos APIs API status and overview Summarizer API Get started Summarize in small context windows Language Detector API Translator API Prompt API Get started Session management Session compacting Structured output Writer API Rewriter API Proofreader API Polyfill for Prompt API Polyfill for task APIs Build with AI Case studies Enhance blogging with the Prompt API Support multilingual experiences Create engaging article summaries Create helpful user review summaries Translate on-device Client-side or server-side AI Encourage better reviews with client-side AI Evaluate reviews with server-side AI Extensions and AI Hybrid AI with Firebase AI Logic Best practices Cache models Stream LLM responses Render streamed LLM responses Debug the built-in model Inform users of model download Understand model management in Chrome Built-in AI do and don't Resources Meet the Chrome team Glossary and concepts Gemini API in Node.js Gemini API in web apps AI on Web.dev Build with Chrome Web Platform Capabilities ChromeDriver Extensions Chrome Web Store Chromium Web on Android Origin trials Release notes Productivity DevTools Lighthouse Chrome UX Report Accessibility Modern Web Guidance Workbox Puppeteer Experience AI Performance CSS and UI Identity Payments Privacy and security Resources All documentation Baseline web.dev PageSpeed Insights audit Isolated Web Apps (IWA) Get started APIs and best practices Best practices DevTools AI assistance AI in Extensions Home Docs AI on Chrome Built-in AI Evaluate product reviews with AI Stay organized with collections Save and categorize content based on your preferences. Maud Nalpas GitHub LinkedIn Bluesky Kenji Baheux Alexandra Klepper GitHub Bluesky Published: May 16, 2024 When shopping online, it can be overwhelming to see the volume of product reviews and the volume of products available. How can we sort through all of this noise to find the product that will actually meet our specific needs? For example, say we're shopping for a work backpack. Backpacks need to meet a balance in function, aesthetics, and practicality. The number of reviews makes it nearly impossible to know if you have found the perfect bag. What if we could use AI to sift through the noise and find the perfect product? What would be helpful is a summary of all reviews, alongside a list of most common pros and cons. An example user review with a star rating and a pros and cons list. To build this, we use server-side generative AI. Inference occurs on a server. In this document, you can follow along with a tutorial for the Gemini API with Node.js, using the Google AI JavaScript SDK to summarize data from many reviews. We focus on the generative AI portion of this work; we won't cover how to store results or create a job queue. In practice, you could use any LLM API with any SDK. However, the suggested prompt may need to be adapted to meet the model you choose. Prerequisites Create a key for the Gemini API, and define it in your environment file. Tip: Remember to treat your API keys as secrets: don't check them into source control. Restrict their scope to your website. Use a separate key for local development. Install the Google AI JavaScript SDK, for example with npm: npm install @google/generative-ai Build a review summarizer application Initialize a generative AI object. Create a function to generate review summaries. Select the generative AI model. For our use case, we'll use Gemini Pro. Use a model that's specific to your use case (for example, gemini-pro-vision is for multimodal input). Add a prompt. Call generateContent to pass the prompt as an argument. Generate and return the response. const { GoogleGenerativeAI } = require("@google/generative-ai"); // Access the API key env const genAI = new GoogleGenerativeAI(process.env.API_KEY_GEMINI); async function generateReviewSummary(reviews) { // Use gemini-pro model for text-only input const model = genAI.getGenerativeModel({ model: "gemini-pro" }); // Shortened for legibility. See "Write an effective prompt" for // writing an actual production-ready prompt. const prompt = `Summarize the following product reviews:\n\n${reviews}`; const result = await model.generateContent(prompt); const response = await result.response; const summary = response.text(); return summary; } Caution: Reviews come (mostly) from real humans and thus are often attached to information which could be considered personally-identifying information (PII). PII isn't useful for summarization tasks and may negatively impact the quality. Always remove any potential PII before sharing data with any AI model. Write an effective prompt The best way to be successful with generative AI is to create a thorough prompt. In this example, we've used the one-shot prompting technique to get consistent outputs. Tip: Consider using Google AI Studio for prompt engineering and iteration. One-shot prompting is represented by the example output for Gemini to model. const prompt = `I will give you user reviews for a product. Generate a short summary of the reviews, with focus on the common positive and negative aspects across all of the reviews. Use the exact same output format as in the example (list of positive highlights, list of negative aspects, summary). In the summary, address the potential buyer with second person ("you", "be aware"). Input (list of reviews): // ... example Output (summary of reviews): // ... example **Positive highlights** // ... example **Negative aspects** // ... example **Summary** // ... example Input (list of reviews): ${reviews} Output (summary of all input reviews):`; Here's an example output from this prompt, which includes a summary of all reviews, alongside a list of common pros and cons. ## Summary of Reviews: **Positive highlights:** * **Style:** Several reviewers appreciate the backpack's color and design. * **Organization:** Some users love the compartments and find them useful for organization. * **Travel & School:** The backpack seems suitable for both travel and school use, being lightweight and able to hold necessary items. **Negative aspects:** * **Durability:** Concerns regarding the zipper breaking and water bottle holder ripping raise questions about the backpack's overall durability. * **Size:** A few reviewers found the backpack smaller than expected. * **Material:** One user felt the material was cheap and expressed concern about its longevity. **Summary:** This backpack seems to be stylish and appreciated for its organization and suitability for travel and school. However, you should be aware of potential durability issues with the zippers and water bottle holder. Some users also found the backpack smaller than anticipated and expressed concerns about the material's quality. Token limits Many reviews can hit the model's token limit. Tokens aren't always equal to a single word; a token can be parts of a word or multiple words together. For example, Gemini Pro has a 30,720 token limit. This means the prompt can include, at-most, 600 average 30-word reviews in English, minus the rest of the prompt instructions. Use countTokens() to check the number of tokens and reduce the input if the prompt is larger than allowed. const MAX_INPUT_TOKENS = 30720 const { totalTokens } = await model.countTokens(prompt); if (totalTokens > MAX_INPUT_TOKENS) { // Shorten the prompt. } Build for enterprise If you're a Google Cloud user or otherwise need enterprise support, you can access Gemini Pro and more models, such as Anthropic's Claude models, with Gemini Enterprise Agent Platform. You may want to use Model Garden to determine which model best matches your specific use case. Next steps The application we built relies heavily on quality reviews to give the most effective summaries. To collect those quality reviews, read the next article in this series is Help users write useful product reviews with on-device web AI. We want to hear from you about this approach. Tell us what use cases most interest you. You can share your feedback and join the Early Preview Program to test this technology with local prototypes. Your contribution can help us make AI a powerful, yet practical, tool for everyone. Next: Help users write useful product reviews Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2024-05-16 UTC. [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-16 UTC."],[],[]] Contribute File a bug See open issues Related content Chromium updates Case studies Archive Podcasts & shows Follow @ChromiumDev on X YouTube Chrome for Developers on LinkedIn RSS Terms Privacy Manage cookies English Deutsch Español – América Latina Français Indonesia Italiano Nederlands Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어