Remove duplicated ApiUtils and polish javadocs
This commit is contained in:
committed by
Christian Tzolov
parent
78f3797f8d
commit
06ff651734
@@ -19,10 +19,10 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import org.springframework.ai.model.ModelDescription;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.ai.util.api.ApiUtils;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -41,8 +41,8 @@ import java.util.function.Predicate;
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* Single class implementation of the MiniMax Chat Completion API: https://www.minimaxi.com/document/guides/chat-model/V2 and
|
||||
* MiniMax Embedding API: https://www.minimaxi.com/document/guides/Embeddings.
|
||||
* Single class implementation of the <a href="https://www.minimaxi.com/document/guides/chat-model/V2">MiniMax Chat Completion API</a> and
|
||||
* <a href="https://www.minimaxi.com/document/guides/Embeddings">MiniMax Embedding API</a>.
|
||||
*
|
||||
* @author Geng Rong
|
||||
* @since 1.0.0 M1
|
||||
@@ -63,7 +63,7 @@ public class MiniMaxApi {
|
||||
* @param miniMaxToken MiniMax apiKey.
|
||||
*/
|
||||
public MiniMaxApi(String miniMaxToken) {
|
||||
this(ApiUtils.DEFAULT_BASE_URL, miniMaxToken);
|
||||
this(MiniMaxApiConstants.DEFAULT_BASE_URL, miniMaxToken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.ai.minimax.api;
|
||||
|
||||
/**
|
||||
* Common value constants for MiniMax api.
|
||||
*
|
||||
* @author Piotr Olaszewski
|
||||
* @since 1.0.0 M2
|
||||
*/
|
||||
public final class MiniMaxApiConstants {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://api.minimax.chat";
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 - 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ai.openai.api;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
public class ApiUtils {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://api.openai.com";
|
||||
|
||||
public static Consumer<HttpHeaders> getJsonContentHeaders(String apiKey) {
|
||||
return (headers) -> {
|
||||
headers.setBearerAuth(apiKey);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -28,7 +28,9 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.ai.model.ModelDescription;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.ai.openai.api.common.OpenAiApiConstants;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.ai.util.api.ApiUtils;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -62,7 +64,7 @@ public class OpenAiApi {
|
||||
* @param openAiToken OpenAI apiKey.
|
||||
*/
|
||||
public OpenAiApi(String openAiToken) {
|
||||
this(ApiUtils.DEFAULT_BASE_URL, openAiToken);
|
||||
this(OpenAiApiConstants.DEFAULT_BASE_URL, openAiToken);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +282,7 @@ public class OpenAiApi {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Creates a model response for the given chat conversation.
|
||||
*
|
||||
* @param messages A list of messages comprising the conversation so far.
|
||||
@@ -393,7 +395,7 @@ public class OpenAiApi {
|
||||
tools, toolChoice, null);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Shortcut constructor for a chat completion request with the given messages for streaming.
|
||||
*
|
||||
* @param messages A list of messages comprising the conversation so far.
|
||||
|
||||
@@ -21,7 +21,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.springframework.ai.openai.api.common.OpenAiApiConstants;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.ai.util.api.ApiUtils;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -49,11 +51,11 @@ public class OpenAiAudioApi {
|
||||
private final WebClient webClient;
|
||||
|
||||
/**
|
||||
* Create an new audio api.
|
||||
* Create a new audio api.
|
||||
* @param openAiToken OpenAI apiKey.
|
||||
*/
|
||||
public OpenAiAudioApi(String openAiToken) {
|
||||
this(ApiUtils.DEFAULT_BASE_URL, openAiToken, RestClient.builder(), WebClient.builder(),
|
||||
this(OpenAiApiConstants.DEFAULT_BASE_URL, openAiToken, RestClient.builder(), WebClient.builder(),
|
||||
RetryUtils.DEFAULT_RESPONSE_ERROR_HANDLER);
|
||||
}
|
||||
|
||||
@@ -710,4 +712,4 @@ public class OpenAiAudioApi {
|
||||
.toEntity(responseType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.springframework.ai.openai.api.common.OpenAiApiConstants;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.ai.util.api.ApiUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
@@ -38,11 +40,11 @@ public class OpenAiImageApi {
|
||||
private final RestClient restClient;
|
||||
|
||||
/**
|
||||
* Create a new OpenAI Image api with base URL set to https://api.openai.com
|
||||
* Create a new OpenAI Image api with base URL set to {@code https://api.openai.com}.
|
||||
* @param openAiToken OpenAI apiKey.
|
||||
*/
|
||||
public OpenAiImageApi(String openAiToken) {
|
||||
this(ApiUtils.DEFAULT_BASE_URL, openAiToken, RestClient.builder());
|
||||
this(OpenAiApiConstants.DEFAULT_BASE_URL, openAiToken, RestClient.builder());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.ai.openai.api.common;
|
||||
|
||||
/**
|
||||
* Common value constants for OpenAI api.
|
||||
*
|
||||
* @author Piotr Olaszewski
|
||||
* @since 1.0.0 M2
|
||||
*/
|
||||
public final class OpenAiApiConstants {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://api.openai.com";
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2024 - 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ai.zhipuai.api;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author Geng Rong
|
||||
*/
|
||||
public class ApiUtils {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://open.bigmodel.cn/api/paas";
|
||||
|
||||
public static Consumer<HttpHeaders> getJsonContentHeaders(String apiKey) {
|
||||
return (headers) -> {
|
||||
headers.setBearerAuth(apiKey);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.ai.model.ModelDescription;
|
||||
import org.springframework.ai.model.ModelOptionsUtils;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.ai.util.api.ApiUtils;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -40,8 +41,8 @@ import java.util.function.Predicate;
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* Single class implementation of the ZhiPuAI Chat Completion API: https://open.bigmodel.cn/dev/api#http and
|
||||
* ZhiPuAI Embedding API: https://open.bigmodel.cn/dev/api#text_embedding.
|
||||
* Single class implementation of the <a href="https://open.bigmodel.cn/dev/api#http">ZhiPuAI Chat Completion API</a> and
|
||||
* <a href="https://open.bigmodel.cn/dev/api#text_embedding">ZhiPuAI Embedding API</a>.
|
||||
*
|
||||
* @author Geng Rong
|
||||
* @since 1.0.0 M1
|
||||
@@ -62,7 +63,7 @@ public class ZhiPuAiApi {
|
||||
* @param zhiPuAiToken ZhiPuAI apiKey.
|
||||
*/
|
||||
public ZhiPuAiApi(String zhiPuAiToken) {
|
||||
this(ApiUtils.DEFAULT_BASE_URL, zhiPuAiToken);
|
||||
this(ZhiPuApiConstants.DEFAULT_BASE_URL, zhiPuAiToken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.ai.zhipuai.api;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.ai.retry.RetryUtils;
|
||||
import org.springframework.ai.util.api.ApiUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
@@ -39,11 +40,12 @@ public class ZhiPuAiImageApi {
|
||||
private final RestClient restClient;
|
||||
|
||||
/**
|
||||
* Create a new ZhiPuAI Image api with base URL set to https://api.ZhiPuAI.com
|
||||
* Create a new ZhiPuAI Image api with base URL set to
|
||||
* {@code https://api.ZhiPuAI.com}.
|
||||
* @param zhiPuAiToken ZhiPuAI apiKey.
|
||||
*/
|
||||
public ZhiPuAiImageApi(String zhiPuAiToken) {
|
||||
this(ApiUtils.DEFAULT_BASE_URL, zhiPuAiToken, RestClient.builder());
|
||||
this(ZhiPuApiConstants.DEFAULT_BASE_URL, zhiPuAiToken, RestClient.builder());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.ai.zhipuai.api;
|
||||
|
||||
/**
|
||||
* Common value constants for ZhiPu api.
|
||||
*
|
||||
* @author Piotr Olaszewski
|
||||
* @since 1.0.0 M2
|
||||
*/
|
||||
public final class ZhiPuApiConstants {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://open.bigmodel.cn/api/paas";
|
||||
|
||||
}
|
||||
@@ -74,6 +74,11 @@
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.knuddels</groupId>
|
||||
<artifactId>jtokkit</artifactId>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ai.minimax.api;
|
||||
package org.springframework.ai.util.api;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -25,17 +25,17 @@ import java.util.function.Consumer;
|
||||
* responses.
|
||||
*
|
||||
* @author Geng Rong
|
||||
* @author Christian Tzolov
|
||||
* @author Piotr Olaszewski
|
||||
* @since 1.0.0 M1
|
||||
*/
|
||||
public class ApiUtils {
|
||||
|
||||
public static final String DEFAULT_BASE_URL = "https://api.minimax.chat";
|
||||
|
||||
public static Consumer<HttpHeaders> getJsonContentHeaders(String apiKey) {
|
||||
return (headers) -> {
|
||||
headers.setBearerAuth(apiKey);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user