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

ClientProviderAPI Key Env Var
OpenAIClientOpenAIOPENAI_API_KEY
AzureOpenAIClientAzure OpenAIAZURE_OPENAI_API_KEY
AnthropicClientAnthropicANTHROPIC_API_KEY
GeminiClientGoogle GeminiGEMINI_API_KEY
OllamaClientOllama (local)N/A
GroqClientGroqGROQ_API_KEY
OpenRouterClientOpenRouterOPENROUTER_API_KEY
MistralClientMistral AIMISTRAL_API_KEY
BedrockClientAWS BedrockAWS 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:
  • LLMClient