Package com.tnsai.llm.providers
Class ZhipuAIClient
java.lang.Object
com.tnsai.llm.providers.AbstractLLMClient
com.tnsai.llm.providers.ZhipuAIClient
- All Implemented Interfaces:
JsonCapableLLMClient,com.tnsai.llm.LLMClient
ZhipuAI (Z.AI/Zhipu) LLM client implementation.
Provides access to ZhipuAI's GLM models via OpenAI-compatible API.
ZhipuAI is a Chinese AI company offering advanced language models with strong coding and multilingual capabilities.
Supported models:
- glm-4-plus - GLM-4 Plus (most capable)
- glm-4-flash - GLM-4 Flash (fast and efficient)
- glm-4-air - GLM-4 Air (balanced)
- glm-4-airx - GLM-4 AirX (extended context)
- glm-4-long - GLM-4 Long (1M context window)
- glm-4v-plus - GLM-4V Plus (vision capable)
- glm-4v-flash - GLM-4V Flash (fast vision)
- codegeex-4 - CodeGeeX 4 (code-specialized)
Configuration via environment variables:
- ZHIPUAI_API_KEY - Required API key for authentication
- ZHIPUAI_BASE_URL - Optional, defaults to https://open.bigmodel.cn/api/paas/v4
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionZhipuAIClient(String model) ZhipuAIClient(String model, float temperature) ZhipuAIClient(String model, float temperature, Float topP, Integer maxTokens) ZhipuAIClient(String model, float temperature, Integer maxTokens) ZhipuAIClient(String baseUrl, String model, float temperature, Float topP, Integer maxTokens, String apiKey) ZhipuAIClient(String baseUrl, String model, float temperature, Integer maxTokens, String apiKey) -
Method Summary
Modifier and TypeMethodDescriptionstatic ZhipuAIClient.Builderbuilder()Builder for ZhipuAIClient.com.tnsai.llm.ChatResponsechat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) com.tnsai.llm.ChatResponsechat(List<com.tnsai.models.chat.ContentPart> messageParts, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) com.tnsai.llm.ChatResponsechatWithFormat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools, ResponseFormat format) Sends a chat message with the specified response format.booleanReturns true if the current model is optimized for code.booleanReturns true if the current model supports vision (images).streamChat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) booleansupportsFormat(ResponseFormat format) Checks if this client supports the given response format.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.format.JsonCapableLLMClient
chatJson, chatJson, chatWithSchema, chatWithSchemaMethods inherited from interface com.tnsai.llm.LLMClient
chat, chat, chat, chat, getCapabilities, getMaxTokens, getModel, getProviderName, getTemperature, getTopP, listModels, streamChat, streamChat, streamChatWithHandler, streamChatWithHandler, streamChatWithSpec, streamChatWithSpec
-
Constructor Details
-
ZhipuAIClient
-
ZhipuAIClient
-
ZhipuAIClient
-
ZhipuAIClient
-
ZhipuAIClient
-
ZhipuAIClient
-
-
Method Details
-
chat
public com.tnsai.llm.ChatResponse chat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) - Specified by:
chatin interfacecom.tnsai.llm.LLMClient
-
chatWithFormat
public com.tnsai.llm.ChatResponse chatWithFormat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools, ResponseFormat format) Description copied from interface:JsonCapableLLMClientSends a chat message with the specified response format.- Specified by:
chatWithFormatin interfaceJsonCapableLLMClient- Parameters:
message- The user messagesystemPrompt- Optional system prompthistory- Optional conversation historytools- Optional list of available toolsformat- The desired response format- Returns:
- The LLM response
-
chat
public com.tnsai.llm.ChatResponse chat(List<com.tnsai.models.chat.ContentPart> messageParts, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) - Specified by:
chatin interfacecom.tnsai.llm.LLMClient
-
streamChat
public Stream<String> streamChat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) - Specified by:
streamChatin interfacecom.tnsai.llm.LLMClient
-
supportsFormat
Description copied from interface:JsonCapableLLMClientChecks if this client supports the given response format.- Specified by:
supportsFormatin interfaceJsonCapableLLMClient- Parameters:
format- The format to check- Returns:
- true if the format is supported
-
isVisionModel
public boolean isVisionModel()Returns true if the current model supports vision (images). -
isCodeModel
public boolean isCodeModel()Returns true if the current model is optimized for code. -
builder
Builder for ZhipuAIClient.
-