-
Notifications
You must be signed in to change notification settings - Fork 16
Functions:generativeAI
Emiel Wit edited this page Nov 9, 2023
·
20 revisions
The generativeAI
function is an asynchronous function that interacts with a Generative AI model.
The helper function expects GenerativeAIArguments
as an argument.
const largeLanguageModels = [
'gpt-4',
'gpt-4-16k',
'gpt-3.5-turbo',
'gpt-3.5-turbo-16k',
] as const;
interface GrimoireAuth {
apiKey: string;
}
type LargeLanguageModel = (typeof largeLanguageModels)[number];
type Agent =
| 'text-to-text'
| 'text-to-object'
| 'text-to-choice'
| 'text-to-array';
interface Choice {
choice: string;
description: string;
}
interface Model {
model: LargeLanguageModel;
settings: {
maxNewTokens: number;
temperature: number;
};
}
interface GenerativeAIResult {
result: string | null;
}
interface GenerativeAIArguments {
agent?: Agent;
authorization: GrimoireAuth;
params: {
variables?: Record<string, string>;
prompt: string;
model: Model;
choices?: Choice[];
};
}
-
agent
: This is a string that represents the type of agent. The default value istext-to-text
. -
authorization
: This is an object that contains theapiKey
. 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. -
variables
: This is an object that represents the values that are used inside the prompt with{{question}}
. -
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.
-
-
-
The function returns a Promise
that resolves to a GenerativeAIResult
object.
interface GenerativeAIResult {
result: string | null;
}
In this example, we translate English into French.
const options = {
agent: 'text-to-text',
authorization: {
apiKey: 'your-api-key',
},
params: {
prompt: 'Translate the following English text to French: {{text_to_translate}}',
variables: {
text_to_translate: "Hello, how are you?"
}
model: {
model: 'gpt-4',
settings: {
maxNewTokens: 1024,
temperature: 0.5,
},
},
},
};
const { result } = await generativeAI(options);
Ensure that you have the necessary permissions and valid API key to interact with the Generative AI model.
- Getting started
- Page Builder Components
- Action Functions
- [deprecated] CustomFunctions