Commit f05f5408658266d3eb349eab76f605aaa9a38f89
1 parent
77ead485
【增加】AI 写作:支持回复
Showing
4 changed files
with
18 additions
and
20 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/write/AiWriteTypeEnum.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWriteGenerateReqVO.java
| ... | ... | @@ -14,9 +14,6 @@ public class AiWriteGenerateReqVO { |
| 14 | 14 | @Schema(description = "原文", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "领导我要辞职") |
| 15 | 15 | private String originalContent; |
| 16 | 16 | |
| 17 | - @Schema(description = "回复内容", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "准了") | |
| 18 | - private String replyContentPrompt; | |
| 19 | - | |
| 20 | 17 | @Schema(description = "长度", requiredMode = Schema.RequiredMode.REQUIRED, example = "中等") |
| 21 | 18 | @NotBlank(message = "长度不能为空") |
| 22 | 19 | private String length; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/write/AiWriteDO.java
| ... | ... | @@ -35,12 +35,12 @@ public class AiWriteDO extends BaseDO { |
| 35 | 35 | private Integer writeType; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * 撰写内容提示 | |
| 38 | + * 生成内容提示 | |
| 39 | 39 | */ |
| 40 | 40 | private String contentPrompt; |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * 生成的撰写内容 | |
| 43 | + * 生成的内容 | |
| 44 | 44 | */ |
| 45 | 45 | private String generatedContent; |
| 46 | 46 | |
| ... | ... | @@ -50,16 +50,6 @@ public class AiWriteDO extends BaseDO { |
| 50 | 50 | private String originalContent; |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * 回复内容提示 | |
| 54 | - */ | |
| 55 | - private String replyContentPrompt; | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * 生成的回复内容 | |
| 59 | - */ | |
| 60 | - private String generatedReplyContent; | |
| 61 | - | |
| 62 | - /** | |
| 63 | 53 | * 长度提示词 |
| 64 | 54 | */ |
| 65 | 55 | private String length; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java
| ... | ... | @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 11 | 11 | import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO; |
| 12 | 12 | import cn.iocoder.yudao.module.ai.dal.mysql.write.AiWriteMapper; |
| 13 | 13 | import cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants; |
| 14 | +import cn.iocoder.yudao.module.ai.enums.write.AiWriteTypeEnum; | |
| 14 | 15 | import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService; |
| 15 | 16 | import cn.iocoder.yudao.module.ai.service.model.AiChatModelService; |
| 16 | 17 | import com.alibaba.cloud.ai.tongyi.chat.TongYiChatOptions; |
| ... | ... | @@ -26,6 +27,8 @@ import org.springframework.ai.qianfan.QianFanChatOptions; |
| 26 | 27 | import org.springframework.stereotype.Service; |
| 27 | 28 | import reactor.core.publisher.Flux; |
| 28 | 29 | |
| 30 | +import java.util.Objects; | |
| 31 | + | |
| 29 | 32 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; |
| 30 | 33 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | 34 | |
| ... | ... | @@ -80,13 +83,21 @@ public class AiWriteServiceImpl implements AiWriteService { |
| 80 | 83 | |
| 81 | 84 | |
| 82 | 85 | private String buildWritingPrompt(AiWriteGenerateReqVO generateReqVO) { |
| 83 | - String template = "请直接写一篇关于 [{}] 的文章,格式为:{},语气为:{},语言为:{},长度为:{}。请确保涵盖主要内容,不需要除了正文内容外的其他回复,如标题、额外的解释或道歉。"; | |
| 84 | - String content = generateReqVO.getContentPrompt(); | |
| 86 | + String template; | |
| 87 | + Integer writeType = generateReqVO.getWriteType(); | |
| 85 | 88 | String format = generateReqVO.getFormat(); |
| 86 | 89 | String tone = generateReqVO.getTone(); |
| 87 | 90 | String language = generateReqVO.getLanguage(); |
| 88 | 91 | String length = generateReqVO.getLength(); |
| 89 | - return StrUtil.format(template, content, format, tone, language, length); | |
| 92 | + if (Objects.equals(writeType, AiWriteTypeEnum.WRITING.getType())) { | |
| 93 | + template = "请撰写一篇关于 [{}] 的文章。文章的内容格式为:[{}],语气为:[{}],语言为:[{}],长度为:[{}]。请确保涵盖主要内容,不需要除了正文内容外的其他回复,如标题、额外的解释或道歉。"; | |
| 94 | + return StrUtil.format(template, generateReqVO.getContentPrompt(), format, tone, language, length); | |
| 95 | + } else if (Objects.equals(writeType, AiWriteTypeEnum.REPLY.getType())) { | |
| 96 | + template = "请针对如下内容:[{}] 做个回复。回复内容参考:[{}], 回复的内容格式为:[{}],语气为:[{}],语言为:[{}],长度为:[{}]。不需要除了正文内容外的其他回复,如标题、额外的解释或道歉。"; | |
| 97 | + return StrUtil.format(template, generateReqVO.getOriginalContent(), generateReqVO.getContentPrompt(), format, tone, language, length); | |
| 98 | + } else { | |
| 99 | + throw new IllegalArgumentException(StrUtil.format("未知写作类型({})", writeType)); | |
| 100 | + } | |
| 90 | 101 | } |
| 91 | 102 | |
| 92 | 103 | // TODO 芋艿:复用 | ... | ... |