AI Actions
ai.chat(message: AIChatMessage, options?: AIChatOptions): Promise<AIChatMessage>
Sends a chat message to the AI.
Returns a promise that contains the response from the AI.
Throws a CasualOSError
if an error occurs while sending the message.
This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
The first parameter is a AIChatMessage and is the message that should be sent to the AI.
The second parameter is optional and is a AIChatOptions and is the options that should be used.
Examples
const response = await ai.chat({
role: "user",
content: "Hello!"
});
console.log(`${response.role}: ${response.content}`);
ai.chat(messages: AIChatMessage[], options?: AIChatOptions): Promise<AIChatMessage>
Sends a chat message to the AI.
Returns a promise that contains the response from the AI.
Throws a CasualOSError
if an error occurs while sending the message.
This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
The first parameter is a AIChatMessage[] and
The second parameter is optional and is a AIChatOptions and is the options that should be used.
Examples
const response = await ai.chat([
{
role: "system",
content: "You are a helpful assistant."
},
{
role: "user",
content: "Hello!"
}
]);
console.log(`${response.role}: ${response.content}`);
const messages = [
{
role: "system",
content: "You are a helpful assistant."
},
];
while(true) {
const userInput = await os.showInput();
if (!userInput) {
break;
}
messages.push({
role: "user",
content: userInput
});
const response = await ai.chat(messages);
messages.push(response);
os.toast(response.content);
}
os.toast("Goodbye!");
ai.chat(message: string, options?: AIChatOptions): Promise<string>
Sends a chat message to the AI.
Returns a promise that contains the response from the AI.
Throws a CasualOSError
if an error occurs while sending the message.
This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
The first parameter is a string and is the message that should be sent to the AI.
The second parameter is optional and is a AIChatOptions and is the options that should be used.
Examples
const response = await ai.chat("Hello!");
console.log(response);
ai.generateImage(request: AIGenerateImageOptions, options?: RecordActionOptions): Promise<AIGenerateImageSuccess>
Generates an image from the given prompt.
Returns a promise that resolves with the Base64 data of the generated image that can be used as the #formAddress
of a bot.
The first parameter is a AIGenerateImageOptions and is the request object that describes what the image should look like.
The second parameter is optional and is a RecordActionOptions and is the options for the request.
Examples
const image = await ai.generateImage({
prompt: "An oil painting of a grassy field.",
});
masks.formAddress = image;
const image = await ai.generateSkybox({
prompt: "An oil painting of a grassy field.",
negativePrompt: "realistic"
});
masks.formAddress = image;
ai.generateImage(prompt: string, negativePrompt?: string, options?: AIGenerateImageOptions & RecordActionOptions): Promise<string>
Generates an image from the given prompt.
Returns a promise that resolves with the Base64 data of the generated image that can be used as the #formAddress
of a bot.
The first parameter is a string and is the string that describes what the image should look like.
The second parameter is optional and is a string and is the string that describes what the image should avoid looking like.
The third parameter is optional and is a AIGenerateImageOptions & RecordActionOptions and is the additional options that should be used.
Examples
const image = await ai.generateImage("An oil painting of a grassy field.");
masks.formAddress = image;
const image = await ai.generateSkybox("An oil painting of a grassy field.", "realistic");
masks.formAddress = image;
ai.generateSkybox(request: AIGenerateSkyboxRequest): Promise<AIGenerateSkyboxResult>
Generates a skybox image from the given request object.
Returns a promise that resolves with an object that contains a URL to the generated image that can be used as the #formAddress
of a bot that has #form
set to skybox
.
The first parameter is a AIGenerateSkyboxRequest and is the request object that describes what the skybox should look like.
Examples
const skybox = await ai.generateSkybox("A skybox with a blue sky and green grass.");
masks.formAddress = skybox;
const skybox = await ai.generateSkybox("A skybox with a blue sky and green grass.", "A skybox with a red sky and brown grass.");
masks.formAddress = skybox;
ai.generateSkybox(prompt: string, negativePrompt?: string, options?: AIGenerateSkyboxOptions): Promise<string>
Generates a skybox image from the given prompt.
Returns a promise that resolves with a URL to the generated image that can be used as the #formAddress
of a bot that has #form
set to skybox
.
The first parameter is a string and is the string that describes what the skybox should look like.
The second parameter is optional and is a string and is the string that describes what the skybox should avoid looking like.
The third parameter is optional and is a AIGenerateSkyboxOptions and is the additional options that should be used.
Examples
const skybox = await ai.generateSkybox("A skybox with a blue sky and green grass.");
masks.formAddress = skybox;
const skybox = await ai.generateSkybox("A skybox with a blue sky and green grass.", "A skybox with a red sky and brown grass.");
masks.formAddress = skybox;