Interface IntegratingAI
Integrating AI Technology
AI technology is woven into the Smart GWT framework, not only at a base level, but also systemically. With only minimal changes to application code, surprisingly sophisticated, AI-powered enhancements can be enabled that have the ability to turn the users of your application into power users. For example, users of your application can use natural language to:- Filter a
ListGrid
according to their description of the records to include or exclude. - Add a custom field to a
ListGrid
, combining data from the underlying dataSource or augmenting the data with AI-provided knowledge. - Sort the data of a
ListGrid
according to the user's description of how the data should be ordered. - Build a custom
DataBoundComponent
using available dataSources according to the user's description of what they would like to see.
The AIEngine
class
Communication with AI services is performed by instances of the AIEngine
class. The first step in integrating AI technology into your application is to register
an AIEngine
instance and set defaultEngineId
to its AIEngine.engineId
.
You may either implement AIEngine
for the generative AI service that you would
like to use, or you may utilize built-in support for the following AI engines:
Engine ID | Provider | Name | Additional Installation Notes |
---|---|---|---|
"gpt-3.5-turbo" |
OpenAI | GPT-3.5 Turbo |
You must obtain an API key having access to the model(s) from: https://platform.openai.com/api-keys Then, the value of server configuration property OpenAI.api.key must be set to
your API key.
The o1-preview and o1-mini models may require higher tier API access. |
"gpt-4" |
OpenAI | GPT-4 | |
"gpt-4-turbo" |
OpenAI | GPT-4 Turbo | |
"gpt-4o" |
OpenAI | GPT-4o | |
"o1-preview" |
OpenAI | o1-preview | |
"o1-mini" |
OpenAI | o1-mini | |
"gemini-pro" |
Gemini Pro & Gemini Pro Vision |
You must obtain an API key having access to these models from: https://makersuite.google.com/app/apikey?authuser=1 Then, the value of server configuration property Gemini.api.key must be set to
your API key.
|
If using a custom AIEngine
instance, register it via AI.registerEngine()
.
Then set defaultEngineId
to the engineId
of the AIEngine
(either custom or built-in) that should be used by default.
Enabling AI
AI is disabled by default. To enable AI within your application, set thedefaultEngineId
to the AIEngine
that you would like to use by default, and then
set disabled
to false
.
If your application will need to ask AI to analyze images, make sure to register at least
one AIEngine
that supports vision requests.
Here is sample Smart GWT code that enables AI using GPT-4o by default:
AI.setDefaultEngineId("gpt-4o"); AI.setDisabled(false);
AI Component Views and AIServiceMode
AI can be used to set up the view settings of a ListGrid
, such as filters, sorts,
and record hilites, according to the user's natural-language request for how the records
should be filtered, sorted, and hilited. These AI-generated view settings are saved in the
component ViewState
.
With each AI component view feature, there is an associated AIServiceMode
setting that controls the mode for how AI should respond to user requests:
Filtering | filterViaAIMode |
Sorting | sortViaAIMode |
Hiliting | hiliteViaAIMode |
With respect to AI component views, the supported AI service modes are:
- AI Assist - AI drives existing UI on the user's behalf according to the request.
An example of this is: AI converts the user's description of what records they would like
to see into
AdvancedCriteria
that is then set as the filter criterion of aDataBoundComponent
. - AIDE (AI Data Enhance) - per-record augmentation or enhancements provided via AI. Examples of this are AI-generated fields, where the field values are not derived from the records, but rather, supplied via AI.
- Hybrid - a combination of AI Assist and AIDE, where AI decides whether AI Assist, AIDE, or some combination of both approaches should be used to best respond to the request.
The amount of interaction with AI is lowest in AI Assist mode. AIDE requires more interaction with AI, and Hybrid mode requires the most amount of interaction. More interaction with AI generally requires more time to process the component view request.
Requirements for AI Component Views to be Enabled
With respect to a particularDataBoundComponent
, the
requirements for AI component views
to be enabled are:
- AI must be enabled:
AI.isEnabled()
- A globally-installed
DataSource
with a primary key andsupporting AdvancedCriteria
must be set. - The
DataSource
cannot have a composite primary key. - The number of data-records must be known, and the total number of records must be less
than the DBC's
aiMaxRecords
.