利用 AI 评估商品评价

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

在线购物时,如果看到大量的商品,可能会感到应接不暇 评价和可售商品的数量。我们该如何整理 找出真正能满足我们特定需求的产品?

例如,假设我们要购买一个工作背包。背包需要满足 兼顾功能、美学和实用性评价数量 几乎不可能知道自己找到的包包是否完美。如果我们能 如何利用 AI 从各种干扰信息中过滤出理想的商品?

建议您提供所有评价的摘要,以及最常见评价的列表。 共同的优点和缺点

<ph type="x-smartling-placeholder">
</ph> 包含正面和负面亮点的用户评价示例。
包含星级和优缺点列表的用户评价示例。

为此,我们使用服务器端生成式 AI。推理在服务器上进行。

在本文档中,您可以 基于 Node.js 的 Gemini API, 使用 Google AI JavaScript SDK 总结众多评价中的数据。我们专注于 生成式 AI 方面的知识;我们不会介绍如何存储搜索结果 或创建作业队列。

在实践中,您可以将任何 LLM API 与任何 SDK 搭配使用。不过, 建议的提示可能需要经过调整,以符合您选择的模型。

前提条件

  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() 检查词元数量,并在提示大于 0 时减少输入 允许。

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。您可能希望使用 Model Garden 来确定使用哪个模型 与您的具体应用场景最匹配。

后续步骤

我们构建的应用在很大程度上依赖于质量审核 有效总结。要收集这些质量评价,请阅读 本系列是 使用设备端 Web AI 帮助用户撰写实用的商品评价

我们想听听您对这种方法的看法。告诉我们哪些应用场景最广 。您可以 欢迎分享反馈并加入抢先试用计划 使用本地原型测试这项技术

您的贡献有助于我们将 AI 打造成强大而实用的工具, 所有人。

下一页:帮助用户撰写实用的商品评价