Commit 9d26381dcc36545138504b64f39d40956c9dd821
1 parent
9bb231eb
【代码优化】增强 JDK17、JDK8 之间的兼容性
Showing
8 changed files
with
20 additions
and
12 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/deepseek/DeepSeekChatModel.java
| 1 | 1 | package cn.iocoder.yudao.framework.ai.core.model.deepseek; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.ListUtil; | |
| 3 | 4 | import cn.hutool.core.lang.Assert; |
| 4 | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | 6 | import org.springframework.ai.chat.metadata.ChatGenerationMetadata; |
| ... | ... | @@ -70,12 +71,12 @@ public class DeepSeekChatModel implements ChatModel { |
| 70 | 71 | OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); |
| 71 | 72 | if (chatCompletion == null) { |
| 72 | 73 | log.warn("No chat completion returned for prompt: {}", prompt); |
| 73 | - return new ChatResponse(List.of()); | |
| 74 | + return new ChatResponse(ListUtil.of()); | |
| 74 | 75 | } |
| 75 | 76 | List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); |
| 76 | 77 | if (choices == null) { |
| 77 | 78 | log.warn("No choices returned for prompt: {}", prompt); |
| 78 | - return new ChatResponse(List.of()); | |
| 79 | + return new ChatResponse(ListUtil.of()); | |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | // 2. 转换 ChatResponse 返回 | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/xinghuo/XingHuoChatModel.java
| 1 | 1 | package cn.iocoder.yudao.framework.ai.core.model.xinghuo; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.ListUtil; | |
| 3 | 4 | import cn.hutool.core.lang.Assert; |
| 4 | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | 6 | import org.springframework.ai.chat.metadata.ChatGenerationMetadata; |
| ... | ... | @@ -72,12 +73,12 @@ public class XingHuoChatModel implements ChatModel { |
| 72 | 73 | OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); |
| 73 | 74 | if (chatCompletion == null) { |
| 74 | 75 | log.warn("No chat completion returned for prompt: {}", prompt); |
| 75 | - return new ChatResponse(List.of()); | |
| 76 | + return new ChatResponse(ListUtil.of()); | |
| 76 | 77 | } |
| 77 | 78 | List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); |
| 78 | 79 | if (choices == null) { |
| 79 | 80 | log.warn("No choices returned for prompt: {}", prompt); |
| 80 | - return new ChatResponse(List.of()); | |
| 81 | + return new ChatResponse(ListUtil.of()); | |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | 84 | // 2. 转换 ChatResponse 返回 | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/com/alibaba/cloud/ai/tongyi/audio/transcription/TongYiAudioTranscriptionModel.java
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | package com.alibaba.cloud.ai.tongyi.audio.transcription; |
| 18 | 18 | |
| 19 | +import cn.hutool.core.collection.ListUtil; | |
| 19 | 20 | import com.alibaba.cloud.ai.tongyi.audio.AudioTranscriptionModels; |
| 20 | 21 | import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionPrompt; |
| 21 | 22 | import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionResponse; |
| ... | ... | @@ -82,7 +83,7 @@ public class TongYiAudioTranscriptionModel |
| 82 | 83 | try { |
| 83 | 84 | transcriptionParam = TranscriptionParam.builder() |
| 84 | 85 | .model(AudioTranscriptionModels.Paraformer_V1) |
| 85 | - .fileUrls(List.of(String.valueOf(instructions.getURL()))) | |
| 86 | + .fileUrls(ListUtil.of(String.valueOf(instructions.getURL()))) | |
| 86 | 87 | .build(); |
| 87 | 88 | } |
| 88 | 89 | catch (IOException e) { | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/com/alibaba/cloud/ai/tongyi/chat/TongYiChatModel.java
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | package com.alibaba.cloud.ai.tongyi.chat; |
| 18 | 18 | |
| 19 | +import cn.hutool.core.collection.ListUtil; | |
| 19 | 20 | import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; |
| 20 | 21 | import com.alibaba.dashscope.aigc.conversation.ConversationParam; |
| 21 | 22 | import com.alibaba.dashscope.aigc.generation.Generation; |
| ... | ... | @@ -207,7 +208,7 @@ public class TongYiChatModel extends |
| 207 | 208 | .getChoices() |
| 208 | 209 | .get(0) |
| 209 | 210 | )); |
| 210 | - return new ChatResponse(List.of(gen)); | |
| 211 | + return new ChatResponse(ListUtil.of(gen)); | |
| 211 | 212 | }) |
| 212 | 213 | ) |
| 213 | 214 | .publishOn(Schedulers.parallel()); | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/com/alibaba/cloud/ai/tongyi/embedding/TongYiTextEmbeddingModel.java
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | package com.alibaba.cloud.ai.tongyi.embedding; |
| 18 | 18 | |
| 19 | +import cn.hutool.core.collection.ListUtil; | |
| 19 | 20 | import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; |
| 20 | 21 | import com.alibaba.cloud.ai.tongyi.metadata.TongYiTextEmbeddingResponseMetadata; |
| 21 | 22 | import com.alibaba.dashscope.embeddings.TextEmbedding; |
| ... | ... | @@ -100,7 +101,7 @@ public class TongYiTextEmbeddingModel extends AbstractEmbeddingModel { |
| 100 | 101 | |
| 101 | 102 | return this.call( |
| 102 | 103 | new EmbeddingRequest( |
| 103 | - List.of(document.getFormattedContent(this.metadataMode)), | |
| 104 | + ListUtil.of(document.getFormattedContent(this.metadataMode)), | |
| 104 | 105 | null) |
| 105 | 106 | ).getResults().stream() |
| 106 | 107 | .map(Embedding::getOutput) | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoApiTests.java
| 1 | 1 | package cn.iocoder.yudao.framework.ai.music; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.ListUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi; |
| 4 | 5 | import org.junit.jupiter.api.Disabled; |
| 5 | 6 | import org.junit.jupiter.api.Test; |
| ... | ... | @@ -66,7 +67,7 @@ public class SunoApiTests { |
| 66 | 67 | String id = "584729e5-0fe9-4157-86da-1b4803ff42bf"; |
| 67 | 68 | |
| 68 | 69 | // 调用方法 |
| 69 | - List<SunoApi.MusicData> musicList = sunoApi.getMusicList(List.of(id)); | |
| 70 | + List<SunoApi.MusicData> musicList = sunoApi.getMusicList(ListUtil.of(id)); | |
| 70 | 71 | // 打印结果 |
| 71 | 72 | System.out.println(musicList); |
| 72 | 73 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.statistics; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.collection.ListUtil; | |
| 4 | 5 | import cn.hutool.core.util.ObjUtil; |
| 5 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; |
| ... | ... | @@ -106,7 +107,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 106 | 107 | private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) { |
| 107 | 108 | // 情况一:选中某个用户 |
| 108 | 109 | if (ObjUtil.isNotNull(reqVO.getUserId())) { |
| 109 | - return List.of(reqVO.getUserId()); | |
| 110 | + return ListUtil.of(reqVO.getUserId()); | |
| 110 | 111 | } |
| 111 | 112 | // 情况二:选中某个部门 |
| 112 | 113 | // 2.1 获得部门列表 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/SmsClientTests.java
| 1 | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.ListUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 4 | 5 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 5 | 6 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; |
| ... | ... | @@ -47,7 +48,7 @@ public class SmsClientTests { |
| 47 | 48 | String mobile = "15601691323"; |
| 48 | 49 | String apiTemplateId = "SMS_207945135"; |
| 49 | 50 | // 调用 |
| 50 | - SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); | |
| 51 | + SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, ListUtil.of(new KeyValue<>("code", "1024"))); | |
| 51 | 52 | // 打印结果 |
| 52 | 53 | System.out.println(sendRespDTO); |
| 53 | 54 | } |
| ... | ... | @@ -96,7 +97,7 @@ public class SmsClientTests { |
| 96 | 97 | String mobile = "15601691323"; |
| 97 | 98 | String apiTemplateId = "2136358"; |
| 98 | 99 | // 调用 |
| 99 | - SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); | |
| 100 | + SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, ListUtil.of(new KeyValue<>("code", "1024"))); | |
| 100 | 101 | // 打印结果 |
| 101 | 102 | System.out.println(sendRespDTO); |
| 102 | 103 | } |
| ... | ... | @@ -131,7 +132,7 @@ public class SmsClientTests { |
| 131 | 132 | Long sendLogId = System.currentTimeMillis(); |
| 132 | 133 | String mobile = "15601691323"; |
| 133 | 134 | String apiTemplateId = "xx test01"; |
| 134 | - List<KeyValue<String, Object>> templateParams = List.of(new KeyValue<>("code", "1024")); | |
| 135 | + List<KeyValue<String, Object>> templateParams = ListUtil.of(new KeyValue<>("code", "1024")); | |
| 135 | 136 | // 调用 |
| 136 | 137 | SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams); |
| 137 | 138 | // 打印结果 | ... | ... |