发布时间:2025 年 5 月 15 日
包含用户评价的网站(例如电子商务网站或旅游网站)通常包含大量信息。这可能会导致用户花费大量时间来过滤大量评价,以便做出购买决定。提供评价摘要有助于用户了解反馈并节省时间。了解 redBus 和 Miravia 如何使用 Summarizer API 来改进决策制定和购买体验。
解说 | Web | 扩展程序 | Chrome 状态 | 意向 |
---|---|---|---|---|
GitHub | 视图 | 意图进行实验 |
借助 Summarizer API,您可以生成不同类型、不同长度和不同格式的摘要,例如句子、段落、项目符号列表等。与我们的许多内置 AI API 一样,此 API 使用 Gemini Nano 执行推理。
redBus 帮助客户选择最佳巴士方案
redBus 是印度最大的巴士提供商,拥有超过 3,000 万客户,在全国约 1 万个城镇提供巴士服务。通过数据和反馈,redBus 意识到,用户生成的评价在帮助客户确定最符合其旅行需求的路线和巴士方面发挥着重要作用。redBus 收到大量评价,每条评价都具体说明了确切的到达和出发点以及时间。
为了帮助客户大致了解特定城市或路线,他们使用 Summarizer API 来呈现相关评价中的关键数据洞见。
“Summarizer API 能够根据我们的大量评价和用户搜索查询排列组合创建优质摘要。此客户端功能消除了服务器端替代方案所带来的技术复杂性和额外业务开销。这对我们来说很重要,因为此用例属于转化漏斗的一部分。”
- Amit Kumar,redBus 高级工程经理
存储在 redBus 后端的评价的粒度,再加上用户搜索查询中可能存在的大量排列组合(包括出发时间和到达时间、城市中的具体上车点和不同的巴士运营商等变量),使得从评价中找出具体数据洞见变得非常困难。如此庞大的数据量,如果为每个搜索查询生成服务器端摘要,费用将会非常高昂。
为了生成有效的摘要,除了客户评价之外,redBus 还向 Summarizer API 提供了以下背景信息:
//Context to provide a useful summary
const promptContext =
'Summarize the following reviews in 30 words or less.' +
'Focus on key positives and negatives, such as comfort, maintenance,' +
'pricing, and cleanliness. Reviews are separated by {end}.' +
'Give the summary in just one paragraph.';
这些摘要有助于客户做出更明智的决策,而无需额外承担业务费用和技术复杂性。此外,redBus 还可以根据已登录用户的旅行偏好(例如座椅舒适度或 Wi-Fi 可用性)对摘要进行个性化设置。在客户端进行推理,这意味着此搜索和摘要仍会保留为用户的私密信息。
请查看以下简短代码示例,了解如何根据用户的搜索查询检查摘要生成器的可用性、提供上下文信息以及检索评价。
// The Summarizer API is available
if ('Summarizer' in self) {
try {
const available = await Summarizer.availability();
let summarizer;
if (available === 'unavailable') {
return null;
}
if (available === 'available') {
//model is already available, use immediately
summarizer = await Summarizer.create();
} else {
//trigger model download and wait
summarizer = await Summarizer.create();
}
// Context to provide a useful summary
const promptContext =
'Summarize the following reviews in 30 words or less.' +
'Focus on key positives and negatives, such as comfort, maintenance,' +
'pricing, and cleanliness. Reviews are separated by {end}.' +
'Give the summary in just one paragraph.';
// Retrieve the reviews to be summarized based on user's search query
let reviews = getIndividualBusReviews();
if (reviews) {
const reviewSummary = await summarizer.summarize(reviews, {
context: promptContext
});
}
} catch (e) {
console.error("SUMMARIZER_API_ERROR: ", e);
return null
}
}
以从班加罗尔到曼加罗尔的搜索为例,摘要生成器的输出如下所示:
<Bus Provider X>
通常因舒适度、清洁度和员工服务而获得好评。部分乘客遇到了一些小问题,例如延迟、司机行为(粗鲁)、缺少设施(实时跟踪、毯子)和舒适度不佳(座椅尺寸、减震器不佳)。
此评价符合要求,将正面和负面评价都包含在一个简短的段落中,比 308 条单独的评价更易于阅读。
Miravia 总结了电子商务评价
Miravia 是西班牙领先的电子商务平台,每月活跃用户数达数百万。每当用户过滤评价(例如按商品评分过滤)时,系统都会生成新的摘要。这会简要概述客户反馈,突出显示问题和建议。
“以前,用户若要了解商品评价中的关键优缺点,就必须阅读详情页面上的大量个别评论。为了帮助用户快速掌握整体客户情绪,我们推出了 Summarizer API。每当用户过滤评价(例如按星级或其他条件过滤)时,此摘要都会动态更新,以便快速全面地了解相关买家反馈。”
- Miravia 高级软件工程师 Ziyi Liang
最初,Miravia 的用户评价摘要功能依赖于服务器端 AI 服务。他们发现,运行客户端 AI 的 Gemini Nano 可以提供类似的结果,同时降低维护费用。对于热门的畅销商品(其评价会不断更新),这一优势尤为明显。
虽然 Miravia 的实现需要实时提取和总结评价,但无论推理是在服务器上还是在浏览器中进行,随着频率的增加,客户端 AI 的效率会显著提高。他们对其整体表现感到满意。
首先,Miravia 会检查功能和设备兼容性。
// Compatibility check for device with built-in AI
export const deviceCheck = async () => {
// Query the browser's AI capabilities
const availability = await Summarizer.availability();
// Case 1: Device doesn't support AI summarization
if (availability === 'unavailable') {
return {
summarizationAvailable: false,
message:
'AI summarization tools are not supported on this device, or the appropriate permissions have not be set.',
};
}
// Case 2: Device supports AI but requires model download
if (availability === 'downloadable') {
// Try to trigger an installation
Summarizer.create();
return {
summarizationAvailable: false,
message: 'Installing in the background. This may take a few minutes...',
};
}
// Case 3: Device supports AI summarization
return {
summarizationAvailable: true,
message: 'Ready for use.',
};
};
然后,Miravia 会汇总可用的评价。评价会附加一个额外的英文句号,以使输入内容更连贯。
/**
* Summarizes a list of reviews using Chrome's Built-in AI
* @param {Array<string>} reviewContentList - Array of review texts to summarize
* @returns {Promise<string>} The generated summary text
* @throws {Error} If summarization is not available or fails
*/
export const reviewSummarize = async (reviewContentList) => {
// Validate input
if (!Array.isArray(reviewContentList) || !reviewContentList.length) {
throw new Error('Please provide a non-empty array of reviews to summarize');
}
// Check device compatibility
const { summarizationAvailable, message } = await deviceCheck();
if (summarizationAvailable) {
try {
// Configure and create the summarizer with appropriate parameters
const summarizer = await Summarizer.create({
type: 'tl;dr',
length: 'short',
sharedContext:
'Summarize the given user reviews. Maintain a polite and formal tone.',
});
// Generate the summary from the joined review texts
const summary = await summarizer.summarize(reviewContentList.join('. '));
// Return the generated summary
return summary;
} catch (error) {
// Handle any errors during summarization
throw new Error(`Summarization failed: ${error.message}`);
}
} else {
// If summarization is not available, throw an error with the message from deviceCheck
throw new Error(
message ||
'AI summarization tools are not supported on this device or browser.'
);
}
};
最佳做法
如果评价输入超出令牌数上限,请采取以下缓解措施:
- 向 API 使用较小的样本(例如最近 4 条评价)。这有助于更快生成结果。请参阅我们关于扩展客户端总结的指南。
QuotaExceededError
会提供有关输入中请求的令牌的更多信息。summarizer
对象有一个inputQuota
属性,用于指示 API 的令牌限制。这样一来,如果输入超出限制,系统便会提供实时反馈并停用相应功能。
您不妨考虑采用混合方法,以确保为所有用户提供顺畅的体验。首次调用内置 AI API 时,浏览器必须下载模型。
- 在模型下载期间,Miravia 使用服务器端模型提供初始摘要。内置模型准备就绪后,网站会切换到在客户端执行推理。
您应始终努力打造友好且富有交互性的界面:
- 实现进度条,以便下载模型并减少响应延迟。
- 考虑在模型下载方面做到透明。Bright Sites 会通知用户模型下载情况,以便用户了解资源使用情况并征得用户同意。这样,用户可以在继续之前接受或拒绝。
结论和建议
以下来自 redBus 和 Miravia 的真实示例展示了 Summarizer API 如何通过提供简洁、相关的用户评价摘要,帮助用户快速做出明智的决策。该 API 能够在客户端运行,无需额外的业务开销且技术复杂性较低,因此对于需要汇总信息的类似用例而言,它是一个可行的选择。所有内置 AI API 都支持实用的客户端 AI 用例。
想知道 Summarizer API 如何帮助实现其他用例?我们还分享了 Summarizer API 如何帮助提高文章互动度。
您是否打算使用这些 API 构建新内容?您可以通过 X 上的@ChromiumDev 或 LinkedIn 上的“Chrome 开发者版”与我们分享您的反馈。
资源
- 详细了解 Summarizer API。
- 开始在 Chrome 上使用内置 API。
- 阅读 Prompt API 案例研究,了解如何赋予博主力量。
- 阅读翻译和语言检测器案例研究。
- 了解 Summarizer API 如何帮助 Bright Sites 和 Terra 创建富有吸引力的文章摘要
致谢
感谢 Miravia(阿里巴巴集团)的 Makakhov Andrey 和 Ziyi Liang、redBus 的 Amit Kumar、Swetha Gopalakrishnan、Alexandra Klepper、Thomas Steiner 和 Kenji Baheux 帮助撰写和审核本文档。