SmartCore AI Component Pack
Starting with version 13.0, RAD Studio continues to provide AI-powered coding assistance in the IDE by introducing a new set of core AI components designed to help customers add AI features to their existing applications or build brand-new AI-focused applications with Delphi or C++Builder.
This is a modular component suite to simplify calling AI providers (OpenAI, Claude, Gemini, Ollama) from Delphi and C++Builder applications. It separates runtime units (components, drivers, types, LiveBindings) from design-time units (property editors, connection wizard, helpers). Drivers can be extended by overriding virtual methods or creating new driver components.
To use the SmartCore AI Components Pack, an API key is required for the specific AI service (available with a free or paid account) or a local installation of the engine in case of Ollama.
Contents
Overview
The SmartCore AI Components feature is a building block and a foundation for the future. It’s a core architecture that our customers and third-party vendors can build on and extend to integrate with additional AI engines and UI controls.
This package includes:
- A new AI connection component (with a role similar to that of a database connection in FireDAC). This is an AI-engine agnostic component, which uses specific drivers to communicate via REST with different AI engines (including OpenAI, Claude, Gemini, and Ollama). The SmartCore AI engine provides the ability to add additional drivers, enabling AI providers to expand the capabilities of your project as the market evolves. The configuration is managed via an easy-to-use AI connection wizard.
- A set of AI request components for different data types (like text, images, structured data), which can be associated with prompts and can be bound directly with UI controls to display the results.
With the SmartCore AI Components Pack, users can integrate AI into both existing and new applications, addressing many popular AI use cases, such as providing support for in-product content creation like generating images and other media, adding in-product localization support for on-the-fly translation, delivering in-app smart insights and personalized recommendations for data analysis, or building an in-app chatbot to add interactivity to an existing application.
Installation and Getting Started
Download the SmartCore AI Component Pack from GetIt to start using the AI connection component.
A set of associated demos is also available in the RAD Studio 13.0 Demo repository. If you have installed the demos with the product, you can get an update via git.
Once the package is installed, follow these steps to get started:
- Dropping TAIConnection, assigning a driver, and assigning to request components.
- Use the Connection Wizard for editing and testing params (double click on TAIConnection).
- Or manually configure params (API key, model, BaseURL, etc.).
The following is a list of the components installed by the Smart AI Components pack:
Components and Drivers Quick Reference
The following is a list of the components and drivers.
- TAIConnection: owns and links a concrete TAIDriver.
- Drivers:
TAIOpenAIDriver
,TAIClaudeDriver
,TAIGeminiDriver
,TAIOllamaDriver
. - Params: strongly-typed per driver (
TAIOpenAIParams
,TAIClaudeParams
,TAIGeminiParams
,TAIOllamaParams
) - Endpoint_*: drivers publish provider-specific endpoints with correct default values (based on the provider API references).
- Request components:
TAIChatRequest
,TAIImageRequest
,TAIJSONRequest
,TAIStreamRequest
Notes and Best Practices
The following section lists best practices and notes.
- Use the Connection Wizard at design-time for simplicity.
- Drivers raise the
EAIException
,EAIJSONException
,EAIXxxxException
exceptions for error handling. - Drivers can do operations without a connection as well, but
TAIXxxxRequest
components are dependent onTAIConnection
. - Injecting an Http Customizer is possible at the
TAIConnection
level, in case you need more customized HTTP client behavior. - Drivers can do operations without a connection as well, but AIRequest components are dependent on AIConnection.
- The Synchronize events property is
True
by default, but in case of having many async in-flight requests, useDriver.CancelALL
and wait and checkDriver.IsRunning
before destroying components, otherwise there could be unexpected exceptions or errors.
Guide to Demos
Remember that to run the demos, you need to have an API key for the specific AI service (available with a free or paid account), except for Ollama.
Console:
SmartCoreAI_Console_Demo
- Headless sample showing fully programmatic wiring: create
TAIConnection
+ a driver +TAIChatRequest
in code and print responses to the console (no forms/IDE design-time).
- Headless sample showing fully programmatic wiring: create
FMX:
Chat_OpenAI_FMX
- FireMonkey chat UI with
TAIConnection
+TAIOpenAIDriver
+TAIChatRequest
. Demonstrates design-time wiring and handling OnResponse and OnError in FMX.
- FireMonkey chat UI with
Image_Gemini_FMX
- FMX image generation using
TAIGeminiDriver
+TAIImageRequest
. Shows building a request DTO and rendering generated images in FMX controls.
- FMX image generation using
Image_OpenAI_FMX
- FMX image generation using
TAIOpenAIDriver
+TAIImageRequest
. Similar to the Gemini FMX demo, but for OpenAI.
- FMX image generation using
JSON_OpenAI_FMX
- FMX example for calling provider JSON endpoints via
TAIJSONRequest
(e.g., moderation), demonstrates setting Endpoint/Body and showing raw JSON result, plus populating data in a Dataset(TFDMemTable).
- FMX example for calling provider JSON endpoints via
VCL:
Chat_OpenAI_VCL
- VCL chat with
TAIConnection
+TAIOpenAIDriver
+TAIChatRequest
. Simple form (Edit + Memo + Button) to send prompts and display responses.
- VCL chat with
Image_Gemini_VCL
- VCL image generation with
TAIGeminiDriver
+TAIImageRequest
. Loads generated images into a TImage control.
- VCL image generation with
Image_OpenAI_VCL
- VCL image generation with
TAIOpenAIDriver
+TAIImageRequest
. Mirrors the Gemini VCL demo for OpenAI’s image APIs.
- VCL image generation with
JSON_Gemini_VCL
- VCL example for calling provider(Gemini) JSON endpoints via
TAIJSONRequest
(e.g., moderation), demonstrates setting Endpoint/Body and showing raw JSON result plus populating data in a Dataset(TFDMemTable).
- VCL example for calling provider(Gemini) JSON endpoints via
JSON_OpenAI_VCL
- VCL example for calling provider(Gemini) JSON endpoints via
TAIJSONRequest
(e.g., moderation), demonstrates setting Endpoint/Body and showing raw JSON result plus populating data in a Dataset(TFDMemTable).
- VCL example for calling provider(Gemini) JSON endpoints via
SmartCoreAI_LiveBindings_Demo
- VCL LiveBindings Showcase: Binds chat component outputs to visual controls using the SmartCoreAI.Design.LiveBindings adapters.
Stream_OpenAI_VCL
- VCL streaming demo for OpenAI (e.g., Audio transcription, Speech recognition, Image understanding, Audio understanding, etc). Uses
TAIStreamRequest
and updates the UI progressively via OnPartial, OnSuccess, and OnError events.
- VCL streaming demo for OpenAI (e.g., Audio transcription, Speech recognition, Image understanding, Audio understanding, etc). Uses
The Code Structure
This is a more technical reference to the packages and units included in the SmartCore AI Components Pack.
Packages
- SmartCoreAI: Core runtime package with components & drivers.
- dclSmartCoreAI: Design-time registration (property editors, wizard).
- SmartCoreAIVCL: VCL Live bindings runtime package.
- dclSmartCoreAI: VCL Live bindings design time package.
- SmartCoreAIFMX: FMX Live bindings runtime package.
- dclSmartCoreAIFMX: FMX Live bindings design time package.
Units
- SmartCoreAI.Comp.Connection.pas:
TAIConnection
,TAIRequest
base class. - SmartCoreAI.Comp.Chat.pas:
TAIChatRequest
with events and Chat method. - SmartCoreAI.Comp.Image.pas:
TAIImageRequest
(image generation). - SmartCoreAI.Comp.JSON.pas:
TAIJSONRequest
(generic JSON endpoints). - SmartCoreAI.Comp.Stream.pas:
TAIStreamRequest
(stream endpoints). - SmartCoreAI.Types.pas: Core dData Types, including Enums, callback interfaces,
IAIDriver
,TAIDriver
base classes. - SmartCoreAI.Serialization.pas: JSON serializer and helpers.
- SmartCoreAI.Driver.Registry.pas:
TAIDriverRegistry
to register or lookup drivers. - SmartCoreAI.Driver.OpenAI.pas:
TAIOpenAIDriver
andTAIOpenAIParams
. - SmartCoreAI.Driver.Claude.pas:
TAIClaudeDriver
andTAIClaudeParams
. - SmartCoreAI.Driver.Gemini.pas:
TAIGeminiDriver
andTAIGeminiParams
. - SmartCoreAI.Driver.Ollama.pas:
TAIOllamaDriver
andTAIOllamaParams
. - SmartCoreAI.Consts.pas: resourcestrings and Consts.
- SmartCoreAI.Design.Registration.pas: Registers editors and wizard at design time.
- SmartCoreAI.Design.PropertyEditors.pas: Property editors for Params and Model dropdowns.
- SmartCoreAI.Design.ConnectionWizard.pas:
TAIConnectionEditor
(launch wizard). - SmartCoreAI.Design.ConnectionWizardForm.pas/.dfm:
TfrmAIConnectionWizard
– select driver, edit params. - SmartCoreAI.Design.LiveBindings.pas: LiveBindings adapters for chat & images.