Class ZhiPuAiApi

java.lang.Object
org.springframework.ai.zhipuai.api.ZhiPuAiApi

public class ZhiPuAiApi extends Object
Single class implementation of the ZhiPuAI Chat Completion API and ZhiPuAI Embedding API.
Since:
1.0.0
Author:
Geng Rong, Thomas Vitale, YunKui Lu
  • Field Details

    • DEFAULT_CHAT_MODEL

      public static final String DEFAULT_CHAT_MODEL
    • DEFAULT_EMBEDDING_MODEL

      public static final String DEFAULT_EMBEDDING_MODEL
    • DEFAULT_EMBEDDINGS_PATH

      public static final String DEFAULT_EMBEDDINGS_PATH
      See Also:
    • DEFAULT_COMPLETIONS_PATH

      public static final String DEFAULT_COMPLETIONS_PATH
      See Also:
  • Constructor Details

    • ZhiPuAiApi

      public ZhiPuAiApi(String baseUrl, ApiKey apiKey, org.springframework.http.HttpHeaders headers, String completionsPath, String embeddingsPath, org.springframework.web.client.ResponseErrorHandler responseErrorHandler, org.springframework.web.client.RestClient restClient, org.springframework.web.reactive.function.client.WebClient webClient)
      Create a new chat completion api.
      Parameters:
      baseUrl - api base URL.
      apiKey - ZhiPuAI apiKey.
      headers - the http headers to use.
      completionsPath - the path to the chat completions endpoint.
      embeddingsPath - the path to the embeddings endpoint.
      responseErrorHandler - Response error handler.
      restClient - RestClient instance.
      webClient - WebClient instance.
  • Method Details

    • mutate

      public ZhiPuAiApi.Builder mutate()
      Returns a builder pre-populated with the current configuration for mutation.
    • builder

      public static ZhiPuAiApi.Builder builder()
    • getTextContent

      public static String getTextContent(List<ZhiPuAiApi.ChatCompletionMessage.MediaContent> content)
    • chatCompletionEntity

      public org.springframework.http.ResponseEntity<ZhiPuAiApi.ChatCompletion> chatCompletionEntity(ZhiPuAiApi.ChatCompletionRequest chatRequest)
      Creates a model response for the given chat conversation.
      Parameters:
      chatRequest - The chat completion request.
      Returns:
      Entity response with ZhiPuAiApi.ChatCompletion as a body and HTTP status code and headers.
    • chatCompletionEntity

      public org.springframework.http.ResponseEntity<ZhiPuAiApi.ChatCompletion> chatCompletionEntity(ZhiPuAiApi.ChatCompletionRequest chatRequest, org.springframework.http.HttpHeaders additionalHttpHeader)
      Creates a model response for the given chat conversation.
      Parameters:
      chatRequest - The chat completion request.
      Returns:
      Entity response with ZhiPuAiApi.ChatCompletion as a body and HTTP status code and headers.
    • chatCompletionStream

      public reactor.core.publisher.Flux<ZhiPuAiApi.ChatCompletionChunk> chatCompletionStream(ZhiPuAiApi.ChatCompletionRequest chatRequest)
      Creates a streaming chat response for the given chat conversation.
      Parameters:
      chatRequest - The chat completion request. Must have the stream property set to true.
      Returns:
      Returns a Flux stream from chat completion chunks.
    • chatCompletionStream

      public reactor.core.publisher.Flux<ZhiPuAiApi.ChatCompletionChunk> chatCompletionStream(ZhiPuAiApi.ChatCompletionRequest chatRequest, org.springframework.http.HttpHeaders additionalHttpHeader)
      Creates a streaming chat response for the given chat conversation.
      Parameters:
      chatRequest - The chat completion request. Must have the stream property set to true.
      Returns:
      Returns a Flux stream from chat completion chunks.
    • embeddings

      public <T> org.springframework.http.ResponseEntity<ZhiPuAiApi.EmbeddingList<ZhiPuAiApi.Embedding>> embeddings(ZhiPuAiApi.EmbeddingRequest<T> embeddingRequest)
      Creates an embedding vector representing the input text or token array.
      Type Parameters:
      T - Type of the entity in the data list. Can be a String or List of tokens (e.g. Integers). For embedding multiple inputs in a single request, You can pass a List of String or List of List of tokens. For example:
      List.of("text1", "text2", "text3") or List.of(List.of(1, 2, 3), List.of(3, 4, 5)) 
      Parameters:
      embeddingRequest - The embedding request.
      Returns:
      Returns list of ZhiPuAiApi.Embedding wrapped in ZhiPuAiApi.EmbeddingList.