Generate and import data from AI services like Google Gemini, ChatGPT, and others
The TBIAI class enables importing data generated by artificial intelligence agents. Simply provide a natural language query and receive structured data ready for visualization.
uses BI.AI, BI.DataItem;var Data: TDataItem;// Import from Google GeminiData := TBIAI.From( 'Give me the list of the highest 10 mountains by elevation in csv format', TBIAI.TAgent.Gemini, 'your_api_key_here');BIGrid1.Data := Data;BIChart1.Data := Data;
class function From( const Question: String; // Natural language query const Agent: TAgent; // AI service to use const Key: String // Your API key): TDataItem;
Data := TBIAI.From( 'Top 20 programming languages by popularity in CSV format, ' + 'just the data table, no explanations', TBIAI.TAgent.Gemini, ApiKey);
uses BI.AI;var Data: TDataItem;try Data := TBIAI.From( 'List Fortune 500 companies in CSV', TBIAI.TAgent.Gemini, ApiKey ); if Data <> nil then BIGrid1.Data := Data else ShowMessage('No data returned');except on E: EBIAI do ShowMessage('AI Error: ' + E.Message);end;
uses BI.AI, BI.Query;var RawData, Summary: TDataItem;// Get data from AIRawData := TBIAI.From( 'Sales data for 12 months with product categories', TBIAI.TAgent.Gemini, ApiKey);// Analyze itSummary := TBISQL.From( RawData, 'sum(Sales) group by Category');BIChart1.Data := Summary;
Parses data: Using appropriate importer (TBICSV/TBIJson)
Type detection: Automatic data type inference
Raw response cleanup:
```csvName,Age,CityJohn,30,NYCJane,25,LA
Becomes:
Name,Age,City
John,30,NYC
Jane,25,LA
## API Keys### Security<Warning> Never hardcode API keys in your source code. Use configuration files or environment variables.</Warning>```pascal// Good - from configvar IniFile: TIniFile; ApiKey: String;IniFile := TIniFile.Create('config.ini');try ApiKey := IniFile.ReadString('AI', 'GeminiKey', '');finally IniFile.Free;end;// Bad - hardcodedApiKey := 'AIzaSyC...';