mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-01 19:24:57 +08:00
【增加】AI 写作:支持回复
This commit is contained in:
parent
77ead4859c
commit
f05f540865
@ -15,8 +15,8 @@ import java.util.Arrays;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum AiWriteTypeEnum implements IntArrayValuable {
|
public enum AiWriteTypeEnum implements IntArrayValuable {
|
||||||
|
|
||||||
DESCRIPTION(1, "撰写"),
|
WRITING(1, "撰写"),
|
||||||
LYRIC(2, "回复");
|
REPLY(2, "回复");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型
|
* 类型
|
||||||
|
@ -14,9 +14,6 @@ public class AiWriteGenerateReqVO {
|
|||||||
@Schema(description = "原文", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "领导我要辞职")
|
@Schema(description = "原文", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "领导我要辞职")
|
||||||
private String originalContent;
|
private String originalContent;
|
||||||
|
|
||||||
@Schema(description = "回复内容", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "准了")
|
|
||||||
private String replyContentPrompt;
|
|
||||||
|
|
||||||
@Schema(description = "长度", requiredMode = Schema.RequiredMode.REQUIRED, example = "中等")
|
@Schema(description = "长度", requiredMode = Schema.RequiredMode.REQUIRED, example = "中等")
|
||||||
@NotBlank(message = "长度不能为空")
|
@NotBlank(message = "长度不能为空")
|
||||||
private String length;
|
private String length;
|
||||||
|
@ -35,12 +35,12 @@ public class AiWriteDO extends BaseDO {
|
|||||||
private Integer writeType;
|
private Integer writeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 撰写内容提示
|
* 生成内容提示
|
||||||
*/
|
*/
|
||||||
private String contentPrompt;
|
private String contentPrompt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成的撰写内容
|
* 生成的内容
|
||||||
*/
|
*/
|
||||||
private String generatedContent;
|
private String generatedContent;
|
||||||
|
|
||||||
@ -49,16 +49,6 @@ public class AiWriteDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String originalContent;
|
private String originalContent;
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复内容提示
|
|
||||||
*/
|
|
||||||
private String replyContentPrompt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成的回复内容
|
|
||||||
*/
|
|
||||||
private String generatedReplyContent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 长度提示词
|
* 长度提示词
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO;
|
|||||||
import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO;
|
import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO;
|
||||||
import cn.iocoder.yudao.module.ai.dal.mysql.write.AiWriteMapper;
|
import cn.iocoder.yudao.module.ai.dal.mysql.write.AiWriteMapper;
|
||||||
import cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants;
|
import cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants;
|
||||||
|
import cn.iocoder.yudao.module.ai.enums.write.AiWriteTypeEnum;
|
||||||
import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService;
|
import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService;
|
||||||
import cn.iocoder.yudao.module.ai.service.model.AiChatModelService;
|
import cn.iocoder.yudao.module.ai.service.model.AiChatModelService;
|
||||||
import com.alibaba.cloud.ai.tongyi.chat.TongYiChatOptions;
|
import com.alibaba.cloud.ai.tongyi.chat.TongYiChatOptions;
|
||||||
@ -26,6 +27,8 @@ import org.springframework.ai.qianfan.QianFanChatOptions;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
@ -80,13 +83,21 @@ public class AiWriteServiceImpl implements AiWriteService {
|
|||||||
|
|
||||||
|
|
||||||
private String buildWritingPrompt(AiWriteGenerateReqVO generateReqVO) {
|
private String buildWritingPrompt(AiWriteGenerateReqVO generateReqVO) {
|
||||||
String template = "请直接写一篇关于 [{}] 的文章,格式为:{},语气为:{},语言为:{},长度为:{}。请确保涵盖主要内容,不需要除了正文内容外的其他回复,如标题、额外的解释或道歉。";
|
String template;
|
||||||
String content = generateReqVO.getContentPrompt();
|
Integer writeType = generateReqVO.getWriteType();
|
||||||
String format = generateReqVO.getFormat();
|
String format = generateReqVO.getFormat();
|
||||||
String tone = generateReqVO.getTone();
|
String tone = generateReqVO.getTone();
|
||||||
String language = generateReqVO.getLanguage();
|
String language = generateReqVO.getLanguage();
|
||||||
String length = generateReqVO.getLength();
|
String length = generateReqVO.getLength();
|
||||||
return StrUtil.format(template, content, format, tone, language, length);
|
if (Objects.equals(writeType, AiWriteTypeEnum.WRITING.getType())) {
|
||||||
|
template = "请撰写一篇关于 [{}] 的文章。文章的内容格式为:[{}],语气为:[{}],语言为:[{}],长度为:[{}]。请确保涵盖主要内容,不需要除了正文内容外的其他回复,如标题、额外的解释或道歉。";
|
||||||
|
return StrUtil.format(template, generateReqVO.getContentPrompt(), format, tone, language, length);
|
||||||
|
} else if (Objects.equals(writeType, AiWriteTypeEnum.REPLY.getType())) {
|
||||||
|
template = "请针对如下内容:[{}] 做个回复。回复内容参考:[{}], 回复的内容格式为:[{}],语气为:[{}],语言为:[{}],长度为:[{}]。不需要除了正文内容外的其他回复,如标题、额外的解释或道歉。";
|
||||||
|
return StrUtil.format(template, generateReqVO.getOriginalContent(), generateReqVO.getContentPrompt(), format, tone, language, length);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(StrUtil.format("未知写作类型({})", writeType));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:复用
|
// TODO 芋艿:复用
|
||||||
|
Loading…
Reference in New Issue
Block a user