Class AbstractModel
java.lang.Object
uno.anahata.asi.agi.provider.AbstractModel
- Direct Known Subclasses:
AnthropicModel, GeminiModel, OpenAiCompatibleModel, OpenAiModel
The abstract base class for a specific AI model (e.g.,
"gemini-1.5-pro-latest"). In the V2 architecture, this class is the
definitive entry point for generating content, creating a clean,
object-oriented API where the model itself is the actor.
- Author:
- anahata-gemini-pro-2.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FloatThe default temperature setting for this model, or null if unspecified.protected IntegerThe default Top-K setting for this model, or null if unspecified.protected FloatThe default Top-P setting for this model, or null if unspecified.protected StringHuman-readable description of this model's capabilities and limitations.protected StringUser-facing or API display name for this model.protected booleanWhether this model is enabled and offered in model selectors and tool listings.static final StringMarkdown table header for model listings.protected IntegerThe maximum number of input tokens allowed, or null if unspecified.protected IntegerThe maximum number of output tokens this model can generate in a single turn, or null if unspecified.protected AbstractAiProviderThe parent AI provider that owns this model instance.protected StringThe raw description or raw JSON representation of the model as received from the remote API endpoint.The list of API actions supported by this model (e.g.protected List<ResponseModality> The list of response modalities supported by this model (e.g., TEXT, IMAGE, AUDIO, VIDEO).protected TokenizerTypeThe optional model-specific tokenizer.protected StringThe version identifier for this model. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract intcountTokens(byte[] data, String mimeType) Counts the number of tokens consumed by raw binary data based on its MIME type and model-specific multimodal billing rules.abstract intcountTokens(String text) Counts the number of tokens in the given text string using this model's specific tokenizer.abstract intcountTokens(AbstractToolCall<?, ?> toolCall) Counts the number of tokens consumed by the given tool call in the context window.abstract intcountTokens(AbstractToolResponse<?> toolResponse) Counts the number of tokens consumed by the given tool execution response.abstract ResponsegenerateContent(GenerationRequest request) The core method for interacting with an AI model.abstract voidgenerateContentStream(GenerationRequest request, StreamObserver<Response<? extends AbstractModelMessage>> observer) Generates content asynchronously using token streaming.abstract List<ServerTool> Gets the list of server-side tools available for this model.abstract List<ServerTool> Gets the list of server-side tools that should be enabled by default for this model.abstract StringGets the unique identifier for this model (e.g., "models/gemini-1.5-pro").final StringDelegate method to get the id of this models provider.Gets the effective tokenizer type for this model.abstract StringgetToolDeclarationJson(AbstractTool<?, ?> tool, RequestConfig config) Gets the provider-specific JSON representation of a tool's declaration.booleanChecks if this locally registered model entity has different configuration values compared to its corresponding cached API model in the provider.booleanChecks if this model is registered in its parent provider's master persisted models list.abstract booleanChecks if this model supports batch embedding generation.abstract booleanChecks if this model supports content caching.abstract booleanChecks if this model supports content generation.abstract booleanChecks if this model supports single content embedding generation.abstract booleanChecks if this model supports native function calling (tools).booleanmatches(Pattern queryPattern, Set<ResponseModality> targetModalities) Checks if this model matches a search query (regex or substring) AND all target response modalities.voidpersist()Persists this model entity directly to disk in its parent provider's models directory (~/.anahata/asi/<provider>/models/<model_id>.kryo).voidremove()Deletes the persisted .kryo file for this model from disk and removes it from its parent provider.voidResets this locally registered model entity from its cached API model counterpart and persists changes to disk.Formats this model as a Markdown table row for model listing and discovery tools.static StringtoSafeModelFileName(String modelId) Converts a model ID into a safe filename with .kryo extension.toString()Returning the display name
-
Field Details
-
MARKUP_TABLE_HEADER
-
provider
The parent AI provider that owns this model instance. Mark transient to prevent serialization of provider graph in model caches. -
enabled
protected boolean enabledWhether this model is enabled and offered in model selectors and tool listings. -
tokenizerType
The optional model-specific tokenizer. If null, the provider's default is used. -
displayName
User-facing or API display name for this model. -
description
Human-readable description of this model's capabilities and limitations. -
version
The version identifier for this model. -
maxInputTokens
The maximum number of input tokens allowed, or null if unspecified. -
maxOutputTokens
The maximum number of output tokens this model can generate in a single turn, or null if unspecified. -
defaultTemperature
The default temperature setting for this model, or null if unspecified. -
defaultTopP
The default Top-P setting for this model, or null if unspecified. -
defaultTopK
The default Top-K setting for this model, or null if unspecified. -
supportedResponseModalities
The list of response modalities supported by this model (e.g., TEXT, IMAGE, AUDIO, VIDEO). -
supportedActions
-
rawDescription
The raw description or raw JSON representation of the model as received from the remote API endpoint.
-
-
Constructor Details
-
AbstractModel
public AbstractModel()
-
-
Method Details
-
isRegistered
public boolean isRegistered()Checks if this model is registered in its parent provider's master persisted models list.- Returns:
- true if this model exists in
provider.getModels(), false otherwise.
-
hasDiscrepancy
public boolean hasDiscrepancy()Checks if this locally registered model entity has different configuration values compared to its corresponding cached API model in the provider.- Returns:
- true if any field value differs, false if identical or no cached API model is available.
- Throws:
IllegalStateException- if called on an unregistered model.
-
resetFromApi
Resets this locally registered model entity from its cached API model counterpart and persists changes to disk.- Throws:
IOException- if persisting the updated model fails.IllegalStateException- if this model is not registered or no cached API model is available.
-
toSafeModelFileName
-
persist
Persists this model entity directly to disk in its parent provider's models directory (~/.anahata/asi/<provider>/models/<model_id>.kryo).- Throws:
IOException- If creating the directory or saving the file fails.
-
remove
Deletes the persisted .kryo file for this model from disk and removes it from its parent provider.- Throws:
IOException- If deleting the file fails.
-
getTokenizerType
Gets the effective tokenizer type for this model.- Returns:
- The model's tokenizer if set, otherwise the parent provider's tokenizer.
-
countTokens
Counts the number of tokens in the given text string using this model's specific tokenizer.- Parameters:
text- The text to count tokens for.- Returns:
- The number of tokens, or 0 if the text is null or empty.
-
countTokens
Counts the number of tokens consumed by the given tool call in the context window.Model subclasses override this method to serialize the tool call into its exact wire-format (JSON, Protobuf, etc.) to ensure 100% accurate billing.
- Parameters:
toolCall- The tool call to count tokens for.- Returns:
- The precise token count.
-
countTokens
Counts the number of tokens consumed by raw binary data based on its MIME type and model-specific multimodal billing rules.This generic signature provides complete decoupling from domain part classes, allowing the model to tokenize any binary payload (such as blob parts or tool attachments).
- Parameters:
data- The raw binary data.mimeType- The MIME type of the binary data (e.g. "image/png").- Returns:
- The precise token count, or 0 if no model is active or the data is null.
-
countTokens
Counts the number of tokens consumed by the given tool execution response.Model subclasses override this to serialize the response into its exact wire-format (Protobuf FunctionResponse, JSON, etc.) to ensure 100% accurate billing.
- Parameters:
toolResponse- The tool response to count tokens for.- Returns:
- The exact number of tokens.
-
getModelId
Gets the unique identifier for this model (e.g., "models/gemini-1.5-pro").- Returns:
- The model ID.
-
getProviderId
Delegate method to get the id of this models provider.- Returns:
- The unique ID of the provider.
-
isSupportsFunctionCalling
public abstract boolean isSupportsFunctionCalling()Checks if this model supports native function calling (tools).- Returns:
- true if supported.
-
isSupportsContentGeneration
public abstract boolean isSupportsContentGeneration()Checks if this model supports content generation.- Returns:
- true if supported.
-
isSupportsBatchEmbeddings
public abstract boolean isSupportsBatchEmbeddings()Checks if this model supports batch embedding generation.- Returns:
- true if supported.
-
isSupportsEmbeddings
public abstract boolean isSupportsEmbeddings()Checks if this model supports single content embedding generation.- Returns:
- true if supported.
-
isSupportsCachedContent
public abstract boolean isSupportsCachedContent()Checks if this model supports content caching.- Returns:
- true if supported.
-
matches
Checks if this model matches a search query (regex or substring) AND all target response modalities.- Parameters:
queryPattern- Optional compiled regex pattern to match against model attributes. If null, matches all.targetModalities- Optional set of required response modalities. If not empty, the model must support ALL specified modalities.- Returns:
- true if the model satisfies all active criteria (AND logic).
-
getAvailableServerTools
Gets the list of server-side tools available for this model.- Returns:
- A list of available server tools.
-
getDefaultServerTools
Gets the list of server-side tools that should be enabled by default for this model.- Returns:
- The list of default server tools.
-
generateContent
The core method for interacting with an AI model. It takes a configuration object and a list of messages and returns a standardized Response.- Parameters:
request- The generation request containing config and history.- Returns:
- A standardized
Responseobject.
-
generateContentStream
public abstract void generateContentStream(GenerationRequest request, StreamObserver<Response<? extends AbstractModelMessage>> observer) Generates content asynchronously using token streaming.- Parameters:
request- The generation request containing config and history.observer- The observer that will receive the streaming response chunks.
-
getToolDeclarationJson
Gets the provider-specific JSON representation of a tool's declaration. This is used by the UI to show exactly what is being sent to the model.- Parameters:
tool- The tool to inspect.config- The request configuration (e.g. to check useNativeSchemas).- Returns:
- The JSON string representing the tool declaration.
-
toString
-
toMarkupRow
Formats this model as a Markdown table row for model listing and discovery tools.- Returns:
- A Markdown row representing this model.
-

