Commit 4fddec5f0217b3aa4895f136a2066134942a3b10
1 parent
17afb14c
【优化】AI:调整 image 相关的包结构
Showing
21 changed files
with
52 additions
and
68 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java
| ... | ... | @@ -89,7 +89,7 @@ public class AiChatMessageController { |
| 89 | 89 | @DeleteMapping("/delete") |
| 90 | 90 | @Parameter(name = "id", required = true, description = "消息编号", example = "1024") |
| 91 | 91 | public CommonResult<Boolean> deleteChatMessage(@RequestParam("id") Long id) { |
| 92 | - chatMessageService.deleteMessage(id, getLoginUserId()); | |
| 92 | + chatMessageService.deleteChatMessage(id, getLoginUserId()); | |
| 93 | 93 | return success(true); |
| 94 | 94 | } |
| 95 | 95 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.ai.controller.admin.image; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; |
| 6 | -import cn.iocoder.yudao.module.ai.service.AiImageService; | |
| 6 | +import cn.iocoder.yudao.module.ai.service.image.AiImageService; | |
| 7 | 7 | import io.swagger.v3.oas.annotations.Operation; |
| 8 | 8 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 9 | 9 | import lombok.AllArgsConstructor; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiChatModelController.java
| ... | ... | @@ -18,7 +18,6 @@ import org.springframework.validation.annotation.Validated; |
| 18 | 18 | import org.springframework.web.bind.annotation.*; |
| 19 | 19 | |
| 20 | 20 | import java.util.List; |
| 21 | -import java.util.function.Function; | |
| 22 | 21 | |
| 23 | 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | 23 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| ... | ... | @@ -77,7 +76,7 @@ public class AiChatModelController { |
| 77 | 76 | @Operation(summary = "获得聊天模型列表") |
| 78 | 77 | @Parameter(name = "status", description = "状态", required = true, example = "1") |
| 79 | 78 | public CommonResult<List<AiChatModelRespVO>> getChatModelSimpleList(@RequestParam("status") Integer status) { |
| 80 | - List<AiChatModelDO> list = chatModelService.getChatModelList(status); | |
| 79 | + List<AiChatModelDO> list = chatModelService.getChatModelListByStatus(status); | |
| 81 | 80 | return success(convertList(list, model -> new AiChatModelRespVO().setId(model.getId()) |
| 82 | 81 | .setName(model.getName()).setModel(model.getModel()))); |
| 83 | 82 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiImageMapper.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/image/AiImageMapper.java
| 1 | -package cn.iocoder.yudao.module.ai.dal.mysql; | |
| 1 | +package cn.iocoder.yudao.module.ai.dal.mysql.image; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| ... | ... | @@ -26,4 +26,5 @@ public interface AiImageMapper extends BaseMapperX<AiImageDO> { |
| 26 | 26 | default void updateByMjNonce(Long mjNonceId, AiImageDO aiImageDO) { |
| 27 | 27 | this.update(aiImageDO, new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getMjNonceId, mjNonceId)); |
| 28 | 28 | } |
| 29 | + | |
| 29 | 30 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/model/AiChatModelMapper.java
| 1 | -package cn.iocoder.yudao.module.ai.dal.mysql; | |
| 1 | +package cn.iocoder.yudao.module.ai.dal.mysql.model; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| ... | ... | @@ -26,17 +26,6 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> { |
| 26 | 26 | .orderByAsc("sort")); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - // TODO 芋艿:不需要哈 | |
| 30 | - /** | |
| 31 | - * 查询 - 根据 ids | |
| 32 | - * | |
| 33 | - * @param modalIds | |
| 34 | - * @return | |
| 35 | - */ | |
| 36 | - default List<AiChatModelDO> selectByIds(Collection<Long> modalIds) { | |
| 37 | - return this.selectList(new LambdaQueryWrapperX<AiChatModelDO>().eq(AiChatModelDO::getId, modalIds)); | |
| 38 | - } | |
| 39 | - | |
| 40 | 29 | default PageResult<AiChatModelDO> selectPage(AiChatModelPageReqVO reqVO) { |
| 41 | 30 | return selectPage(reqVO, new LambdaQueryWrapperX<AiChatModelDO>() |
| 42 | 31 | .likeIfPresent(AiChatModelDO::getName, reqVO.getName()) |
| ... | ... | @@ -50,4 +39,5 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> { |
| 50 | 39 | .eq(AiChatModelDO::getStatus, status) |
| 51 | 40 | .orderByAsc(AiChatModelDO::getSort)); |
| 52 | 41 | } |
| 42 | + | |
| 53 | 43 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatRoleMapper.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/model/AiChatRoleMapper.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/chat/AiChatMessageService.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/chat/AiChatMessageServiceImpl.java
| ... | ... | @@ -40,6 +40,8 @@ import java.time.LocalDateTime; |
| 40 | 40 | import java.util.*; |
| 41 | 41 | |
| 42 | 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 43 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; | |
| 44 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 43 | 45 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 44 | 46 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.AI_CHAT_MESSAGE_NOT_EXIST; |
| 45 | 47 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.CHAT_CONVERSATION_NOT_EXISTS; |
| ... | ... | @@ -138,7 +140,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { |
| 138 | 140 | Flux<ChatResponse> streamResponse = chatClient.stream(prompt); |
| 139 | 141 | |
| 140 | 142 | // 3.3 流式返回 |
| 141 | - // 注意:Schedulers.immediate() 目的是,避免默认 Schedulers.parallel() 并发消费 chunk 导致 SSE 响应前端会乱序问题 | |
| 143 | + // TODO 注意:Schedulers.immediate() 目的是,避免默认 Schedulers.parallel() 并发消费 chunk 导致 SSE 响应前端会乱序问题 | |
| 142 | 144 | StringBuffer contentBuffer = new StringBuffer(); |
| 143 | 145 | return streamResponse.map(chunk -> { |
| 144 | 146 | String newContent = chunk.getResult() != null ? chunk.getResult().getOutput().getContent() : null; |
| ... | ... | @@ -149,14 +151,14 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { |
| 149 | 151 | o -> o.setUserAvatar(user.getAvatar())); |
| 150 | 152 | AiChatMessageSendRespVO.Message receive = BeanUtils.toBean(assistantMessage, AiChatMessageSendRespVO.Message.class, |
| 151 | 153 | o -> o.setRoleAvatar(role != null ? role.getAvatar() : null)).setContent(newContent); |
| 152 | - return CommonResult.success(new AiChatMessageSendRespVO().setSend(send).setReceive(receive)); | |
| 154 | + return success(new AiChatMessageSendRespVO().setSend(send).setReceive(receive)); | |
| 153 | 155 | }).doOnComplete(() -> { |
| 154 | 156 | chatMessageMapper.updateById(new AiChatMessageDO().setId(assistantMessage.getId()).setContent(contentBuffer.toString())); |
| 155 | 157 | }).doOnError(throwable -> { |
| 156 | 158 | log.error("[sendChatMessageStream][userId({}) sendReqVO({}) 发生异常]", userId, sendReqVO, throwable); |
| 157 | 159 | chatMessageMapper.updateById(new AiChatMessageDO().setId(assistantMessage.getId()).setContent(throwable.getMessage())); |
| 158 | - }).onErrorResume( error -> { | |
| 159 | - return Flux.just(CommonResult.error(ErrorCodeConstants.AI_CHAT_STREAM_ERROR)); | |
| 160 | + }).onErrorResume(error -> { | |
| 161 | + return Flux.just(error(ErrorCodeConstants.AI_CHAT_STREAM_ERROR)); | |
| 160 | 162 | }); |
| 161 | 163 | } |
| 162 | 164 | |
| ... | ... | @@ -235,7 +237,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { |
| 235 | 237 | } |
| 236 | 238 | |
| 237 | 239 | @Override |
| 238 | - public void deleteMessage(Long id, Long userId) { | |
| 240 | + public void deleteChatMessage(Long id, Long userId) { | |
| 239 | 241 | // 1. 校验消息存在 |
| 240 | 242 | AiChatMessageDO message = chatMessageMapper.selectById(id); |
| 241 | 243 | if (message == null || ObjUtil.notEqual(message.getUserId(), userId)) { | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiImageService.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiImageServiceImpl.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| 1 | -package cn.iocoder.yudao.module.ai.service.impl; | |
| 1 | +package cn.iocoder.yudao.module.ai.service.image; | |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.IdUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| ... | ... | @@ -21,9 +21,8 @@ import cn.iocoder.yudao.module.ai.ErrorCodeConstants; |
| 21 | 21 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; |
| 22 | 22 | import cn.iocoder.yudao.module.ai.convert.AiImageConvert; |
| 23 | 23 | import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; |
| 24 | -import cn.iocoder.yudao.module.ai.dal.mysql.AiImageMapper; | |
| 24 | +import cn.iocoder.yudao.module.ai.dal.mysql.image.AiImageMapper; | |
| 25 | 25 | import cn.iocoder.yudao.module.ai.enums.AiImageDrawingStatusEnum; |
| 26 | -import cn.iocoder.yudao.module.ai.service.AiImageService; | |
| 27 | 26 | import jakarta.annotation.PostConstruct; |
| 28 | 27 | import lombok.AllArgsConstructor; |
| 29 | 28 | import lombok.extern.slf4j.Slf4j; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/midjourneyHandler/YuDaoMidjourneyMessageHandler.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/midjourneyHandler/YuDaoMidjourneyMessageHandler.java
| 1 | -package cn.iocoder.yudao.module.ai.service.midjourneyHandler; | |
| 1 | +package cn.iocoder.yudao.module.ai.service.image.midjourneyHandler; | |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| ... | ... | @@ -10,7 +10,7 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 10 | 10 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyOperationsVO; |
| 11 | 11 | import cn.iocoder.yudao.module.ai.convert.AiImageConvert; |
| 12 | 12 | import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; |
| 13 | -import cn.iocoder.yudao.module.ai.dal.mysql.AiImageMapper; | |
| 13 | +import cn.iocoder.yudao.module.ai.dal.mysql.image.AiImageMapper; | |
| 14 | 14 | import cn.iocoder.yudao.module.ai.enums.AiImageDrawingStatusEnum; |
| 15 | 15 | import lombok.AllArgsConstructor; |
| 16 | 16 | import lombok.extern.slf4j.Slf4j; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/vo/typeHandler/AiChatModelConfigTypeHandler.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/midjourneyHandler/typeHandler/AiChatModelConfigTypeHandler.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/vo/AiChatModalChatConfigVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/midjourneyHandler/vo/AiChatModalChatConfigVO.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/vo/AiChatModalConfigVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/midjourneyHandler/vo/AiChatModalConfigVO.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/vo/AiChatModalDallConfigVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/midjourneyHandler/vo/AiChatModalDallConfigVO.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/vo/AiChatModalMidjourneyConfigVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/midjourneyHandler/vo/AiChatModalMidjourneyConfigVO.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelService.java
| ... | ... | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatMode |
| 6 | 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | +import java.util.Collection; | |
| 9 | 10 | import java.util.List; |
| 10 | 11 | |
| 11 | 12 | import java.util.Set; |
| ... | ... | @@ -79,13 +80,13 @@ public interface AiChatModelService { |
| 79 | 80 | * @param status 状态 |
| 80 | 81 | * @return 聊天模型列表 |
| 81 | 82 | */ |
| 82 | - List<AiChatModelDO> getChatModelList(Integer status); | |
| 83 | + List<AiChatModelDO> getChatModelListByStatus(Integer status); | |
| 83 | 84 | |
| 84 | 85 | /** |
| 85 | - * 获取 - 根据多个 ids 获取 | |
| 86 | + * 获得聊天模型列表 | |
| 86 | 87 | * |
| 87 | - * @param modalIds | |
| 88 | - * @return | |
| 88 | + * @param ids 编号数组 | |
| 89 | + * @return 模型列表 | |
| 89 | 90 | */ |
| 90 | - List<AiChatModelDO> getModalByIds(Set<Long> modalIds); | |
| 91 | + List<AiChatModelDO> getChatModelList(Collection<Long> ids); | |
| 91 | 92 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelServiceImpl.java
| ... | ... | @@ -7,15 +7,14 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatModelPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatModelSaveReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 10 | -import cn.iocoder.yudao.module.ai.dal.mysql.AiChatModelMapper; | |
| 10 | +import cn.iocoder.yudao.module.ai.dal.mysql.model.AiChatModelMapper; | |
| 11 | 11 | import jakarta.annotation.Resource; |
| 12 | 12 | import org.springframework.stereotype.Service; |
| 13 | 13 | import org.springframework.validation.annotation.Validated; |
| 14 | 14 | |
| 15 | +import java.util.Collection; | |
| 15 | 16 | import java.util.List; |
| 16 | 17 | |
| 17 | -import java.util.Set; | |
| 18 | - | |
| 19 | 18 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 20 | 19 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; |
| 21 | 20 | |
| ... | ... | @@ -103,13 +102,13 @@ public class AiChatModelServiceImpl implements AiChatModelService { |
| 103 | 102 | } |
| 104 | 103 | |
| 105 | 104 | @Override |
| 106 | - public List<AiChatModelDO> getChatModelList(Integer status) { | |
| 105 | + public List<AiChatModelDO> getChatModelListByStatus(Integer status) { | |
| 107 | 106 | return chatModelMapper.selectList(status); |
| 108 | 107 | } |
| 109 | 108 | |
| 110 | 109 | @Override |
| 111 | - public List<AiChatModelDO> getModalByIds(Set<Long> modalIds) { | |
| 112 | - return chatModelMapper.selectByIds(modalIds); | |
| 110 | + public List<AiChatModelDO> getChatModelList(Collection<Long> ids) { | |
| 111 | + return chatModelMapper.selectBatchIds(ids); | |
| 113 | 112 | } |
| 114 | 113 | |
| 115 | 114 | } |
| 116 | 115 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatRoleServiceImpl.java
| ... | ... | @@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleP |
| 10 | 10 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveMyReqVO; |
| 11 | 11 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveReqVO; |
| 12 | 12 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; |
| 13 | -import cn.iocoder.yudao.module.ai.dal.mysql.AiChatRoleMapper; | |
| 13 | +import cn.iocoder.yudao.module.ai.dal.mysql.model.AiChatRoleMapper; | |
| 14 | 14 | import jakarta.annotation.Resource; |
| 15 | 15 | import lombok.extern.slf4j.Slf4j; |
| 16 | 16 | import org.springframework.stereotype.Service; | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/factory/AiClientFactoryImpl.java
| ... | ... | @@ -20,6 +20,7 @@ import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoApi; |
| 20 | 20 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient; |
| 21 | 21 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatOptions; |
| 22 | 22 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi; |
| 23 | +import com.google.cloud.vertexai.VertexAI; | |
| 23 | 24 | import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration; |
| 24 | 25 | import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration; |
| 25 | 26 | import org.springframework.ai.chat.StreamingChatClient; |
| ... | ... | @@ -31,6 +32,8 @@ import org.springframework.ai.openai.OpenAiChatClient; |
| 31 | 32 | import org.springframework.ai.openai.OpenAiChatOptions; |
| 32 | 33 | import org.springframework.ai.openai.api.ApiUtils; |
| 33 | 34 | import org.springframework.ai.openai.api.OpenAiApi; |
| 35 | +import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; | |
| 36 | +import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; | |
| 34 | 37 | |
| 35 | 38 | import java.util.List; |
| 36 | 39 | |
| ... | ... | @@ -57,8 +60,8 @@ public class AiClientFactoryImpl implements AiClientFactory { |
| 57 | 60 | return buildXingHuoChatClient(apiKey); |
| 58 | 61 | case QIAN_WEN: |
| 59 | 62 | return buildQianWenChatClient(apiKey); |
| 60 | -// case GEMIR: | |
| 61 | -// return buildGoogleGemir(apiKey); | |
| 63 | + case GEMIR: | |
| 64 | + return buildGoogleGemir(apiKey); | |
| 62 | 65 | default: |
| 63 | 66 | throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform)); |
| 64 | 67 | } |
| ... | ... | @@ -165,24 +168,13 @@ public class AiClientFactoryImpl implements AiClientFactory { |
| 165 | 168 | QianWenApi qianWenApi = new QianWenApi(key, QianWenChatModal.QWEN_72B_CHAT); |
| 166 | 169 | return new QianWenChatClient(qianWenApi); |
| 167 | 170 | } |
| 168 | -// | |
| 169 | -// private static VertexAiGeminiChatClient buildGoogleGemir(String key) { | |
| 170 | -// List<String> keys = StrUtil.split(key, '|'); | |
| 171 | -// Assert.equals(keys.size(), 2, "VertexAiGeminiChatClient 的密钥需要 (projectId|location) 格式"); | |
| 172 | -//// VertexAiGeminiConnectionProperties connectionProperties = new VertexAiGeminiConnectionProperties(); | |
| 173 | -//// connectionProperties.setApiKey("AIzaSyBpe376HTA8uPKJN_OJTh7MEO3v6LMqfXU"); | |
| 174 | -//// | |
| 175 | -//// GoogleCredentials credentials = GoogleCredentials.fromStream(connectionProperties.getCredentialsUri().getInputStream()); | |
| 176 | -// // todo @芋艿 google gemini 没找到对于初始化 client 方式,文档中说是用过 GoogleCredentials 来初始化凭证 | |
| 177 | -// // api-key: AIzaSyBpe376HTA8uPKJN_OJTh7MEO3v6LMqfXU | |
| 178 | -// VertexAI vertexApi = new VertexAI( | |
| 179 | -// "skilled-snow-409401", | |
| 180 | -// "us-central1" | |
| 181 | -// ); | |
| 182 | -// return new VertexAiGeminiChatClient(vertexApi, | |
| 183 | -// VertexAiGeminiChatOptions.builder() | |
| 184 | -// .withTemperature(0.4F) | |
| 185 | -// .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) | |
| 186 | -// .build()); | |
| 187 | -// } | |
| 171 | + | |
| 172 | + | |
| 173 | + private static VertexAiGeminiChatClient buildGoogleGemir(String key) { | |
| 174 | + List<String> keys = StrUtil.split(key, '|'); | |
| 175 | + Assert.equals(keys.size(), 2, "VertexAiGeminiChatClient 的密钥需要 (projectId|location) 格式"); | |
| 176 | + VertexAI vertexApi = new VertexAI(keys.get(0), keys.get(1)); | |
| 177 | + return new VertexAiGeminiChatClient(vertexApi); | |
| 178 | + } | |
| 179 | + | |
| 188 | 180 | } | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/tongyi/QianWenChatClient.java
| 1 | 1 | package cn.iocoder.yudao.framework.ai.core.model.tongyi; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.NumberUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.ai.core.exception.ChatException; |
| 4 | 5 | import cn.iocoder.yudao.framework.ai.core.model.tongyi.api.QianWenApi; |
| 5 | 6 | import org.springframework.ai.chat.*; | ... | ... |