Class MoonshotApi
java.lang.Object
org.springframework.ai.moonshot.api.MoonshotApi
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Represents a chat completion response returned by model, based on the provided input.static final record
Represents a streamed chunk of a chat completion response returned by model, based on the provided input.static enum
The reason the model stopped generating tokens.static final record
Message comprising the conversation.static final record
Creates a model response for the given chat conversation.static enum
Moonshot Chat Completion Models: MOONSHOT_V1_8K - moonshot-v1-8k MOONSHOT_V1_32K - moonshot-v1-32k MOONSHOT_V1_128K - moonshot-v1-128kstatic final record
Represents a tool the model may call.static final record
Usage statistics. -
Field Summary
-
Constructor Summary
ConstructorDescriptionMoonshotApi
(String moonshotApiKey) Create a new client api with DEFAULT_BASE_URLMoonshotApi
(String baseUrl, String moonshotApiKey) Create a new client api.MoonshotApi
(String baseUrl, String moonshotApiKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new client api. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<MoonshotApi.ChatCompletion>
chatCompletionEntity
(MoonshotApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.reactor.core.publisher.Flux<MoonshotApi.ChatCompletionChunk>
chatCompletionStream
(MoonshotApi.ChatCompletionRequest chatRequest) Creates a streaming chat response for the given chat conversation.
-
Field Details
-
DEFAULT_CHAT_MODEL
-
-
Constructor Details
-
MoonshotApi
Create a new client api with DEFAULT_BASE_URL- Parameters:
moonshotApiKey
- Moonshot api Key.
-
MoonshotApi
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.
-