Functions:generativeAI - bettyblocks/cli GitHub Wiki
Generative AI
Description
The generativeAI
function is an asynchronous function that interacts with a Generative AI model and serves as a gateway to tap into the capabilities of generative AI, offering users the ability to leverage advanced algorithms for creative content generation, automation, and problem-solving within their applications. This documentation aims to provide a comprehensive guide on integrating and utilizing the generative AI function seamlessly in your projects.
Parameters
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-choice';
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. This prompt can be improved by using jinja templating and the variables object. The default value is an empty string.variables
: This is an object that represents the values that are used inside the prompt with{{question}}
.choices
: This option is an array ofChoice
and needs to be provided when using thetext-to-choice
agent.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;
}
Examples
Text to text
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);
// result: Bonjour, comment ça va?
Text to choice
In this example, we ask if a certain title is a movie or series the result will be based on the choices that are provided.
const options = {
agent: "text-to-choice",
authorization: {
apiKey: "your-api-key",
},
params: {
prompt: "Is {{title}} a movie or a series?",
variables: {
title: "Game of Thrones",
},
choices: [
{
choice: "Movie",
description: "Movies are like bite-sized journeys into other worlds. In a couple of hours or so, you get to witness a complete story unfold on the screen. It's a condensed yet powerful form of storytelling, where every frame, line, and scene contributes to the overall narrative. Whether it's the adrenaline rush of an action film, the laughs of a comedy, or the emotional rollercoaster of a drama, movies have this magical ability to transport you to different realities, making you feel, think, and experience in a way that's unique to the medium.",
},
{
choice: "Series",
description: "A series is like a literary or cinematic journey that unfolds over multiple installments. It's a storytelling format that allows for more in-depth exploration of characters, plotlines, and settings. Each episode or book adds layers to the narrative, creating a rich and immersive experience for the audience. Whether it's the thrilling suspense of a crime series, the magical realms of a fantasy saga, or the complex relationships in a drama, a series provides the time and space for a story to evolve and captivate its audience over the long haul.",
},
],
model: {
model: "gpt-4",
settings: {
maxNewTokens: 1024,
temperature: 0.5,
},
},
},
};
const { result } = await generativeAI(options);
// result: Series
Note
Ensure that you have the necessary permissions and valid API key to interact with the Generative AI model.