Package com.tnsai.llm
Interface LLMCapabilities
- All Known Implementing Classes:
ModelCapabilities
public interface LLMCapabilities
Describes the capabilities of an LLM provider/model.
LLMCapabilities provides a standardized way to discover what features a particular LLM model supports. This enables capability-driven model selection, automatic fallback, and smart routing.
Why Capabilities?
Different LLM models have vastly different capabilities:
- GPT-4o supports vision, but GPT-3.5 doesn't
- Some models support function calling, others don't
- Context windows vary from 4K to 2M tokens
- Not all models support JSON mode
With LLMCapabilities, you can:
// Auto-select a vision model
LLMClient client = router.selectByCapability(cap -> cap.supportsVision());
// Fallback if function calling not available
if (!client.getCapabilities().supportsFunctionCalling()) {
return handleWithoutTools(message);
}
Usage Example
LLMClient client = new OpenAIClient("gpt-4o");
LLMCapabilities caps = client.getCapabilities();
// Check capabilities before use
if (caps.supportsVision()) {
response = client.chat(List.of(textPart, imagePart), system, history, tools);
} else {
response = client.chat(textPart.getText(), system, history, tools);
}
// Check context limit
int maxContext = caps.getMaxInputTokens();
if (estimatedTokens > maxContext) {
// Truncate or summarize
}
Capability Discovery
Capabilities can be discovered in two ways:
- Static: Hardcoded based on model name (fast, offline)
- Runtime: Queried from provider API (accurate, requires API call)
Model Profiles
Common model capability profiles:
| Model | Vision | Tools | JSON | Context |
|---|---|---|---|---|
| GPT-4o | Yes | Yes | Yes | 128K |
| GPT-4-turbo | Yes | Yes | Yes | 128K |
| GPT-3.5-turbo | No | Yes | Yes | 16K |
| Claude Sonnet 4 | Yes | Yes | Yes | 200K |
| Claude 3 Opus | Yes | Yes | Yes | 200K |
| Gemini 2.5 Flash | Yes | Yes | Yes | 1M |
| Llama 3.2 | No | Yes | No | 128K |
| Mistral Large | No | Yes | Yes | 128K |
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumInput modalities the model can process. -
Method Summary
Modifier and TypeMethodDescriptionReturns additional provider-specific capabilities.default intTotal context window (usually same as maxInputTokens for most models).default StringReturns a human-readable description of the model.Estimated average latency for first token (TTFT) in milliseconds.Cost per 1000 input tokens in USD.intMaximum input tokens (context window).intMaximum output tokens the model can generate.The model identifier.Model version if applicable.Cost per 1000 output tokens in USD.The provider name (OpenAI, Anthropic, Google, etc.).Returns the list of supported input modalities.default booleanWhethergetMaxInputTokens()is the model's own window rather than a placeholder for a model the provider does not list.default booleanmeetsRequirements(boolean requiresVision, boolean requiresTools, int minContextTokens) Checks if the model is suitable for a given use case.default voidValidates that this model supports streaming.default voidValidates that this model supports tool/function calling.default voidValidates that this model supports vision/image input.default booleanWhether the model supports code execution (like Code Interpreter).default booleanWhether the model supports file uploads.booleanWhether the model supports function/tool calling.default booleansupportsModality(LLMCapabilities.Modality modality) Checks if a specific modality is supported.default booleanWhether the model supports parallel function calls.default booleanWhether the model has reasoning/thinking capabilities (like o1).booleanWhether the model supports streaming responses.booleanWhether the model supports structured JSON output mode.default booleanWhether the model supports system prompts.booleanWhether the model can process images (vision capability).default booleanWhether the model supports web browsing.
-
Method Details
-
supportsStreaming
boolean supportsStreaming()Whether the model supports streaming responses. Most modern LLMs support this. -
supportsVision
boolean supportsVision()Whether the model can process images (vision capability). Examples: GPT-4o, Claude 3, Gemini -
supportsFunctionCalling
boolean supportsFunctionCalling()Whether the model supports function/tool calling. This is critical for agent-based applications. -
supportsStructuredOutput
boolean supportsStructuredOutput()Whether the model supports structured JSON output mode. When enabled, model output is guaranteed to be valid JSON. -
supportsSystemPrompt
default boolean supportsSystemPrompt()Whether the model supports system prompts. Some older models don't distinguish system from user messages. -
supportsParallelFunctionCalls
default boolean supportsParallelFunctionCalls()Whether the model supports parallel function calls. Some models can request multiple tool calls in a single response. -
getMaxInputTokens
int getMaxInputTokens()Maximum input tokens (context window). This is the combined limit for system prompt + history + user message. -
knowsInputWindow
default boolean knowsInputWindow()WhethergetMaxInputTokens()is the model's own window rather than a placeholder for a model the provider does not list. A caller that sizes a budget from the window treats a placeholder as unknown.- Returns:
trueunless the window is a placeholder- Since:
- 0.18.0
-
getMaxOutputTokens
int getMaxOutputTokens()Maximum output tokens the model can generate. Some models have separate input/output limits. -
getContextWindow
default int getContextWindow()Total context window (usually same as maxInputTokens for most models). -
getSupportedModalities
Set<LLMCapabilities.Modality> getSupportedModalities()Returns the list of supported input modalities.- Returns:
- Set of supported modalities (TEXT, IMAGE, AUDIO, etc.)
-
supportsModality
Checks if a specific modality is supported. -
getProviderName
String getProviderName()The provider name (OpenAI, Anthropic, Google, etc.). -
getModelId
String getModelId()The model identifier. -
getModelVersion
Model version if applicable. -
getInputCostPer1KTokens
Cost per 1000 input tokens in USD. Returns empty if pricing not available. -
getOutputCostPer1KTokens
Cost per 1000 output tokens in USD. Returns empty if pricing not available. -
getEstimatedLatencyMs
Estimated average latency for first token (TTFT) in milliseconds. Useful for latency-sensitive applications. -
supportsCodeExecution
default boolean supportsCodeExecution()Whether the model supports code execution (like Code Interpreter). -
supportsWebBrowsing
default boolean supportsWebBrowsing()Whether the model supports web browsing. -
supportsFileUpload
default boolean supportsFileUpload()Whether the model supports file uploads. -
supportsReasoning
default boolean supportsReasoning()Whether the model has reasoning/thinking capabilities (like o1). -
getAdditionalCapabilities
Returns additional provider-specific capabilities. This is an extension point for capabilities not covered by the interface. -
getDescription
Returns a human-readable description of the model. -
meetsRequirements
default boolean meetsRequirements(boolean requiresVision, boolean requiresTools, int minContextTokens) Checks if the model is suitable for a given use case.- Parameters:
requiresVision- Whether vision capability is requiredrequiresTools- Whether function calling is requiredminContextTokens- Minimum context window size- Returns:
- true if the model meets all requirements
-
requireToolCalling
default void requireToolCalling()Validates that this model supports tool/function calling.Call this before sending tools to the LLM to get a clear error instead of silent failure or a generic exception.
- Throws:
ToolCallNotSupportedException- if tool calling is not supported
-
requireStreaming
default void requireStreaming()Validates that this model supports streaming.- Throws:
LLMCapabilityException- if streaming is not supported
-
requireVision
default void requireVision()Validates that this model supports vision/image input.- Throws:
LLMCapabilityException- if vision is not supported
-