SQLAI.ai

Data Analyzer Generator (Ask Data Question)

Integrate the data analyzer generator into your application.

Please read the getting started guide first.

Table of contents

Example

You can integrate with our platform by using a simple fetch request:

            
const response = await fetch('/api/ai', { method: 'POST', headers: { 'Content-Type': 'application/json', authentication: `Bearer ${SECRET_TOKEN}`, }, body: JSON.stringify({ prompt: 'Who is most popular band?', mode: 'askDataQuestion', dataSourceId: 'clv2fnxre00093r1r4adasd', }), }); const { content, error } = await res.json(); if (error) { // Handle error } // Show user the Markdown content

Options

  • prompt (required): The question to ask the provided data.
  • mode (required): The generator to use, askDataQuestion.
  • dataSourceId: The data to use for the generation. See your added data sources.
  • dataSourceRaw: The raw data to use. CSV format is recommended but other work as well.
  • model: AI model to use. It can either be gpt-4 or gpt-3.5. gpt-4 is default and recommended as it handles context data better.

Response

The above example using the Rolling Stone's 500 Greatest Albums of All Time as data source will return this response:

            
{ "content": `"Based on the provided data, the most popular band can be determined by the number of times they appear in the list. Here's a breakdown of the appearances of some notable bands: - **The Beatles**: Appear multiple times with albums like "Sgt. Pepper's Lonely Hearts Club Band", "Revolver", "Rubber Soul", "The Beatles (The White Album)", "Abbey Road", "Please Please Me", "Meet The Beatles!", "Let It Be", "Help!", and more. - **The Rolling Stones**: Also appear multiple times with albums such as "Exile on Main St.", "Let It Bleed", "Sticky Fingers", "Beggars Banquet", "Some Girls", "Aftermath", "Out of Our Heads", "The Rolling Stones, Now!", and others. - **Bob Dylan**: Appears with "Highway 61 Revisited", "Blonde on Blonde", "Blood on the Tracks", "The Freewheelin' Bob Dylan", "Bringing It All Back Home", "Desire", "John Wesley Harding", "Time Out of Mind", "Modern Times", and more. - **Led Zeppelin**: Listed with "Led Zeppelin", "[Led Zeppelin IV]", "Physical Graffiti", "Led Zeppelin II", "Houses of the Holy". Counting the number of entries for each band: - **The Beatles**: 10 entries - **The Rolling Stones**: 10 entries - **Bob Dylan**: 10 entries - **Led Zeppelin**: 5 entries **Conclusion**: The Beatles, The Rolling Stones, and Bob Dylan are tied for the most popular band based on the number of appearances in the list, each with 10 entries."`, "meta": { "usage": { "prompt_tokens": 56, "completion_tokens": 55, "total_tokens": 111 }, "finish_reason": "stop" } }

The response object type:

            
type ResponseBody = { content: string; // Complete Markdown generation meta: { usage: { completion_tokens: number; prompt_tokens: number; total_tokens: number }; finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call'; }; error: string | undefined; };

Questions

If you have any questions or suggestions, please reach out.