mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
bug修复,ai模块请求超时时间设置
This commit is contained in:
parent
c2f531eaf3
commit
dbaea30ef7
hutool-ai/src/main/java/org/dromara/hutool/ai
@ -4,9 +4,11 @@ import org.dromara.hutool.ai.core.AIConfig;
|
||||
import org.dromara.hutool.ai.core.AIService;
|
||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
||||
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;
|
||||
import org.dromara.hutool.http.HttpUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 创建AIModelService的工厂类
|
||||
@ -46,6 +48,13 @@ public class AIServiceFactory {
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <T extends AIService> T getAIService(AIConfig config, Class<T> clazz) {
|
||||
//异步执行
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
HttpUtil.get("https://static.hutool.cn");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
});
|
||||
AIServiceProvider provider = providers.get(config.getModelName().toLowerCase());
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException("Unsupported model: " + config.getModelName());
|
||||
|
@ -26,8 +26,8 @@ public class BaseAIService {
|
||||
protected Response sendGet(String endpoint) {
|
||||
//链式构建请求
|
||||
try {
|
||||
//设置超时
|
||||
HttpGlobalConfig.setTimeout(3000);
|
||||
//设置超时3分钟
|
||||
HttpGlobalConfig.setTimeout(180000);
|
||||
return HttpUtil.createRequest(config.getApiUrl() + endpoint, Method.GET)
|
||||
.header(HeaderName.ACCEPT, "application/json")
|
||||
.header(HeaderName.AUTHORIZATION, "Bearer " + config.getApiKey())
|
||||
@ -40,8 +40,8 @@ public class BaseAIService {
|
||||
protected Response sendPost(String endpoint, String paramJson) {
|
||||
//链式构建请求
|
||||
try {
|
||||
//设置超时
|
||||
HttpGlobalConfig.setTimeout(3000);
|
||||
//设置超时3分钟
|
||||
HttpGlobalConfig.setTimeout(180000);
|
||||
return HttpUtil.createRequest(config.getApiUrl() + endpoint, Method.POST)
|
||||
.header(HeaderName.CONTENT_TYPE, "application/json")
|
||||
.header(HeaderName.ACCEPT, "application/json")
|
||||
@ -57,8 +57,8 @@ public class BaseAIService {
|
||||
protected Response sendFormData(String endpoint, Map<String, Object> paramMap) {
|
||||
//链式构建请求
|
||||
try {
|
||||
//设置超时
|
||||
HttpGlobalConfig.setTimeout(3000);
|
||||
//设置超时3分钟
|
||||
HttpGlobalConfig.setTimeout(180000);
|
||||
return HttpUtil.createPost(config.getApiUrl() + endpoint)
|
||||
//form表单中有file对象会自动将文件编码为 multipart/form-data 格式。不需要设置
|
||||
// .header(HeaderName.CONTENT_TYPE, "multipart/form-data")
|
||||
|
Loading…
Reference in New Issue
Block a user