AI
API Reference
AI.ask
Signature
async function ask(prompt: string, options?: AskOptions): Promise<string> & EventEmitter;Example
import { AI, Clipboard } from "@raycast/api";
export default async function command() {
const answer = await AI.ask("Suggest 5 jazz songs");
await Clipboard.copy(answer);
}import { AI, showToast, Toast } from "@raycast/api";
export default async function command() {
try {
await AI.ask("Suggest 5 jazz songs");
} catch (error) {
// Handle error here, eg: by showing a Toast
await showToast({
style: Toast.Style.Failure,
title: "Failed to generate answer",
});
}
}import { AI, getSelectedFinderItems, showHUD } from "@raycast/api";
import fs from "fs";
export default async function main() {
let allData = "";
const [file] = await getSelectedFinderItems();
const answer = AI.ask("Suggest 5 jazz songs");
// Listen to "data" event to stream the answer
answer.on("data", async (data) => {
allData += data;
await fs.promises.writeFile(`${file.path}`, allData.trim(), "utf-8");
});
await answer;
await showHUD("Done!");
}Parameters
Name
Description
Type
Return
Types
AI.Creativity
AI.Model
Model
Description
AI.AskOptions
Properties
Property
Description
Type
Last updated

