Class QianFanApi
java.lang.Object
org.springframework.ai.qianfan.api.auth.AuthApi
org.springframework.ai.qianfan.api.QianFanApi
Single class implementation of the QianFan Chat Completion API and Embedding API.
QianFan Docs
- Since:
- 1.0
- 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 final record
Message comprising the conversation.static final record
Creates a model response for the given chat conversation.static enum
QianFan Chat Completion Models: QianFan Model.static final record
Represents an embedding vector returned by embedding endpoint.static final record
List of multiple embedding responses.static enum
QianFan Embeddings Models: Embeddings.static final record
Creates an embedding vector representing the input text.static final record
Usage statistics for the completion request. -
Field Summary
-
Constructor Summary
ConstructorDescriptionQianFanApi
(String apiKey, String secretKey) Create a new chat completion api with default base URL.QianFanApi
(String baseUrl, String apiKey, String secretKey) Create a new chat completion api.QianFanApi
(String baseUrl, String apiKey, String secretKey, org.springframework.web.client.RestClient.Builder restClientBuilder) Create a new chat completion api.QianFanApi
(String baseUrl, String apiKey, String secretKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new chat completion api.QianFanApi
(String baseUrl, String apiKey, String secretKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new chat completion api. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<QianFanApi.ChatCompletion>
chatCompletionEntity
(QianFanApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.reactor.core.publisher.Flux<QianFanApi.ChatCompletionChunk>
chatCompletionStream
(QianFanApi.ChatCompletionRequest chatRequest) Creates a streaming chat response for the given chat conversation.org.springframework.http.ResponseEntity<QianFanApi.EmbeddingList>
embeddings
(QianFanApi.EmbeddingRequest embeddingRequest) Creates an embedding vector representing the input text or token array.Methods inherited from class org.springframework.ai.qianfan.api.auth.AuthApi
getAccessToken
-
Field Details
-
DEFAULT_CHAT_MODEL
-
DEFAULT_EMBEDDING_MODEL
-
-
Constructor Details
-
QianFanApi
Create a new chat completion api with default base URL.- Parameters:
apiKey
- QianFan api key.secretKey
- QianFan secret key.
-
QianFanApi
Create a new chat completion api.- Parameters:
baseUrl
- api base URL.apiKey
- QianFan api key.secretKey
- QianFan secret key.
-
QianFanApi
public QianFanApi(String baseUrl, String apiKey, String secretKey, org.springframework.web.client.RestClient.Builder restClientBuilder) Create a new chat completion api.- Parameters:
baseUrl
- api base URL.apiKey
- QianFan api key.secretKey
- QianFan secret key.restClientBuilder
- RestClient builder.
-
QianFanApi
public QianFanApi(String baseUrl, String apiKey, String secretKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new chat completion api.- Parameters:
baseUrl
- api base URL.apiKey
- QianFan api key.secretKey
- QianFan secret key.restClientBuilder
- RestClient builder.responseErrorHandler
- Response error handler.
-
QianFanApi
public QianFanApi(String baseUrl, String apiKey, String secretKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new chat completion api.- Parameters:
baseUrl
- api base URL.apiKey
- QianFan api key.secretKey
- QianFan secret key.restClientBuilder
- RestClient builder.webClientBuilder
- WebClient builder.responseErrorHandler
- Response error handler.
-
-
Method Details
-
chatCompletionEntity
public org.springframework.http.ResponseEntity<QianFanApi.ChatCompletion> chatCompletionEntity(QianFanApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.- Parameters:
chatRequest
- The chat completion request.- Returns:
- Entity response with
QianFanApi.ChatCompletion
as a body and HTTP status code and headers.
-
chatCompletionStream
public reactor.core.publisher.Flux<QianFanApi.ChatCompletionChunk> chatCompletionStream(QianFanApi.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.
-
embeddings
public org.springframework.http.ResponseEntity<QianFanApi.EmbeddingList> embeddings(QianFanApi.EmbeddingRequest embeddingRequest) Creates an embedding vector representing the input text or token array.- Parameters:
embeddingRequest
- The embedding request.- Returns:
- Returns list of
QianFanApi.Embedding
wrapped inQianFanApi.EmbeddingList
.
-