運用 AI 評估產品評論

Maud Nalpas
Maud Nalpas
Kenji Baheux
Kenji Baheux
Alexandra Klepper
Alexandra Klepper

線上購物時,想掌握大量產品量可能會令人眼花撩亂 和供應的產品數量我們該如何排序 找出能真正滿足我們特定需求的產品?

舉例來說,假設我們要購買工作背包,背包必須見證 在功能、美學和實用性之間取得平衡評論數是指 沒想到你能否找到完美的包包?不如我們能 運用 AI 過濾雜訊,找出最適合的產品。

實用的功能是列出所有評論的摘要,以及大多數評論的清單 常見的優缺點

使用者評論範例 (正面和負面)。
內含星級評等及優缺點清單的使用者評論範例。

為建構這項功能,我們採用伺服器端生成式 AI。推論發生在伺服器上。

也可按照 Gemini API with Node.js, 使用 Google AI JavaScript SDK,總結許多評論的資料。我們著重於 生成式 AI 的部分我們不會說明如何儲存結果 或建立工作佇列

實務上,任何 SDK 皆可使用任何 LLM API。不過, 您可能需要調整建議提示,以符合所選模型

必備條件

  1. 建立 Gemini API 的金鑰。 並在您的環境檔案中定義該版本。

  2. 安裝 Google AI JavaScript SDK,例如使用 npm: npm install @google/generative-ai

建構評論摘要應用程式

  1. 初始化生成式 AI 物件
  2. 建立用來產生評論摘要的函式。
    1. 選取生成式 AI 模型。針對我們的用途,我們會使用 Gemini Pro。使用 專屬於你的用途的模型,例如 gemini-pro-vision 多模態輸入)。
    2. 新增提示。
    3. 呼叫 generateContent,將提示做為引數傳遞。
    4. 產生並傳回回應。
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;
}

撰寫有效提示

若想充分發揮生成式 AI 的妙用,最好的方式就是生成詳盡提示。在本例中,我們使用單樣本提示技術取得一致的輸出內容。

單樣本提示會表示 Gemini 用來訓練模型的輸出內容。

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):`;

以下是這個提示的輸出內容範例 評論,以及常見優缺點清單

## 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.

符記限制

許多審查作業都可能會達到模型的符記限制。符記不一定等於 單一字詞符記可以是字詞的部分內容,也可以是多個字詞組合。適用對象 比方說,Gemini Pro 獲得的 最多 30,720 個符記這表示提示中最多可以有 600 包含 30 字的英文評論,不含其餘提示操作說明。

使用 countTokens() 檢查符記數量,如果提示大於 。

const MAX_INPUT_TOKENS = 30720
const { totalTokens } = await model.countTokens(prompt);
if (totalTokens > MAX_INPUT_TOKENS) {
    // Shorten the prompt.
}

打造適合企業的應用程式

如果您是 Google Cloud 使用者或需要企業支援, 存取 Gemini Pro 等更多模型,例如 Anthropic 的 Claude 模型, Vertex AI建議使用 模型園地:判斷哪個模型 最符合您的用途

後續步驟

我們打造的應用程式非常仰賴品質審查 有效的摘要如要收集這些品質評論,請參閱 這個系列已成為 運用裝置端網頁 AI 協助使用者撰寫實用的產品評論

我們想聽聽您對這個做法的想法。請說明大多數用途 您的興趣。你可以 提供意見回饋並加入搶先體驗計畫 使用本機原型來測試這項技術

你的貢獻可以幫助我們打造強大而實用的 AI 工具 大家都愛不釋手

下一步:協助使用者撰寫實用的產品評論