askOpenAi

This function gives the possibility to address the AI of OpenAi via API. Questions can be asked or tasks can be described. This function is also used to explain or optimize the code in the App Editor.

Function Signature

The function requires an object as a parameter. Only the command field must be filled, the remaining properties are optional and will be filled with default values if required.

Information about the model and task parameters can be found in the official documentation of openAI: Doku - openAI

//aiModel is an object with 4 parameters
const aiModel = {
    command: "Question", //Question or instruction to the AI (required)
    task: "Completions", //Api internal task type, default "Completions"
    model: "gpt-3.5-turbo" //AI model to use, default "gpt-3.5-turbo"
    text: "Additional Information" //Additional information, such as source code, default " "
}

app.askOpenAi(aiModel);

Examples

//simple Call 
let response = app.askOpenAi({
  command: "Tell me a joke."
});
//full options
let response = app.askOpenAi({
  command: "Explain this code to me and add comments:",
  task: "Completions",
  model: "gpt-3.5-turbo",
  text: "let counter = 25; for (let i = 0; i < counter; i++) { if (i % 2 == 0) { console.log(i); } }"
});

Return Values

Function does return the answer to your prompt.

Last updated