Class AbstractOpenAICompatibleClient
- All Implemented Interfaces:
com.tnsai.llm.LLMClient
- Direct Known Subclasses:
CerebrasClient,DatabricksClient,DeepInfraClient,DeepSeekClient,FireworksAIClient,GroqClient,HuggingFaceClient,LlamaCppServerClient,LMStudioClient,MistralClient,NvidiaNIMClient,OpenRouterClient,PerplexityClient,QwenCloudClient,TencentHunyuanClient,TogetherAIClient,VLLMClient,XAIGrokClient,YiClient
/chat/completions
wire format verbatim — same request body, same choices[].message
response, same choices[].delta streaming, Bearer auth.
The OpenAI chat-completions shape is a de-facto standard: roughly a dozen
providers (DeepSeek, Groq, Together.ai, Fireworks, Perplexity, xAI, …) expose
an endpoint that is byte-compatible with it, differing only in base URL,
API-key env var, and a human-readable label. Before this class each of those
clients carried its own ~150-line copy of buildChatRequest /
parseChatResponse / extractStreamContent / chat /
streamChat; a fix to tool-call parsing or stream-delta extraction had
to be applied to every copy by hand. Consolidating here removes that drift
surface — a pure OpenAI-compatible provider now shrinks to a constructor plus
its base-URL/env-var constants.
Providers that are not byte-compatible stay on AbstractLLMClient
directly — Anthropic, Gemini, Bedrock, Vertex AI, Cohere (own wire
formats), and OpenAI itself plus OpenRouter, Mistral, ZhipuAI, MiniMax, which
add response_format / extra headers / JWT auth on top of the base shape.
Extending
Subclasses that are pure-compatible need only forward a constructor. A provider that is identical except for extra HTTP headers (e.g. anHTTP-Referer) can override addProviderHeaders(Request.Builder)
and inherit everything else.- Since:
- 0.11.0
- Author:
- TnsAI Team
-
Method Summary
Modifier and TypeMethodDescriptioncom.tnsai.llm.ChatResponsechat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) streamChat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) Methods inherited from class com.tnsai.llm.providers.AbstractLLMClient
getBaseUrl, getCallTimeoutMs, getMaxTokens, getModel, getTemperature, getTopPMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.llm.LLMClient
chat, chat, chat, chat, chat, getCapabilities, getProviderName, listModels, streamChat, streamChat, streamChatWithHandler, streamChatWithHandler, streamChatWithSpec, streamChatWithSpec
-
Method Details
-
chat
-
streamChat
-