Package com.smartgwt.client.ai
Class AI
java.lang.Object
com.smartgwt.client.ai.AI
Provides class methods for enabling and disabling the use of AI technology, registering and unregistering
AI engines, and performing high-level operations using installed AI engines.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMockResponses(Map[] responses) Alias foraddSpoofedResponses().static voidaskDataQuestion(UserAIRequest question) Asks AI to answer a question about the data of the application.static voidaskDataQuestion(UserAIRequest question, DataSource... dataSources) static voidaskDataQuestion(UserAIRequest question, DataSource[] dataSources, DataQuestionSettings settings) static voidaskDataQuestion(UserAIRequest question, DataSource[] dataSources, DataQuestionSettings settings, AskDataQuestionResultCallback callback) Asks AI to answer a question about the data of the application.static voidaskDataQuestion(String question) Asks AI to answer a question about the data of the application.static voidaskDataQuestion(String question, DataSource... dataSources) static voidaskDataQuestion(String question, DataSource[] dataSources, DataQuestionSettings settings) static voidaskDataQuestion(String question, DataSource[] dataSources, DataQuestionSettings settings, AskDataQuestionResultCallback callback) Asks AI to answer a question about the data of the application.static voidcancelDataQuestion(String questionId) Cancels a data question if not already canceled.static voidcheckModuleLoaded(String faultingAction) static voidAlias forclearSpoofedResponses().static Map[]Returns an array of summaries (seegetDataSourceSummary()) for the specified DataSources, or all registered application DataSources if no list is provided.static Map[]getDataSourceSummaries(String[] dataSourceNames) static Map[]getDataSourceSummaries(String[] dataSourceNames, Map settings) Returns an array of summaries (seegetDataSourceSummary()) for the specified DataSources, or all registered application DataSources if no list is provided.static MapgetDataSourceSummary(DataSource dataSource) Returns a structured summary of a DataSource at a configurable detail level.static MapgetDataSourceSummary(DataSource dataSource, Map settings) Returns a structured summary of a DataSource at a configurable detail level.static MapgetDataSourceSummary(String dataSource) Returns a structured summary of a DataSource at a configurable detail level.static MapgetDataSourceSummary(String dataSource, Map settings) Returns a structured summary of a DataSource at a configurable detail level.static StringThe ID of the defaultAIEngineto use.static intThe defualt maximum number of retries for any one particular request to AI.static BooleanWhether AI is disabled.static AIEngineReturns theAIEnginehaving the given engine ID.static AIEngineReturns theAIEnginehaving the given engine ID.static StringReturns the currentmockingPolicy.static booleanDetermines whether AI support is enabled.static booleanReports whether the optional AI module is loaded for the page.static voidpauseDataQuestion(String questionId) Pauses a data question if not already paused or canceled.static booleanregisterEngine(AIEngine engine) Registers the givenAIEngine.static voidresumeDataQuestion(String questionId) Resumes a data question if paused.static voidsendPrompt(String dynamicString, Map context, AIResponseCallback callback) Evaluates the givendynamic stringto form a prompt string that is then sent as the request to the default AI engine.static voidsetDefaultEngineId(String defaultEngineId) The ID of the defaultAIEngineto use.static voidsetDefaultMaxRetries(int defaultMaxRetries) The defualt maximum number of retries for any one particular request to AI.static voidsetDisabled(Boolean disabled) Whether AI is disabled.static voidsetMockingPolicy(String policy) SetsmockingPolicy.static booleanunregisterEngine(String engineId) Unregisters anAIEnginespecified by its ID.
-
Constructor Details
-
AI
public AI()
-
-
Method Details
-
setDefaultEngineId
The ID of the defaultAIEngineto use.- Parameters:
defaultEngineId- new defaultEngineId. Default value is "gpt-4.1".
-
getDefaultEngineId
The ID of the defaultAIEngineto use.- Returns:
- current value of defaultEngineId
-
setDefaultMaxRetries
public static void setDefaultMaxRetries(int defaultMaxRetries) The defualt maximum number of retries for any one particular request to AI.- Parameters:
defaultMaxRetries- new defaultMaxRetries. Default value is 2.
-
getDefaultMaxRetries
public static int getDefaultMaxRetries()The defualt maximum number of retries for any one particular request to AI.- Returns:
- current value of defaultMaxRetries
-
setDisabled
Whether AI is disabled.By default, AI is disabled. This static property must be set to
falseand thedefaultAIEnginemust be registered in order to enable the use of AI in the application.- Parameters:
disabled- new disabled. Default value is true.
-
getDisabled
Whether AI is disabled.By default, AI is disabled. This static property must be set to
falseand thedefaultAIEnginemust be registered in order to enable the use of AI in the application.- Returns:
- current value of disabled
-
addMockResponses
Alias foraddSpoofedResponses().- Parameters:
responses- mock response entries
-
askDataQuestion
Asks AI to answer a question about the data of the application.- Parameters:
question- The text of the end-user's question or their request for an answer to a data question.
-
askDataQuestion
Asks AI to answer a question about the data of the application.- Parameters:
question- The text of the end-user's question or their request for an answer to a data question.
-
askDataQuestion
-
askDataQuestion
-
askDataQuestion
public static void askDataQuestion(String question, DataSource[] dataSources, DataQuestionSettings settings) -
askDataQuestion
public static void askDataQuestion(UserAIRequest question, DataSource[] dataSources, DataQuestionSettings settings) -
askDataQuestion
public static void askDataQuestion(String question, DataSource[] dataSources, DataQuestionSettings settings, AskDataQuestionResultCallback callback) Asks AI to answer a question about the data of the application.- Parameters:
question- The text of the end-user's question or their request for an answer to a data question.dataSources- The available data sources. All data sources in the array must have a global ID. Ifnull, then the array of all DataSources available to the AI module is used.settings- Settings to use when answering the data question.callback- The callback to call with the result.
-
askDataQuestion
public static void askDataQuestion(UserAIRequest question, DataSource[] dataSources, DataQuestionSettings settings, AskDataQuestionResultCallback callback) Asks AI to answer a question about the data of the application.- Parameters:
question- The text of the end-user's question or their request for an answer to a data question.dataSources- The available data sources. All data sources in the array must have a global ID. Ifnull, then the array of all DataSources available to the AI module is used.settings- Settings to use when answering the data question.callback- The callback to call with the result.
-
cancelDataQuestion
Cancels a data question if not already canceled.- Parameters:
questionId- The ID of the data question to cancel.
-
clearMockResponses
public static void clearMockResponses()Alias forclearSpoofedResponses(). -
getDataSourceSummaries
Returns an array of summaries (seegetDataSourceSummary()) for the specified DataSources, or all registered application DataSources if no list is provided. Thesettingsparameter is passed through to eachgetDataSourceSummary()call.- Returns:
- array of summary objects
-
getDataSourceSummaries
-
getDataSourceSummaries
Returns an array of summaries (seegetDataSourceSummary()) for the specified DataSources, or all registered application DataSources if no list is provided. Thesettingsparameter is passed through to eachgetDataSourceSummary()call.- Parameters:
dataSourceNames- DataSource IDs to summarize; defaults togetDataSourceNames()settings- passed through togetDataSourceSummary()- Returns:
- array of summary objects
-
getDataSourceSummary
Returns a structured summary of a DataSource at a configurable detail level. In"compact"mode (default), only identity metadata, primary key, and foreign key relationships are included ? suitable for large-app DS selection where full field listings would exceed the AI context window. Higher detail levels progressively add field information via anotherFieldsproperty.Detail levels (set via
settings.detail):"compact"? ID, title, description, fieldCount, pk, fk. No field list."salientNames"? addsotherFieldsas an array of field name strings for salient/critical fields (PK and FK fields already shown inpk/fkare excluded)."salientTyped"? like salientNames but each entry is an object withname,type, and optionallyrequiredandvalueMap."allTyped"? like salientTyped but includes all fields, not just salient ones."full"? all fields with the fullsalientFieldAttributesattribute mask.
Settings:
detail(String) ? one of the levels above; default"compact".maxFields(Integer) ? cap on the number of fields inotherFields.excludeHousekeeping(Boolean) ? omit auto-populated fields (creator, modifier, creatorTimestamp, modifierTimestamp); defaulttruefor all modes except"full".includeData(String) ? if set, includes representative data samples from available client-side caches. Values:"fieldValues"(per-field unique sample values added assampleValueson each field entry) or"records"(whole sample records added assampleRecords). Data is sourced from clientOnly cacheData, cacheAllData cacheResultSet, or any default-fetch (no operationId) ResultSet observing the DataSource ? no server requests are triggered.dataSampleCount(Integer) ? maximum unique sample values per field (fieldValues mode) or sample records (records mode); default 3.dataSampleMaxSearch(Integer) ? maximum cache records to scan when collecting unique sample values; default 100.
- Parameters:
dataSource- DataSource or ID- Returns:
- structured summary
- See Also:
-
getDataSourceSummary
Returns a structured summary of a DataSource at a configurable detail level. In"compact"mode (default), only identity metadata, primary key, and foreign key relationships are included ? suitable for large-app DS selection where full field listings would exceed the AI context window. Higher detail levels progressively add field information via anotherFieldsproperty.Detail levels (set via
settings.detail):"compact"? ID, title, description, fieldCount, pk, fk. No field list."salientNames"? addsotherFieldsas an array of field name strings for salient/critical fields (PK and FK fields already shown inpk/fkare excluded)."salientTyped"? like salientNames but each entry is an object withname,type, and optionallyrequiredandvalueMap."allTyped"? like salientTyped but includes all fields, not just salient ones."full"? all fields with the fullsalientFieldAttributesattribute mask.
Settings:
detail(String) ? one of the levels above; default"compact".maxFields(Integer) ? cap on the number of fields inotherFields.excludeHousekeeping(Boolean) ? omit auto-populated fields (creator, modifier, creatorTimestamp, modifierTimestamp); defaulttruefor all modes except"full".includeData(String) ? if set, includes representative data samples from available client-side caches. Values:"fieldValues"(per-field unique sample values added assampleValueson each field entry) or"records"(whole sample records added assampleRecords). Data is sourced from clientOnly cacheData, cacheAllData cacheResultSet, or any default-fetch (no operationId) ResultSet observing the DataSource ? no server requests are triggered.dataSampleCount(Integer) ? maximum unique sample values per field (fieldValues mode) or sample records (records mode); default 3.dataSampleMaxSearch(Integer) ? maximum cache records to scan when collecting unique sample values; default 100.
- Parameters:
dataSource- DataSource or ID- Returns:
- structured summary
- See Also:
-
getDataSourceSummary
Returns a structured summary of a DataSource at a configurable detail level. In"compact"mode (default), only identity metadata, primary key, and foreign key relationships are included ? suitable for large-app DS selection where full field listings would exceed the AI context window. Higher detail levels progressively add field information via anotherFieldsproperty.Detail levels (set via
settings.detail):"compact"? ID, title, description, fieldCount, pk, fk. No field list."salientNames"? addsotherFieldsas an array of field name strings for salient/critical fields (PK and FK fields already shown inpk/fkare excluded)."salientTyped"? like salientNames but each entry is an object withname,type, and optionallyrequiredandvalueMap."allTyped"? like salientTyped but includes all fields, not just salient ones."full"? all fields with the fullsalientFieldAttributesattribute mask.
Settings:
detail(String) ? one of the levels above; default"compact".maxFields(Integer) ? cap on the number of fields inotherFields.excludeHousekeeping(Boolean) ? omit auto-populated fields (creator, modifier, creatorTimestamp, modifierTimestamp); defaulttruefor all modes except"full".includeData(String) ? if set, includes representative data samples from available client-side caches. Values:"fieldValues"(per-field unique sample values added assampleValueson each field entry) or"records"(whole sample records added assampleRecords). Data is sourced from clientOnly cacheData, cacheAllData cacheResultSet, or any default-fetch (no operationId) ResultSet observing the DataSource ? no server requests are triggered.dataSampleCount(Integer) ? maximum unique sample values per field (fieldValues mode) or sample records (records mode); default 3.dataSampleMaxSearch(Integer) ? maximum cache records to scan when collecting unique sample values; default 100.
- Parameters:
dataSource- DataSource or IDsettings- detail level and field options- Returns:
- structured summary
- See Also:
-
getDataSourceSummary
Returns a structured summary of a DataSource at a configurable detail level. In"compact"mode (default), only identity metadata, primary key, and foreign key relationships are included ? suitable for large-app DS selection where full field listings would exceed the AI context window. Higher detail levels progressively add field information via anotherFieldsproperty.Detail levels (set via
settings.detail):"compact"? ID, title, description, fieldCount, pk, fk. No field list."salientNames"? addsotherFieldsas an array of field name strings for salient/critical fields (PK and FK fields already shown inpk/fkare excluded)."salientTyped"? like salientNames but each entry is an object withname,type, and optionallyrequiredandvalueMap."allTyped"? like salientTyped but includes all fields, not just salient ones."full"? all fields with the fullsalientFieldAttributesattribute mask.
Settings:
detail(String) ? one of the levels above; default"compact".maxFields(Integer) ? cap on the number of fields inotherFields.excludeHousekeeping(Boolean) ? omit auto-populated fields (creator, modifier, creatorTimestamp, modifierTimestamp); defaulttruefor all modes except"full".includeData(String) ? if set, includes representative data samples from available client-side caches. Values:"fieldValues"(per-field unique sample values added assampleValueson each field entry) or"records"(whole sample records added assampleRecords). Data is sourced from clientOnly cacheData, cacheAllData cacheResultSet, or any default-fetch (no operationId) ResultSet observing the DataSource ? no server requests are triggered.dataSampleCount(Integer) ? maximum unique sample values per field (fieldValues mode) or sample records (records mode); default 3.dataSampleMaxSearch(Integer) ? maximum cache records to scan when collecting unique sample values; default 100.
- Parameters:
dataSource- DataSource or IDsettings- detail level and field options- Returns:
- structured summary
- See Also:
-
getEngine
Returns theAIEnginehaving the given engine ID.- Returns:
- the
AIEngine, ornullif theAIEnginecould not be found.
-
getEngine
Returns theAIEnginehaving the given engine ID.- Parameters:
engineId- the engineId of theAIEngineto get. If not specified,defaultEngineIdis used.- Returns:
- the
AIEngine, ornullif theAIEnginecould not be found.
-
getMockingPolicy
Returns the currentmockingPolicy. The return value is always one of"none","auto", or"interactive"; the legacyresponseSpoofingModevalues"hybrid"and"full"are normalized before returning.- Returns:
- The current mocking policy: "none", "auto", or "interactive"
-
isEnabled
public static boolean isEnabled()Determines whether AI support is enabled.disabledmust be set tofalseand the defaultAIEnginemust be registered in order to enable the use of AI.- Returns:
trueif the use of AI is enabled;falseotherwise.- See Also:
-
com.smartgwt.client.ai.AI#disabledcom.smartgwt.client.ai.AI#defaultEngineId
-
pauseDataQuestion
Pauses a data question if not already paused or canceled.- Parameters:
questionId- The ID of the data question to pause.
-
registerEngine
Registers the givenAIEngine.- Parameters:
engine- TheAIEngineto register.- Returns:
trueif theAIEnginewas successfully registered;falseotherwise.- See Also:
-
resumeDataQuestion
Resumes a data question if paused.- Parameters:
questionId- The ID of the data question to resume.
-
sendPrompt
Evaluates the givendynamic stringto form a prompt string that is then sent as the request to the default AI engine.Within
dynamicString, any evaluated JavaScript expressions have access to all of the values in thecontextValueMap.- Parameters:
dynamicString- A dynamic string. SeeDynamicStringcontext- A map from each in-scopeIdentifierto its value.callback- The callback to fire with the response from AI.
-
setMockingPolicy
SetsmockingPolicy. Pass one of"none","auto", or"interactive".- Parameters:
policy- The mocking policy: "none", "auto", or "interactive"
-
unregisterEngine
Unregisters anAIEnginespecified by its ID.- Parameters:
engineId- the ID of theAIEngineto unregister.- Returns:
trueif theAIEnginewas successfully unregistered;falseotherwise.- See Also:
-
moduleLoaded
public static boolean moduleLoaded()Reports whether the optional AI module is loaded for the page.- Returns:
- true if and only if the AI module has been loaded
-
checkModuleLoaded
-