Class MoonshotApi

java.lang.Object
org.springframework.ai.moonshot.api.MoonshotApi

public class MoonshotApi extends Object
Single-class, Java Client library for Moonshot platform. Provides implementation for the Chat Completion APIs.

Implements Synchronous and Streaming chat completion.

Author:
Geng Rong, Thomas Vitale
  • Field Details

    • DEFAULT_CHAT_MODEL

      public static final String DEFAULT_CHAT_MODEL
  • Constructor Details

    • MoonshotApi

      public MoonshotApi(String moonshotApiKey)
      Create a new client api with DEFAULT_BASE_URL
      Parameters:
      moonshotApiKey - Moonshot api Key.
    • MoonshotApi

      public MoonshotApi(String baseUrl, String moonshotApiKey)
      Create a new client api.
      Parameters:
      baseUrl - api base URL.
      moonshotApiKey - Moonshot api Key.
    • MoonshotApi

      public MoonshotApi(String baseUrl, String moonshotApiKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler)
      Create a new client api.
      Parameters:
      baseUrl - api base URL.
      moonshotApiKey - Moonshot api Key.
      restClientBuilder - RestClient builder.
      responseErrorHandler - Response error handler.
  • Method Details

    • chatCompletionEntity

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

      public reactor.core.publisher.Flux<MoonshotApi.ChatCompletionChunk> chatCompletionStream(MoonshotApi.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.