Package com.smartgwt.client.ai
Class AIEngine
java.lang.Object
com.smartgwt.client.core.BaseClass
com.smartgwt.client.ai.AIEngine
- All Implemented Interfaces:
HasHandlers
Provides access to a particular generative AI model.
-
Field Summary
Fields inherited from class com.smartgwt.client.core.BaseClass
config, configOnly, factoryCreated, factoryProperties, id, scClassName -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this AI engine can handle vision requests, or requests where one or more of the messages is an image.booleancouldSupportRequest(AIRequest aiRequest) Determines whether this engine could support the given request.create()The unique ID of this engine.getJsObj()getName()The local name of this engine.static AIEnginegetOrCreateRef(JavaScriptObject jsObj) The provider of this engine.Whether this model supportstemperature.Optional temperature of the model.booleanisAPIKeyError(String rawResponse) Returnstrueif the given raw AI response represents an API key authentication failure from the provider (e.g.booleanisAPIKeyError(Map rawResponse) Returnstrueif the given raw AI response represents an API key authentication failure from the provider (e.g.booleanvoidsendRequest(AIRequest aiRequest, AIResponseCallback callback) Sends a request to this AI engine.setEngineId(String engineId) The unique ID of this engine.voidThe local name of this engine.setProvider(String provider) The provider of this engine.setSupportsTemperature(Boolean supportsTemperature) Whether this model supportstemperature.setTemperature(Double temperature) Optional temperature of the model.Methods inherited from class com.smartgwt.client.core.BaseClass
addDynamicProperty, addDynamicProperty, addDynamicProperty, addDynamicProperty, applyFactoryProperties, asSGWTComponent, clearDynamicProperty, createJsObj, destroy, doAddHandler, doInit, error, error, errorIfNotCreated, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsJavaScriptObject, getAttributeAsMap, getAttributeAsString, getAttributeAsStringArray, getClassName, getConfig, getHandlerCount, getID, getRef, getRuleScope, getScClassName, getTestInstance, hasAutoAssignedID, hasDynamicProperty, internalSetID, internalSetID, isConfigOnly, isFactoryCreated, onBind, onInit, registerID, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setConfig, setConfigOnly, setFactoryCreated, setID, setProperty, setProperty, setProperty, setProperty, setRuleScope, setScClassName
-
Constructor Details
-
AIEngine
public AIEngine() -
AIEngine
-
-
Method Details
-
getOrCreateRef
-
setJavaScriptObject
- Overrides:
setJavaScriptObjectin classBaseClass
-
create
-
isCreated
public boolean isCreated() -
getJsObj
-
getOrCreateJsObj
- Overrides:
getOrCreateJsObjin classBaseClass
-
setEngineId
The unique ID of this engine.- Parameters:
engineId- New engineId value. Default value is null- Returns:
AIEngineinstance, for chaining setter calls- Throws:
IllegalStateException- this property cannot be changed after the underlying component has been created
-
getEngineId
The unique ID of this engine.- Returns:
- Current engineId value. Default value is null
-
setName
The local name of this engine.- Parameters:
name- New name value. Default value is null- Returns:
AIEngineinstance, for chaining setter calls- Throws:
IllegalStateException- this property cannot be changed after the underlying component has been created
-
getName
The local name of this engine.- Returns:
- Current name value. Default value is null
-
setProvider
The provider of this engine. Typically this is the name of the company or organization that provides access to the AI model.- Parameters:
provider- New provider value. Default value is null- Returns:
AIEngineinstance, for chaining setter calls- Throws:
IllegalStateException- this property cannot be changed after the underlying component has been created
-
getProvider
The provider of this engine. Typically this is the name of the company or organization that provides access to the AI model.- Returns:
- Current provider value. Default value is null
-
setSupportsTemperature
Whether this model supportstemperature. If this is false, anytemperatureconfigured at engine or reuqest level will be ignored- Parameters:
supportsTemperature- New supportsTemperature value. Default value is true- Returns:
AIEngineinstance, for chaining setter calls- Throws:
IllegalStateException- this property cannot be changed after the underlying component has been created
-
getSupportsTemperature
Whether this model supportstemperature. If this is false, anytemperatureconfigured at engine or reuqest level will be ignored- Returns:
- Current supportsTemperature value. Default value is true
-
setTemperature
Optional temperature of the model. This is a number between 0 and 1 denoting how much variation to receive in results.- Parameters:
temperature- New temperature value. Default value is null- Returns:
AIEngineinstance, for chaining setter calls- Throws:
IllegalStateException- this property cannot be changed after the underlying component has been created- See Also:
-
getTemperature
Optional temperature of the model. This is a number between 0 and 1 denoting how much variation to receive in results.- Returns:
- Current temperature value. Default value is null
- See Also:
-
canSupportVisionRequests
public boolean canSupportVisionRequests()Whether this AI engine can handle vision requests, or requests where one or more of the messages is an image.- Returns:
trueif this AI engine can handle vision requests;falseotherwise.
-
couldSupportRequest
Determines whether this engine could support the given request.The reason for the uncertainty is that the implementation may use estimates (e.g. the number of tokens in a given message, as applied to input token limits), or an AI may decide to refuse to respond to the request.
- Parameters:
aiRequest- The request to check.- Returns:
trueif this AIEngine could support the request;falseotherwise.
-
isAPIKeyError
Returnstrueif the given raw AI response represents an API key authentication failure from the provider (e.g. invalid key, missing key, or permission denied). The base implementation recognises the OpenAI-compatible error shape used by OpenAI and most OpenAI-API-compatible providers.Override this method in
AIEnginesubclasses to add provider-specific recognition logic.- Parameters:
rawResponse- The raw provider error response, as received bygetErrorResponseInfo.- Returns:
trueif this is an API key / authentication error.
-
isAPIKeyError
Returnstrueif the given raw AI response represents an API key authentication failure from the provider (e.g. invalid key, missing key, or permission denied). The base implementation recognises the OpenAI-compatible error shape used by OpenAI and most OpenAI-API-compatible providers.Override this method in
AIEnginesubclasses to add provider-specific recognition logic.- Parameters:
rawResponse- The raw provider error response, as received bygetErrorResponseInfo.- Returns:
trueif this is an API key / authentication error.
-
sendRequest
Sends a request to this AI engine.- Parameters:
aiRequest- The request.callback- The callback to fire with the response.
-