Package com.smartgwt.client.ai

# Class AIEngine

java.lang.Object
com.smartgwt.client.core.BaseClass
com.smartgwt.client.ai.AIEngine

All Implemented Interfaces:
  `HasHandlers`

public class AIEngine extends BaseClass
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
  Constructor
  Description
  `AIEngine()`
  `AIEngine(JavaScriptObject jsObj)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `canSupportVisionRequests()`
  Whether this AI engine can handle vision requests, or requests where one or more of the messages is an image.
  `boolean`
  `couldSupportRequest(AIRequest aiRequest)`
  Determines whether this engine could support the given request.
  `JavaScriptObject`
  `create()`
  `String`
  `getEngineId()`
  The unique ID of this engine.
  `JavaScriptObject`
  `getJsObj()`
  `String`
  `getName()`
  The local name of this engine.
  `JavaScriptObject`
  `getOrCreateJsObj()`
  `static AIEngine`
  `getOrCreateRef(JavaScriptObject jsObj)`
  `String`
  `getProvider()`
  The provider of this engine.
  `Boolean`
  `getSupportsTemperature()`
  Whether this model supports `temperature`.
  `Double`
  `getTemperature()`
  Optional temperature of the model.
  `boolean`
  `isAPIKeyError(String rawResponse)`
  Returns `true` if the given raw AI response represents an API key authentication failure from the provider (e.g.
  `boolean`
  `isAPIKeyError(Map rawResponse)`
  Returns `true` if the given raw AI response represents an API key authentication failure from the provider (e.g.
  `boolean`
  `isCreated()`
  `void`
  `sendRequest(AIRequest aiRequest, AIResponseCallback callback)`
  Sends a request to this AI engine.
  `AIEngine`
  `setEngineId(String engineId)`
  The unique ID of this engine.
  `void`
  `setJavaScriptObject(JavaScriptObject jsObj)`
  `AIEngine`
  `setName(String name)`
  The local name of this engine.
  `AIEngine`
  `setProvider(String provider)`
  The provider of this engine.
  `AIEngine`
  `setSupportsTemperature(Boolean supportsTemperature)`
  Whether this model supports `temperature`.
  `AIEngine`
  `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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AIEngine

    public AIEngine()

  - ### AIEngine

    public AIEngine(JavaScriptObject jsObj)

- ## Method Details

  - ### getOrCreateRef

    public static AIEngine getOrCreateRef(JavaScriptObject jsObj)

  - ### setJavaScriptObject

    public void setJavaScriptObject(JavaScriptObject jsObj)
    Overrides:
      `setJavaScriptObject` in class `BaseClass`

  - ### create

    public JavaScriptObject create()
    Specified by:
      `create` in class `BaseClass`

  - ### isCreated

    public boolean isCreated()
    Overrides:
      `isCreated` in class `BaseClass`

  - ### getJsObj

    public JavaScriptObject getJsObj()
    Overrides:
      `getJsObj` in class `BaseClass`

  - ### getOrCreateJsObj

    public JavaScriptObject getOrCreateJsObj()
    Overrides:
      `getOrCreateJsObj` in class `BaseClass`

  - ### setEngineId

    public AIEngine setEngineId(String engineId) throws IllegalStateException
    The unique ID of this engine.
    Parameters:
      `engineId` - New engineId value. Default value is null
    Returns:
      `AIEngine` instance, for chaining setter calls
    Throws:
      `IllegalStateException` - this property cannot be changed after the underlying component has been created

  - ### getEngineId

    public String getEngineId()
    The unique ID of this engine.
    Returns:
      Current engineId value. Default value is null

  - ### setName

    public AIEngine setName(String name) throws IllegalStateException
    The local name of this engine.
    Parameters:
      `name` - New name value. Default value is null
    Returns:
      `AIEngine` instance, for chaining setter calls
    Throws:
      `IllegalStateException` - this property cannot be changed after the underlying component has been created

  - ### getName

    public String getName()
    The local name of this engine.
    Returns:
      Current name value. Default value is null

  - ### setProvider

    public AIEngine setProvider(String provider) throws IllegalStateException
    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:
      `AIEngine` instance, for chaining setter calls
    Throws:
      `IllegalStateException` - this property cannot be changed after the underlying component has been created

  - ### getProvider

    public String 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

    public AIEngine setSupportsTemperature(Boolean supportsTemperature) throws IllegalStateException
    Whether this model supports `temperature`. If this is false, any `temperature` configured at engine or reuqest level will be ignored
    Parameters:
      `supportsTemperature` - New supportsTemperature value. Default value is true
    Returns:
      `AIEngine` instance, for chaining setter calls
    Throws:
      `IllegalStateException` - this property cannot be changed after the underlying component has been created

  - ### getSupportsTemperature

    public Boolean getSupportsTemperature()
    Whether this model supports `temperature`. If this is false, any `temperature` configured at engine or reuqest level will be ignored
    Returns:
      Current supportsTemperature value. Default value is true

  - ### setTemperature

    public AIEngine setTemperature(Double temperature) throws IllegalStateException
    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:
      `AIEngine` instance, for chaining setter calls
    Throws:
      `IllegalStateException` - this property cannot be changed after the underlying component has been created
    See Also:
      - `setSupportsTemperature(java.lang.Boolean)`

  - ### getTemperature

    public Double 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:
      - `getSupportsTemperature()`

  - ### 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:
      `true` if this AI engine can handle vision requests; `false` otherwise.

  - ### couldSupportRequest

    public boolean couldSupportRequest(AIRequest aiRequest)
    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:
      `true` if this AIEngine could support the request; `false` otherwise.

  - ### isAPIKeyError

    public boolean isAPIKeyError(String rawResponse)
    Returns `true` if 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 `AIEngine` subclasses to add provider-specific recognition logic.

    Parameters:
      `rawResponse` - The raw provider error response, as received by `getErrorResponseInfo`.
    Returns:
      `true` if this is an API key / authentication error.

  - ### isAPIKeyError

    public boolean isAPIKeyError(Map rawResponse)
    Returns `true` if 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 `AIEngine` subclasses to add provider-specific recognition logic.

    Parameters:
      `rawResponse` - The raw provider error response, as received by `getErrorResponseInfo`.
    Returns:
      `true` if this is an API key / authentication error.

  - ### sendRequest

    public void sendRequest(AIRequest aiRequest, AIResponseCallback callback)
    Sends a request to this AI engine.
    Parameters:
      `aiRequest` - The request.
      `callback` - The callback to fire with the response.