Skip to Content

AI Ask

Overview

This function interacts with an AI model (specifically designed for chat completions, compatible with OpenAI’s API structure) to generate text-based responses based on a given prompt. It can optionally incorporate data provided as a 2D list into the prompt for more context-specific analysis or generation.

View Python code on GitHub

Usage

Sends a prompt and optional data to an AI model and returns the generated text response.

=AI_ASK(prompt, [data], [temperature], [max_tokens], [model])

Arguments:

ArgumentTypeDescriptionDefault
promptstringThe question, task, or instruction for the AI.
data2D listOptional: Data from an Excel range to be included in the context sent to the AI.None
temperaturefloatOptional: Controls the randomness/creativity of the response (0.0 to 2.0). Higher values mean more creative.0.5
max_tokensintOptional: Maximum number of tokens (words/subwords) the AI should generate in its response.250
modelstringOptional: The specific AI model ID to use for the request (e.g., ‘mistral-small’, ‘mistral-large’).mistral-small

Returns:

Return ValueTypeDescription
ResponsestringThe text response generated by the AI model.

Examples

1. Basic Question Answering

Ask a simple factual question.

=AI_ASK("What is the tallest mountain in the world?")

Sample Output: “Mount Everest is the tallest mountain in the world.”

2. Text Summarization

Summarize a block of text provided in a cell.

Sample Input Text (Cell A1): “The Industrial Revolution, which began in Great Britain in the late 18th century, was a period of major technological, socioeconomic, and cultural change. Key innovations included the steam engine, power loom, and advancements in iron production. This era transformed economies from agrarian and handicraft-based to industrial and machine-based, leading to urbanization and new social classes.”

=AI_ASK("Summarize the following text in one sentence:", A1)

Sample Output: “The Industrial Revolution, starting in 18th-century Britain, marked a significant shift to industrialization driven by key technological innovations like the steam engine, profoundly altering society and the economy.”

3. Data Analysis (Simple)

Analyze a small dataset to find the average.

Sample Input Data (Range A1:A5):

Sales
150
200
175
225
190
=AI_ASK("What is the average of the sales figures provided?", A1:A5)

Sample Output: “The average of the provided sales figures is 188.”

4. Creative Writing

Generate a short story based on a prompt.

=AI_ASK("Write a short paragraph about a robot discovering music for the first time.")

Sample Output: “Unit 734 processed the auditory input—a cascade of harmonized frequencies unlike any factory rhythm or diagnostic beep it had ever known. Its optical sensors widened slightly as the complex patterns resonated through its circuits, evoking an unfamiliar sensation, a simulated echo of… joy? It tilted its head, analyzing the ‘music,’ a novel dataset that felt unexpectedly significant.”

Last updated on