Package com.tnsai.llm.providers
package com.tnsai.llm.providers
LLM provider implementations for various AI services.
This package contains concrete implementations of the LLMClient
interface for different LLM providers. Each client handles provider-specific
API details while exposing a unified interface.
Available Providers
| Client | Provider | API Key Env Var |
|---|---|---|
OpenAIClient | OpenAI | OPENAI_API_KEY |
AzureOpenAIClient | Azure OpenAI | AZURE_OPENAI_API_KEY |
AnthropicClient | Anthropic | ANTHROPIC_API_KEY |
GeminiClient | Google Gemini | GEMINI_API_KEY |
OllamaClient | Ollama (local) | N/A |
GroqClient | Groq | GROQ_API_KEY |
OpenRouterClient | OpenRouter | OPENROUTER_API_KEY |
MistralClient | Mistral AI | MISTRAL_API_KEY |
BedrockClient | AWS Bedrock | AWS credentials |
Common Features
- Retry Logic: Exponential backoff on rate limits (429) and server errors (5xx)
- Tool Calling: Function/tool support where provider allows
- Configurable: Model, temperature, max tokens, etc.
- Error Handling: Provider-specific error mapping to common exceptions
Usage Examples
OpenAI
LLMClient client = new OpenAIClient("gpt-4");
String response = client.chat("Explain quantum computing");
Anthropic
LLMClient client = new AnthropicClient("claude-3-opus-20240229");
String response = client.chat("Write a haiku about programming");
Ollama (Local)
LLMClient client = new OllamaClient("llama2");
// Uses localhost:11434 by default
String response = client.chat("What is 2+2?");
Gemini with Images
GeminiClient client = new GeminiClient("gemini-pro-vision");
List<ContentPart> parts = List.of(
new TextPart("Describe this image"),
ImagePart.fromBase64(imageData, "image/jpeg")
);
String response = client.chat(parts);
Provider Selection Guide
- Best quality: GPT-4, Claude 3 Opus, Gemini Ultra
- Best speed: Groq (Llama/Mixtral), GPT-3.5-turbo
- Best value: OpenRouter, Ollama (free local)
- Enterprise: Azure OpenAI, AWS Bedrock
- Privacy: Ollama (local), Azure (private deployment)
- See Also:
-
ClassDescriptionAbstract base class for LLM client implementations.Base class for providers that speak the OpenAI
/chat/completionswire format verbatim — same request body, samechoices[].messageresponse, samechoices[].deltastreaming, Bearer auth.Anthropic Claude LLM client implementation.Builder for creating AnthropicClient instances.Translates the OpenAI-flavoured intermediate tool schema into Anthropic's Messages-API tool shape.Azure OpenAI Service client implementation.Authentication type for Azure OpenAI.Exception thrown when Azure OpenAI content filter rejects the request.AWS Bedrock LLM client implementation.Cerebras LLM client.Cohere LLM client implementation.Translates the OpenAI-flavoured intermediate tool schema into Cohere's chat-API tool shape.Databricks Mosaic AI Model Serving LLM client.DeepInfra LLM client.DeepSeek LLM client.Fireworks.ai LLM client.Google Gemini LLM client with multimodal support (text, image, audio, video).Groq LLM client implementation.HuggingFace Inference API client using OpenAI-compatible endpoint.llama.cpp server LLM client.LM Studio LLM client.MiniMax LLM client implementation.Mistral AI LLM client implementation.NVIDIA NIM (NVIDIA Inference Microservices) LLM client.Ollama LLM client implementation for local and cloud deployments.OpenAI LLM client implementation.OpenRouter LLM client implementation.Perplexity LLM client.Alibaba Qwen Cloud (DashScope) LLM client.Replicate LLM client.Tencent Hunyuan LLM client.Together.ai LLM client.Google Cloud Vertex AI LLM client (enterprise Gemini).vLLM LLM client.IBM watsonx.ai LLM client.xAI Grok LLM client.01.AI Yi LLM client.ZhipuAI (Z.AI/Zhipu) LLM client implementation.