2.1.0 • Published 5 months ago

@algolia/generative-experiences-api-client v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@algolia/generative-experiences-api-client

generative-experiences-api-client MIT License

✨ Features

  • Thin & minimal low-level HTTP client to interact with Algolia's Generative Experiences API
  • Works both on the browser and node.js
  • UMD and ESM compatible, you can use it with any module loader
  • Built with TypeScript

💡 Getting Started

All of the packages comes with type definition, and are available for both browser and node environments.

Installation

All Generative Experiences packages are available on the npm registry.

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

Without a package manager (CommonJS)

<script src="https://cdn.jsdelivr.net/npm/@algolia/generative-experiences-api-client/dist/index.umd.js"></script>
<script>
  const { createClient } = window['@algolia/generative-experiences-api-client'];

  const client = createClient({
    appId: 'YourApplicationID',
    indexName: 'YourIndexName',
    searchOnlyAPIKey: 'YourSearchOnlyAPIKey',
    writeAPIKey: 'YourWriteAPIKey', // (optional) only needed for dynamic generation
    region: 'us', // (optional) region of the Algolia Application. Can be either `us` or `eu`. Default is `us`
  });
</script>

Usage

Guides Headlines

Retrieve your guides headlines using the getHeadlines() method.

import { createClient } from '@algolia/generative-experiences-api-client';

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

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.

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

import { createClient } from '@algolia/generative-experiences-api-client';

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

client
  .getOrGenerateHeadlines({
    category: guidesCategory,
    source: 'generated',
  })
  .then((response) => console.log(response));
Prop nameTypeDefaultDescriptionNotes
categorystring \| undefinedN/AThe category to use for retrieving/generating the headlines.-
maxHeadlinesnumber \| undefined4The maximum number of headlines to display.Maximum 1,000
source'combined' \| 'generated' \| 'index'indexThe source of the headlines.-
tone'natural' \| 'friendly' \| 'professional'naturalThe model will use a specific tone when provided.-
language_code'english' \| 'german' \| 'french'englishThe language code used for generating headlines.-
custom_contentstring-The extended instrcutions that the model should take into account for generating content.-
keywordsstring[]-A list of keywords that the model should highlight in the generated content.-
onlyPublishedbooleantrueOnly display published guides.-

Guides Content

Retrieve your guide's content using the getContent() method.

import { createClient } from '@algolia/generative-experiences-api-client';

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

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

You can dynamically generate content 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.

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

import { createClient } from '@algolia/generative-experiences-api-client';

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

client
  .getOrGenerateContent({
    objectID: guideID,
    source: 'generated',
  })
  .then((response) => console.log(response));
Prop nameTypeDefaultDescriptionNotes
objectIDstringN/AThe objectID for the guide to be retrieved/generated.required
source'combined' \| 'generated' \| 'index'indexThe source of the content.-
type'shopping_guide' \| 'category_guide'shopping_guideThe type of guide to generate.Used if source is generated
tone'natural' \| 'friendly' \| 'professional'naturalThe model will use a specific tone when provided.-
language_code'english' \| 'german' \| 'french'englishThe language code used for generating content.-
custom_contentstring-The extended instrcutions that the model should take into account for generating content.-
keywordsstring[]-A list of keywords that the model should highlight in the generated content.-
onlyPublishedbooleantrueOnly display published guides.-

Gather Feedback

You can gather user feedback using the vote() method.

import { createClient } from '@algolia/generative-experiences-api-client';

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

client.vote({
  objectID: guideID,
  voteType: 'upvote',
  voteTarget: 'content',
  userToken: userToken,
});
Prop nameTypeDefaultDescriptionNotes
client-N/AThe Algolia Generative Experiences client.required
objectIDsstringN/AArray of objectIDs for gathering feedback.required
userTokenstringN/AThe user token needed for computing feedback.required
voteTarget'content' \| 'headline'contentThe target of the feedback.required

❓ Troubleshooting

Encountering an issue? Before reaching out to support, we recommend checking the GitHub Discussions. You can also open a Github issue.

📄 License

The project is an open-sourced software, licensed under the MIT license.

2.1.0

5 months ago

2.0.0

5 months ago

1.6.0

5 months ago

1.5.0

7 months ago

1.4.0

8 months ago

1.3.0

8 months ago

1.2.0

8 months ago

1.1.0

10 months ago

1.0.0

10 months ago

1.0.0-alpha.3

10 months ago

1.0.0-alpha.2

10 months ago