Guides / Algolia AI / Shopping Guides / Ui library

Alternative implementations

Algolia Shopping Guides is currently in beta according to the Algolia Terms of Service (“Beta Services”).

If you aren’t developing a React or JavaScript app, you can integrate the Algolia Shopping Guides into your app with an API client.

Installation

The Algolia Shopping Guides API Client package is available on the npm registry.

1
2
3
yarn add @algolia/generative-experiences-api-client
# or
npm install @algolia/generative-experiences-api-client

Usage

Shopping guide headlines

The getHeadlines method lets you retrieve different shopping guides for your app.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { createClient } from '@algolia/generative-experiences-api-client';

const client = createClient({
  appId: 'YourApplicationID',
  indexName: 'your_index_name',
  searchOnlyAPIKey: 'YourSearchOnlyAPIKey',
  region: 'us',
});

client
  .getHeadlines({
    category: guidesCategory,
  })
  .then((response) => console.log(response));

You can dynamically generate headlines using the getOrGenerateHeadlines method by passing a source parameter. For this method you must provide a write API key, generated with the search and addObject ACLs, when initializing the client.

Only use this method in your backend implementation (for example, Node) or if providing a layer of authentication.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { createClient } from '@algolia/generative-experiences-api-client';

const client = createClient({
  appId: 'YourApplicationID',
  indexName: 'your_index_name',
  searchOnlyAPIKey: 'YourSearchOnlyAPIKey',
  writeAPIKey: 'YourWriteAPIKey',
  region: 'us',
});

client
  .getOrGenerateHeadlines({
    category: guidesCategory,
    source: 'generated',
  })
  .then((response) => console.log(response));

Parameters

category
type: string
Required

The category used for retrieving the headlines.

nbHeadlines
type: number

The number of headlines to display. Default: 4

source
type: string

The source of the headlines. One of index, generated, or combined. Default: index

tone
type: string

The model will use a specific tone when provided. One of natural, friendly, or professional. Default: natural

language_code
type: string

The language code used for generating headlines. One of en_US, de_DE, or fr_FR. Default: en_US

content_to_avoid
type: string

The content that the model should avoid when generating headlines.

onlyPublished
type: boolean

Whether to only return headlines with generated content. Default: true

Shopping guide content

The getContent method lets you retrieve the content of a shopping guide.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { createClient } from '@algolia/generative-experiences-api-client';

const client = createClient({
  appId: 'YourApplicationID',
  indexName: 'your_index_name',
  searchOnlyAPIKey: 'YourSearchOnlyAPIKey',
  region: 'us',
});

client
  .getContent({
    objectID: guideID,
  })
  .then((response) => console.log(response));

You can dynamically generate the content of a guide using the getOrGenerateContent method by passing a source parameter. For this method you must provide a write API key, generated with the search and addObject ACLs, when initializing the client.

Only use this method in your backend implementation (for example, Node) or if providing a layer of authentication.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { createClient } from '@algolia/generative-experiences-api-client';

const client = createClient({
  appId: 'YourApplicationID',
  indexName: 'your_index_name',
  searchOnlyAPIKey: 'YourSearchOnlyAPIKey',
  writeAPIKey: 'YourWriteAPIKey',
  region: 'us',
});

client
  .getOrGenerateContent({
    objectID: guideID,
    source: 'generated',
  })
  .then((response) => console.log(response));

Parameters

objectID
type: string
Required

The objectID of the guide to be retrieved.

source
type: string

The source of the guide content. One of index, generated, or combined. Default: index

type
type: string

The type of guide to generate (used if source is generated): shopping_guide orcategory_guide. Default: shopping_guide

tone
type: string

The model will use a specific tone when provided. One of natural, friendly, or professional. Default: natural

language_code
type: string

The language code used for generating headlines. One of en_US, de_DE, or fr_FR. Default: en_US

content_to_avoid
type: string

The content that the model should avoid when generating headlines.

onlyPublished
type: boolean

Whether to only return headlines with generated content. Default: true

Gather feedback

The vote method lets you gather feedback for the content of a shopping guide or for the shopping guide headlines.

This feature uses the Insights API to gather events related to Shopping Guides feedback. You will need to set up a User Token.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { createClient } from '@algolia/generative-experiences-api-client';

const client = createClient({
  appId: 'YourApplicationID',
  indexName: 'your_index_name',
  searchOnlyAPIKey: 'YourSearchOnlyAPIKey',
  region: 'us',
});

client
  .vote({
    objectID: guideID,
    voteType: 'upvote',
    voteTarget: 'content',
    userToken: userToken
  })

Parameters

objectIDs
type: string
Required

List of objectIDs to gather feedback on.

userToken
type: string
Required

The user token needed for computing feedback.

voteTarget
type: string
Required

The feedback target: content or headline. Default: content

voteType
type: string
Required

Feedback type: upvote or downvote

Did you find this page helpful?