public abstract class AbstractAiClient extends AbstractClientBaseService
This class serves as the foundation for specific AI client implementations such as ZaiClient and ZhipuAiClient, providing shared functionality while allowing each implementation to have its own static factory methods.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractAiClient.AbstractBuilder<T extends AbstractAiClient,B extends AbstractAiClient.AbstractBuilder<T,B>>
Abstract base builder class for creating AI client instances with custom
configurations.
|
| Modifier and Type | Field and Description |
|---|---|
protected okhttp3.OkHttpClient |
httpClient
HTTP client for making network requests
|
protected retrofit2.Retrofit |
retrofit
Retrofit instance for API communication
|
mapper| Modifier | Constructor and Description |
|---|---|
protected |
AbstractAiClient(ZaiConfig config,
String baseUrl)
Constructs a new AbstractAiClient with the specified configuration.
|
| Modifier and Type | Method and Description |
|---|---|
AgentService |
agents()
Returns the agent service for AI agent management.
|
AssistantService |
assistants()
Returns the assistant service for AI assistant functionality.
|
AudioService |
audio()
Returns the audio service for audio processing.
|
BatchService |
batches()
Returns the batch service for batch processing operations.
|
<Data,F,Param,TReq extends ClientRequest<Param>,TResp extends BiFlowableClientResponse<Data,F>> |
biStreamRequest(TReq request,
FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier,
Class<TResp> tRespClass,
Class<F> tStreamDataClass)
Executes a streaming API request and returns a BiFlowableClientResponse where
response body and stream element type can differ.
|
ChatService |
chat()
Returns the chat service for conversational AI operations.
|
void |
close()
Closes the AI client and releases all associated resources.
|
EmbeddingService |
embeddings()
Returns the embedding service for text embeddings.
|
<Data,Param,TReq extends ClientRequest<Param>,TResp extends ClientResponse<Data>> |
executeRequest(TReq request,
RequestSupplier<Param,Data> requestSupplier,
Class<TResp> tRespClass)
Executes a synchronous API request and returns the response.
|
FileParsingService |
fileParsing()
Returns the file service for file operations.
|
FileService |
files()
Returns the file service for file operations.
|
HandwritingOcrService |
handwriting() |
ImageService |
images()
Returns the image service for image generation and processing.
|
ModerationService |
moderations()
Returns the moderation service for content safety detection.
|
retrofit2.Retrofit |
retrofit()
Returns the underlying Retrofit instance used for API communication.
|
<Data,Param,TReq extends ClientRequest<Param>,TResp extends FlowableClientResponse<Data>> |
streamRequest(TReq request,
FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier,
Class<TResp> tRespClass,
Class<Data> tDataClass)
Executes a streaming API request and returns a FlowableClientResponse with stream
elements of type Data.
|
VideosService |
videos()
Returns the videos service for video processing.
|
VoiceCloneService |
voiceClone()
Returns the voice clone service for voice cloning operations.
|
WebReaderService |
webReader()
Returns the web reader service for parsing web pages.
|
WebSearchService |
webSearch()
Returns the web search service for internet search capabilities.
|
execute, stream, stream, streamprotected final okhttp3.OkHttpClient httpClient
protected final retrofit2.Retrofit retrofit
protected AbstractAiClient(ZaiConfig config, String baseUrl)
config - the configuration object containing API keys, timeouts, and other
settingsbaseUrl - the base URL for the API endpointIllegalArgumentException - if config is null or invalidpublic ChatService chat()
public AgentService agents()
public EmbeddingService embeddings()
public FileService files()
public AudioService audio()
public ImageService images()
public BatchService batches()
public WebSearchService webSearch()
public WebReaderService webReader()
public VideosService videos()
public AssistantService assistants()
public VoiceCloneService voiceClone()
public FileParsingService fileParsing()
public HandwritingOcrService handwriting()
public ModerationService moderations()
public retrofit2.Retrofit retrofit()
public void close()
Important: Always call this method when you're done with the client to prevent resource leaks.
public <Data,Param,TReq extends ClientRequest<Param>,TResp extends ClientResponse<Data>> TResp executeRequest(TReq request, RequestSupplier<Param,Data> requestSupplier, Class<TResp> tRespClass)
executeRequest in class AbstractClientBaseServiceData - the type of data expected in the responseParam - the type of parameters for the requestTReq - the type of client requestTResp - the type of client responserequest - the client request containing parametersrequestSupplier - the supplier that creates the actual API calltRespClass - the class of the response typepublic <Data,F,Param,TReq extends ClientRequest<Param>,TResp extends BiFlowableClientResponse<Data,F>> TResp biStreamRequest(TReq request, FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier, Class<TResp> tRespClass, Class<F> tStreamDataClass)
biStreamRequest in class AbstractClientBaseServiceData - type of response bodyF - type of each element in the stream (can be same as Data)Param - request param typeTReq - request typeTResp - response type (must extend BiFlowableClientResponse)request - the request objectrequestSupplier - the streaming API suppliertRespClass - the client response class (must implement
BiFlowableClientResponse)tStreamDataClass - the stream data element classpublic <Data,Param,TReq extends ClientRequest<Param>,TResp extends FlowableClientResponse<Data>> TResp streamRequest(TReq request, FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier, Class<TResp> tRespClass, Class<Data> tDataClass)
streamRequest in class AbstractClientBaseServiceData - data type for both response and streamParam - request param typeTReq - request typeTResp - response type (must extend FlowableClientResponserequest - the request objectrequestSupplier - the streaming API suppliertRespClass - the client response class (must implement
FlowableClientResponse)tDataClass - the class representing stream data typeCopyright © 2025. All rights reserved.