Skip to content

Functions:generativeAI

Emiel Wit edited this page Nov 9, 2023 · 20 revisions

generativeAI Function

Description

The generativeAI function is an asynchronous function that interacts with a Generative AI model.

Parameters

  • GenerativeAIArguments: This is an object that contains the following properties:
    • agent: This is a string that represents the type of agent. The default value is text-to-text.
    • authorization: This is an object that contains the apiKey. The default value is an empty string.
    • params: This is an object that contains the following properties:
      • prompt: This is a string that represents the prompt for the AI model. The default value is an empty string.
      • model: This is an object that contains the following properties:
        • model: This is a string that represents the model to be used.
        • settings: This is an object that contains the following properties:
          • maxNewTokens: This is a number that represents the maximum number of new tokens. The default value is 1024.
          • temperature: This is a number that represents the temperature for the AI model. The default value is 0.2.

Returns

The function returns a Promise that resolves to a GenerativeAIResult object.

interface GenerativeAIResult {
  result: string | null;
}

Errors

The function throws an error if:

  • The provided model is not included in the largeLanguageModels array.
  • The provided agent is not a key in the agents object.
  • No API key is provided.

Example

const options = {
  agent: 'text-to-text',
  authorization: {
    apiKey: 'your-api-key',
  },
  params: {
    prompt: 'your-prompt',
    model: {
      model: 'your-model',
      settings: {
        maxNewTokens: 1024,
        temperature: 0.2,
      },
    },
  },
};

const { result } = await generativeAI(options)

Note

Ensure that you have the necessary permissions and valid API key to interact with the Generative AI model.

Clone this wiki locally