Alternative implementations
On this page
If you aren’t developing a React or JavaScript app, you can integrate the Algolia Guides into your app with an API client.
Installation
The Algolia 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
Guide headlines
The getHeadlines
method lets you retrieve different 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 |
tone
|
type: string
The model will use a specific tone when provided. One of |
language_code
|
type: string
The language code used for generating headlines. One of |
custom_content
|
type: string
The customised instructions that the model should take into account for generating content, for example, to refine the focus of the article, add constraints, or adjust to a target audience. |
keywords
|
type: string
A list of keywords that the model should highlight in the generated content. |
onlyPublished
|
type: boolean
Whether to only return headlines with generated content. Default: |
Guide content
The getContent
method lets you retrieve the content of a 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 |
type
|
type: string
The type of guide to generate (used if |
tone
|
type: string
The model will use a specific tone when provided. One of |
language_code
|
type: string
The language code used for generating headlines. One of |
custom_content
|
type: string
The customised instructions that the model should take into account for generating content, for example, to refine the focus of the article, add constraints, or adjust to a target audience. |
keywords
|
type: string
A list of keywords that the model should highlight in the generated content. |
onlyPublished
|
type: boolean
Whether to only return headlines with generated content. Default: |
Gather feedback
The vote
method lets you gather feedback for the guide’s headlines or content.
This feature uses the Insights API to gather events related to 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: |
voteType
|
type: string
Required
Feedback type: |