Amazon 使用适用于 JavaScript (v3) 的软件开发工具包对运行时进行个性化示例 - AWS SDK for JavaScript

AWS SDK for JavaScript V3 API 参考指南详细描述了 AWS SDK for JavaScript 版本 3 (V3) 的所有 API 操作。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon 使用适用于 JavaScript (v3) 的软件开发工具包对运行时进行个性化示例

以下代码示例向您展示了如何使用带有 Amazon Personalize Runtime 的 AWS SDK for JavaScript (v3) 来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景 是展示如何通过在同一服务中调用多个函数来完成特定任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例展示了如何获取 Amazon Personalize Runtime 排名推荐。

适用于 JavaScript (v3) 的软件开发工具包
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

// Get service clients module and commands using ES6 syntax. import { GetPersonalizedRankingCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set the ranking request parameters. export const getPersonalizedRankingParam = { campaignArn: "CAMPAIGN_ARN", /* required */ userId: 'USER_ID', /* required */ inputList: ["ITEM_ID_1", "ITEM_ID_2", "ITEM_ID_3", "ITEM_ID_4"] } export const run = async () => { try { const response = await personalizeRuntimeClient.send(new GetPersonalizedRankingCommand(getPersonalizedRankingParam)); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

以下代码示例展示了如何获取 Amazon Personalize Runtime 推荐。

适用于 JavaScript (v3) 的软件开发工具包
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

// Get service clients module and commands using ES6 syntax. import { GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set the recommendation request parameters. export const getRecommendationsParam = { campaignArn: 'CAMPAIGN_ARN', /* required */ userId: 'USER_ID', /* required */ numResults: 15 /* optional */ } export const run = async () => { try { const response = await personalizeRuntimeClient.send(new GetRecommendationsCommand(getRecommendationsParam)); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

使用筛选条件(自定义数据集组)获取推荐。

// Get service clients module and commands using ES6 syntax. import { GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set the recommendation request parameters. export const getRecommendationsParam = { recommenderArn: 'RECOMMENDER_ARN', /* required */ userId: 'USER_ID', /* required */ numResults: 15 /* optional */ } export const run = async () => { try { const response = await personalizeRuntimeClient.send(new GetRecommendationsCommand(getRecommendationsParam)); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

从在域数据集组中创建的推荐系统处获取经过筛选的推荐。

// Get service clients module and commands using ES6 syntax. import { GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here: // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set recommendation request parameters. export const getRecommendationsParam = { campaignArn: 'CAMPAIGN_ARN', /* required */ userId: 'USER_ID', /* required */ numResults: 15, /* optional */ filterArn: 'FILTER_ARN', /* required to filter recommendations */ filterValues: { "PROPERTY": "\"VALUE\"" /* Only required if your filter has a placeholder parameter */ } } export const run = async () => { try { const response = await personalizeRuntimeClient.send(new GetRecommendationsCommand(getRecommendationsParam)); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • 有关 API 的详细信息,请参阅 AWS SDK for JavaScript API 参考GetRecommendations中的。