@adobe/spacecat-shared-gpt-client
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

Spacecat Shared - GPT Client

The FirefallClient library offers a streamlined way to interact with the Firefall API, enabling applications to fetch insights, recommendations, and codes based on provided prompts. Designed with simplicity and efficiency in mind, this client handles all aspects of communication with the Firefall API, including request authentication, error handling, and response parsing.

Configuration

To use the FirefallClient, you need to configure it with the following parameters:

  • FIREFALL_API_ENDPOINT: The endpoint URL for the Firefall API.
  • FIREFALL_API_KEY: Your API key for accessing the Firefall API.
  • FIREFALL_API_CAPABILITY_NAME: The capability name for the Firefall API.

These parameters can be set through environment variables or passed directly to the FirefallClient.createFrom method.

Additionally, the configuration for the @adobe/spacecat-shared-ims-client library is required to fetch the service access token from the IMS API:

  • IMS_HOST: The hostname of the IMS API.
  • IMS_CLIENT_ID: Your IMS client ID.
  • IMS_CLIENT_CODE: Your IMS client code, used for authentication.
  • IMS_CLIENT_SECRET: Your IMS client secret, used for authentication.

Usage Examples

Instantiating the Firefall Client

import FirefallClient from 'path/to/firefall-client';

// Assuming environment variables are set
const context = {
  env: process.env,
  log: console, // Using console for logging in this example
};

try {
  const client = FirefallClient.createFrom(context);
  console.log('FirefallClient created successfully.');
} catch (error) {
  console.error('Error creating FirefallClient:', error.message);
}

Fetching Insights

async function fetchInsights(prompt) {
  try {
    const client = FirefallClient.createFrom({
      env: {
        FIREFALL_API_ENDPOINT: 'https://api.firefall.example.com',
        FIREFALL_API_KEY: 'yourApiKey',
        FIREFALL_API_CAPABILITY_NAME: 'yourCapabilityName',
        IMS_HOST: 'ims.example.com',
        IMS_CLIENT_ID: 'yourClientId',
        IMS_CLIENT_CODE: 'yourClientCode',
        IMS_CLIENT_SECRET: 'yourClientSecret',
      },
      log: console,
    });

    const insights = await client.fetch(prompt);
    console.log('Insights:', insights);
  } catch (error) {
    console.error('Failed to fetch insights:', error.message);
  }
}

fetchInsights('How can we improve customer satisfaction?');

Ensure that you replace 'path/to/firefall-client' with the actual path to the FirefallClient class in your project and adjust the configuration parameters according to your Firefall API credentials.

Testing

To run tests:

npm test

Linting

Lint your code:

npm run lint

Cleaning

To remove node_modules and package-lock.json:

npm run clean

Additional Information

Readme

Keywords

none

Package Sidebar

Install

npm i @adobe/spacecat-shared-gpt-client

Weekly Downloads

193

Version

1.2.3

License

Apache-2.0

Unpacked Size

40.8 kB

Total Files

11

Last publish

Collaborators

  • dylandepass
  • djaeggi
  • adobehalls
  • fullcolorcoder
  • marbec
  • tripod
  • garthdb
  • lazd
  • adobe-admin
  • patrickfulton
  • trieloff
  • shazron
  • krisnye
  • dcpfsdk
  • natebaldwin
  • devongovett
  • aspro83
  • symanovi
  • dpfister
  • stefan-guggisberg
  • korra
  • rofe
  • kptdobe