Commit 403f42d4 authored by alex yao's avatar alex yao

Merge branch 'release' into task/temp_function_call

# Conflicts:
#	src/main/java/cn/com/poc/agent_application/aggregate/AgentApplicationInfoService.java
#	src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
#	src/main/java/cn/com/poc/agent_application/convert/AgentApplicationInfoConvert.java
#	src/main/java/cn/com/poc/agent_application/rest/impl/AgentApplicationInfoRestImpl.java
#	src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
#	src/main/java/cn/com/poc/expose/rest/AgentApplicationRest.java
#	src/main/java/cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
parents fb52d923 a3f0e6c8
...@@ -18,7 +18,7 @@ public interface AgentApplicationInfoService { ...@@ -18,7 +18,7 @@ public interface AgentApplicationInfoService {
* 应用预览 * 应用预览
*/ */
String callAgentApplication(String largeModel, String[] unitIds, String agentSystem, String callAgentApplication(String largeModel, String[] unitIds, String agentSystem,
String[] knowledgeIds, Integer communicationTurn, Float topP, Integer[] knowledgeIds, Integer communicationTurn, Float topP,
List<Message> messages, Boolean isLongMemory, String[] variableStructure, boolean isFunction, String[] functionName, List<String> functionConfig, String useStatus, HttpServletResponse httpServletResponse) throws Exception; List<Message> messages, Boolean isLongMemory, String[] variableStructure, boolean isFunction, String[] functionName, List<String> functionConfig, String useStatus, HttpServletResponse httpServletResponse) throws Exception;
......
...@@ -4,15 +4,15 @@ import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; ...@@ -4,15 +4,15 @@ import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.agent_application.constant.AgentApplicationConstants; import cn.com.poc.agent_application.constant.AgentApplicationConstants;
import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants; import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants;
import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants; import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity; import cn.com.poc.agent_application.entity.*;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.poc.agent_application.entity.CreateAgentTitleAndDescEntity;
import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService; import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.service.BizAgentApplicationInfoService; import cn.com.poc.agent_application.service.BizAgentApplicationInfoService;
import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.service.BizKnowledgeDocumentService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.AICreateImageService; import cn.com.poc.thirdparty.resource.demand.ai.aggregate.AICreateImageService;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService; import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
...@@ -39,7 +39,10 @@ import javax.servlet.http.HttpServletResponse; ...@@ -39,7 +39,10 @@ import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
...@@ -51,6 +54,12 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -51,6 +54,12 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
final private Logger logger = LoggerFactory.getLogger(AgentApplicationInfoService.class); final private Logger logger = LoggerFactory.getLogger(AgentApplicationInfoService.class);
@Resource
private BizKnowledgeDocumentService bizKnowledgeDocumentService;
@Resource
private BizAgentApplicationLargeModelListService bizAgentApplicationLargeModelListService;
@Resource @Resource
private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService; private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService;
...@@ -69,7 +78,6 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -69,7 +78,6 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Resource @Resource
private LLMService llmService; private LLMService llmService;
@Override @Override
public boolean updateAndPublish(BizAgentApplicationInfoEntity bizAgentApplicationInfoEntity) throws Exception { public boolean updateAndPublish(BizAgentApplicationInfoEntity bizAgentApplicationInfoEntity) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException(); UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
...@@ -91,9 +99,12 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -91,9 +99,12 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
@Override @Override
public String callAgentApplication(String largeModel, String[] unitIds, String agentSystem, String[] knowledgeIds, Integer communicationTurn, Float topP, List<Message> messages, Boolean isLongMemory, String[] variableStructure, boolean isFunction, String[] functionName, List<String> functionConfig, String useStatus, HttpServletResponse httpServletResponse) throws Exception { public String callAgentApplication(String largeModel, String[] unitIds, String agentSystem, Integer[] kdIds, Integer communicationTurn, Float topP, List<Message> messages, Boolean isLongMemory, String[] variableStructure, boolean isFunction, String[] functionName, List<String> functionConfig, String useStatus, HttpServletResponse httpServletResponse) throws Exception {
logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" + " communicationTurn:{},topP:{},messages:{}--------------", largeModel, unitIds, agentSystem, knowledgeIds, communicationTurn, topP, messages); logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" + " communicationTurn:{},topP:{},messages:{}--------------", largeModel, unitIds, agentSystem, knowledgeIds, communicationTurn, topP, messages);
String promptTemplate = buildDialogsPrompt(messages, agentSystem, knowledgeIds);
String model = modelConvert(largeModel);
String promptTemplate = buildDialogsPrompt(messages, agentSystem, kdIds);
Message[] messageArray = buildMessages(messages, communicationTurn, promptTemplate); Message[] messageArray = buildMessages(messages, communicationTurn, promptTemplate);
...@@ -372,12 +383,20 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -372,12 +383,20 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return JsonUtils.deSerialize(res.substring(start, end + 1), CreateAgentTitleAndDescEntity.class); return JsonUtils.deSerialize(res.substring(start, end + 1), CreateAgentTitleAndDescEntity.class);
} }
private String buildDialogsPrompt(List<Message> messages, String agentSystem, String[] knowledgeIds) { private String buildDialogsPrompt(List<Message> messages, String agentSystem, Integer[] kdIds) {
String promptTemplate = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_BASE_SYSTEM).getConfigSystem(); String promptTemplate = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_BASE_SYSTEM).getConfigSystem();
promptTemplate = promptTemplate.replace("${agentSystem}", StringUtils.isNotBlank(agentSystem) ? agentSystem : StringUtils.EMPTY); promptTemplate = promptTemplate.replace("${agentSystem}", StringUtils.isNotBlank(agentSystem) ? agentSystem : StringUtils.EMPTY);
// 调用知识库 // 调用知识库
if (ArrayUtils.isNotEmpty(knowledgeIds)) { if (ArrayUtils.isNotEmpty(kdIds)) {
List<String> knowledgeResults = demandKnowledgeService.searchKnowledge(messages.get(messages.size() - 1).getContent().get(0).getText(), Arrays.stream(knowledgeIds).collect(Collectors.toList()), 10); List<String> knowledgeIds = new ArrayList<>();
for (Integer kdId : kdIds) {
BizKnowledgeDocumentEntity knowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (null == knowledgeDocumentEntity) {
continue;
}
knowledgeIds.add(knowledgeDocumentEntity.getKnowledgeId());
}
List<String> knowledgeResults = demandKnowledgeService.searchKnowledge(messages.get(messages.size() - 1).getContent().get(0).getText(), knowledgeIds, 3);
promptTemplate = promptTemplate.replace("${knowledgeResults}", knowledgeResults.toString()); promptTemplate = promptTemplate.replace("${knowledgeResults}", knowledgeResults.toString());
} }
return promptTemplate; return promptTemplate;
...@@ -560,4 +579,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -560,4 +579,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
return messages.toArray(new Message[0]); return messages.toArray(new Message[0]);
} }
/**
* 获取模型
*
* @param largeModel
* @return
*/
private String modelConvert(String largeModel) {
BizAgentApplicationLargeModelListEntity largeModelEntity = bizAgentApplicationLargeModelListService.findByModelNickName(largeModel);
if (largeModelEntity == null) {
throw new BusinessException("模型不存在");
}
return largeModelEntity.getModelName();
}
} }
...@@ -8,7 +8,9 @@ import cn.com.poc.agent_application.model.BizAgentApplicationInfoModel; ...@@ -8,7 +8,9 @@ import cn.com.poc.agent_application.model.BizAgentApplicationInfoModel;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoDto;
import cn.com.poc.agent_application.query.AgentApplicationInfoQueryItem; import cn.com.poc.agent_application.query.AgentApplicationInfoQueryItem;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.expose.dto.SearchAgentApplicationDto;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.tencent.core.utils.JsonUtil; import com.tencent.core.utils.JsonUtil;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
...@@ -17,6 +19,17 @@ import org.apache.commons.lang3.StringUtils; ...@@ -17,6 +19,17 @@ import org.apache.commons.lang3.StringUtils;
public class AgentApplicationInfoConvert { public class AgentApplicationInfoConvert {
public static SearchAgentApplicationDto itemToSearchDto(PublishAgentApplicationQueryItem item) {
SearchAgentApplicationDto dto = new SearchAgentApplicationDto();
dto.setAgentId(item.getAgentId());
dto.setAgentTitle(item.getAgentTitle());
dto.setAgentDesc(item.getAgentDesc());
dto.setAgentAvatar(item.getAgentAvatar());
dto.setPublishedTime(item.getModifiedTime());
dto.setCreator(item.getNickName());
return dto;
}
public static BizAgentApplicationInfoEntity modelToEntity(BizAgentApplicationInfoModel model) { public static BizAgentApplicationInfoEntity modelToEntity(BizAgentApplicationInfoModel model) {
BizAgentApplicationInfoEntity entity = new BizAgentApplicationInfoEntity(); BizAgentApplicationInfoEntity entity = new BizAgentApplicationInfoEntity();
entity.setId(model.getId()); entity.setId(model.getId());
......
package cn.com.poc.agent_application.convert; package cn.com.poc.agent_application.convert;
import cn.com.poc.agent_application.model.BizAgentApplicationLargeModelListModel; import cn.com.poc.agent_application.model.BizAgentApplicationLargeModelListModel;
import cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity;
...@@ -7,20 +7,24 @@ import cn.com.poc.agent_application.dto.BizAgentApplicationLargeModelListDto; ...@@ -7,20 +7,24 @@ import cn.com.poc.agent_application.dto.BizAgentApplicationLargeModelListDto;
public class BizAgentApplicationLargeModelListConvert { public class BizAgentApplicationLargeModelListConvert {
public static BizAgentApplicationLargeModelListEntity modelToEntity(BizAgentApplicationLargeModelListModel model){ public static BizAgentApplicationLargeModelListEntity modelToEntity(BizAgentApplicationLargeModelListModel model) {
BizAgentApplicationLargeModelListEntity entity = new BizAgentApplicationLargeModelListEntity(); BizAgentApplicationLargeModelListEntity bizAgentApplicationLargeModelListEntity = new BizAgentApplicationLargeModelListEntity();
entity.setId(model.getId()); bizAgentApplicationLargeModelListEntity.setId(model.getId());
entity.setModelName(model.getModelName()); bizAgentApplicationLargeModelListEntity.setModelName(model.getModelName());
entity.setOwner(model.getOwner()); bizAgentApplicationLargeModelListEntity.setOwner(model.getOwner());
return entity; bizAgentApplicationLargeModelListEntity.setIconUrl(model.getIconUrl());
bizAgentApplicationLargeModelListEntity.setModelNickName(model.getModelNickName());
return bizAgentApplicationLargeModelListEntity;
} }
public static BizAgentApplicationLargeModelListModel entityToModel(BizAgentApplicationLargeModelListEntity entity){ public static BizAgentApplicationLargeModelListModel entityToModel(BizAgentApplicationLargeModelListEntity entity) {
BizAgentApplicationLargeModelListModel model = new BizAgentApplicationLargeModelListModel(); BizAgentApplicationLargeModelListModel bizAgentApplicationLargeModelListModel = new BizAgentApplicationLargeModelListModel();
model.setId(entity.getId()); bizAgentApplicationLargeModelListModel.setId(entity.getId());
model.setModelName(entity.getModelName()); bizAgentApplicationLargeModelListModel.setModelName(entity.getModelName());
model.setOwner(entity.getOwner()); bizAgentApplicationLargeModelListModel.setOwner(entity.getOwner());
return model; bizAgentApplicationLargeModelListModel.setIconUrl(entity.getIconUrl());
bizAgentApplicationLargeModelListModel.setModelNickName(entity.getModelNickName());
return bizAgentApplicationLargeModelListModel;
} }
} }
\ No newline at end of file
...@@ -32,4 +32,17 @@ public class BizAgentApplicationLargeModelListDto { ...@@ -32,4 +32,17 @@ public class BizAgentApplicationLargeModelListDto {
public void setOwner(java.lang.String owner) { public void setOwner(java.lang.String owner) {
this.owner = owner; this.owner = owner;
} }
/**
* icon
*/
private java.lang.String icon;
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
} }
\ No newline at end of file
...@@ -40,4 +40,30 @@ public class BizAgentApplicationLargeModelListEntity { ...@@ -40,4 +40,30 @@ public class BizAgentApplicationLargeModelListEntity {
public void setOwner(java.lang.String owner){ public void setOwner(java.lang.String owner){
this.owner = owner; this.owner = owner;
} }
/**
* icon_url
*/
private String iconUrl;
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
/**
* model_nick_name
*/
private String modelNickName;
public String getModelNickName() {
return modelNickName;
}
public void setModelNickName(String modelNickName) {
this.modelNickName = modelNickName;
}
} }
\ No newline at end of file
package cn.com.poc.agent_application.model; package cn.com.poc.agent_application.model;
import java.io.Serializable; import java.io.Serializable;
import cn.com.yict.framemax.data.model.BaseModelClass; import cn.com.yict.framemax.data.model.BaseModelClass;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Id; import javax.persistence.Id;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
...@@ -22,55 +26,89 @@ import javax.persistence.GenerationType; ...@@ -22,55 +26,89 @@ import javax.persistence.GenerationType;
public class BizAgentApplicationLargeModelListModel extends BaseModelClass implements Serializable { public class BizAgentApplicationLargeModelListModel extends BaseModelClass implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** id /**
* * id
*/ */
private java.lang.Integer id; private java.lang.Integer id;
@Column(name = "id",length = 10) @Column(name = "id", length = 10)
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Id
public java.lang.Integer getId(){ @GeneratedValue(strategy = GenerationType.AUTO)
public java.lang.Integer getId() {
return this.id; return this.id;
} }
public void setId(java.lang.Integer id){ public void setId(java.lang.Integer id) {
this.id = id; this.id = id;
super.addValidField("id"); super.addValidField("id");
} }
/** model_name /**
*模型 * model_name
*/ * 模型
*/
private java.lang.String modelName; private java.lang.String modelName;
@Column(name = "model_name",length = 100) @Column(name = "model_name", length = 100)
public java.lang.String getModelName(){ public java.lang.String getModelName() {
return this.modelName; return this.modelName;
} }
public void setModelName(java.lang.String modelName){ public void setModelName(java.lang.String modelName) {
this.modelName = modelName; this.modelName = modelName;
super.addValidField("modelName"); super.addValidField("modelName");
} }
/** owner /**
*模型服务商 * owner
*/ * 模型服务商
*/
private java.lang.String owner; private java.lang.String owner;
@Column(name = "owner",length = 100) @Column(name = "owner", length = 100)
public java.lang.String getOwner(){ public java.lang.String getOwner() {
return this.owner; return this.owner;
} }
public void setOwner(java.lang.String owner){ public void setOwner(java.lang.String owner) {
this.owner = owner; this.owner = owner;
super.addValidField("owner"); super.addValidField("owner");
} }
/**
* icon_url
* 模型图标
*/
private java.lang.String iconUrl;
@Column(name = "icon_url", length = 150)
public java.lang.String getIconUrl() {
return this.iconUrl;
}
public void setIconUrl(java.lang.String iconUrl) {
this.iconUrl = iconUrl;
super.addValidField("iconUrl");
}
/**
* model_nick_name
*/
private java.lang.String modelNickName;
@Column(name = "model_nick_name", length = 100)
public java.lang.String getModelNickName() {
return this.modelNickName;
}
public void setModelNickName(java.lang.String modelNickName) {
this.modelNickName = modelNickName;
super.addValidField("modelNickName");
}
} }
\ No newline at end of file
select distinct
agent_id,
dialogs_id,
member_id,
content,
`timestamp`
from
biz_agent_application_dialogues_record
where is_deleted ='N'
<< and member_id= :memberId>>
group by dialogs_id
order by `timestamp` desc
\ No newline at end of file
package cn.com.poc.agent_application.query;
import java.io.Serializable;
/**
* Query Condition class for MemberDialoguesQuery
*/
public class MemberDialoguesQueryCondition implements Serializable{
private static final long serialVersionUID = 1L;
private java.lang.Long memberId;
public java.lang.Long getMemberId(){
return this.memberId;
}
public void setMemberId(java.lang.Long memberId){
this.memberId = memberId;
}
}
\ No newline at end of file
package cn.com.poc.agent_application.query;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import cn.com.yict.framemax.data.model.BaseItemClass;
/**
* Query Item class for MemberDialoguesQuery
*/
@Entity
public class MemberDialoguesQueryItem extends BaseItemClass implements Serializable{
private static final long serialVersionUID = 1L;
/** agent_id
*agent_id
*/
private java.lang.String agentId;
@Column(name = "agent_id")
public java.lang.String getAgentId(){
return this.agentId;
}
public void setAgentId(java.lang.String agentId){
this.agentId = agentId;
}
/** dialogs_id
*dialogs_id
*/
private java.lang.String dialogsId;
@Column(name = "dialogs_id")
public java.lang.String getDialogsId(){
return this.dialogsId;
}
public void setDialogsId(java.lang.String dialogsId){
this.dialogsId = dialogsId;
}
/** member_id
*member_id
*/
private java.lang.Long memberId;
@Column(name = "member_id")
public java.lang.Long getMemberId(){
return this.memberId;
}
public void setMemberId(java.lang.Long memberId){
this.memberId = memberId;
}
/** content
*content
*/
private java.lang.String content;
@Column(name = "content")
public java.lang.String getContent(){
return this.content;
}
public void setContent(java.lang.String content){
this.content = content;
}
/** timestamp
*timestamp
*/
private java.lang.Long timestamp;
@Column(name = "timestamp")
public java.lang.Long getTimestamp(){
return this.timestamp;
}
public void setTimestamp(java.lang.Long timestamp){
this.timestamp = timestamp;
}
}
\ No newline at end of file
select distinct
baap.id,
bmi.nick_name,
baap.agent_id,
baap.agent_avatar,
baap.agent_title,
baap.agent_desc,
baap.MODIFIED_TIME
from
biz_agent_application_publish baap
left join biz_member_info bmi on baap.member_id = bmi.member_id
where baap.is_deleted = 'N'
<< and LOCATE(:query,baap.agent_title) >>
order by baap.MODIFIED_TIME desc
\ No newline at end of file
package cn.com.poc.agent_application.query;
import java.io.Serializable;
/**
* Query Condition class for PulishAgentApplicationQuery
*/
public class PublishAgentApplicationQueryCondition implements Serializable{
private static final long serialVersionUID = 1L;
private java.lang.String query;
public java.lang.String getQuery(){
return this.query;
}
public void setQuery(java.lang.String query){
this.query = query;
}
}
\ No newline at end of file
package cn.com.poc.agent_application.query;
import cn.com.yict.framemax.data.model.BaseItemClass;
import javax.persistence.Column;
import javax.persistence.Entity;
import java.io.Serializable;
/**
* Query Item class for PulishAgentApplicationQuery
*/
@Entity
public class PublishAgentApplicationQueryItem extends BaseItemClass implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
* id
*/
private java.lang.Integer id;
@Column(name = "id")
public java.lang.Integer getId() {
return this.id;
}
public void setId(java.lang.Integer id) {
this.id = id;
}
/**
* nick_name
* nick_name
*/
private java.lang.String nickName;
@Column(name = "nick_name")
public java.lang.String getNickName() {
return this.nickName;
}
public void setNickName(java.lang.String nickName) {
this.nickName = nickName;
}
/**
* agent_id
* agent_id
*/
private java.lang.String agentId;
@Column(name = "agent_id")
public java.lang.String getAgentId() {
return this.agentId;
}
public void setAgentId(java.lang.String agentId) {
this.agentId = agentId;
}
/**
* agent_avatar
* agent_avatar
*/
private java.lang.String agentAvatar;
@Column(name = "agent_avatar")
public java.lang.String getAgentAvatar() {
return this.agentAvatar;
}
public void setAgentAvatar(java.lang.String agentAvatar) {
this.agentAvatar = agentAvatar;
}
/**
* agent_title
* agent_title
*/
private java.lang.String agentTitle;
@Column(name = "agent_title")
public java.lang.String getAgentTitle() {
return this.agentTitle;
}
public void setAgentTitle(java.lang.String agentTitle) {
this.agentTitle = agentTitle;
}
/**
* agent_desc
* agent_desc
*/
private java.lang.String agentDesc;
@Column(name = "agent_desc")
public java.lang.String getAgentDesc() {
return this.agentDesc;
}
public void setAgentDesc(java.lang.String agentDesc) {
this.agentDesc = agentDesc;
}
/**
* MODIFIED_TIME
* MODIFIED_TIME
*/
private java.util.Date modifiedTime;
@Column(name = "MODIFIED_TIME")
public java.util.Date getModifiedTime() {
return this.modifiedTime;
}
public void setModifiedTime(java.util.Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
}
\ No newline at end of file
...@@ -56,6 +56,11 @@ public interface AgentApplicationInfoRest extends BaseRest { ...@@ -56,6 +56,11 @@ public interface AgentApplicationInfoRest extends BaseRest {
*/ */
List<BizAgentApplicationLargeModelListDto> getLargeModelList() throws Exception; List<BizAgentApplicationLargeModelListDto> getLargeModelList() throws Exception;
/**
* 查询模型信息
*/
BizAgentApplicationLargeModelListDto getLargeModelInfo(@RequestParam String query) throws Exception;
/** /**
* 角色指令AI生成 * 角色指令AI生成
......
...@@ -14,16 +14,25 @@ import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListSer ...@@ -14,16 +14,25 @@ import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListSer
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.common.utils.ListUtils;
import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import cn.hutool.core.collection.ListUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.ListUI;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -46,6 +55,9 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -46,6 +55,9 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Resource @Resource
private BizAgentApplicationLargeModelListService bizAgentApplicationLargeModelListService; private BizAgentApplicationLargeModelListService bizAgentApplicationLargeModelListService;
@Resource
private KnowledgeService knowledgeService;
public List<AgentApplicationInfoDto> getListByMember(AgentApplicationInfoSearchDto dto, PagingInfo pagingInfo) throws Exception { public List<AgentApplicationInfoDto> getListByMember(AgentApplicationInfoSearchDto dto, PagingInfo pagingInfo) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException(); UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
Long userId = userBaseEntity.getUserId(); Long userId = userBaseEntity.getUserId();
...@@ -131,8 +143,12 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -131,8 +143,12 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
if (infoEntity == null) { if (infoEntity == null) {
throw new BusinessException("应用不存在"); throw new BusinessException("应用不存在");
} }
//获取知识库配置
List<Integer> kdIds = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
//调用应用服务
agentApplicationInfoService.callAgentApplication(infoEntity.getLargeModel(), infoEntity.getUnitIds() agentApplicationInfoService.callAgentApplication(infoEntity.getLargeModel(), infoEntity.getUnitIds()
, infoEntity.getAgentSystem(), infoEntity.getKnowledgeIds(), infoEntity.getCommunicationTurn(), infoEntity.getTopP() , infoEntity.getAgentSystem(), kdIds.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getTopP()
, dto.getMessages(), infoEntity.getIsLongMemory().equals(CommonConstant.IsDeleted.Y), infoEntity.getVariableStructure(), infoEntity.getIsFunction().equals(CommonConstant.IsDeleted.Y), infoEntity.getFunctionName(), null , AgentApplicationConstants.USE_AGENT_STATUS.PREVIEW,httpServletResponse); , dto.getMessages(), infoEntity.getIsLongMemory().equals(CommonConstant.IsDeleted.Y), infoEntity.getVariableStructure(), infoEntity.getIsFunction().equals(CommonConstant.IsDeleted.Y), infoEntity.getFunctionName(), null , AgentApplicationConstants.USE_AGENT_STATUS.PREVIEW,httpServletResponse);
} catch (Exception e) { } catch (Exception e) {
httpServletResponse.setContentType("text/event-stream"); httpServletResponse.setContentType("text/event-stream");
...@@ -146,19 +162,37 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -146,19 +162,37 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Override @Override
public List<BizAgentApplicationLargeModelListDto> getLargeModelList() throws Exception { public List<BizAgentApplicationLargeModelListDto> getLargeModelList() throws Exception {
List<BizAgentApplicationLargeModelListEntity> entities = bizAgentApplicationLargeModelListService.findByExample(new BizAgentApplicationLargeModelListEntity(), null); List<BizAgentApplicationLargeModelListEntity> entities = bizAgentApplicationLargeModelListService.findByExample(new BizAgentApplicationLargeModelListEntity(), null);
Map<String, List<String>> map = entities.stream() Map<String, List<BizAgentApplicationLargeModelListEntity>> map = entities.stream()
.collect(Collectors.groupingBy(BizAgentApplicationLargeModelListEntity::getOwner .collect(Collectors.groupingBy(BizAgentApplicationLargeModelListEntity::getOwner));
, Collectors.mapping(BizAgentApplicationLargeModelListEntity::getModelName, Collectors.toList())));
List<BizAgentApplicationLargeModelListDto> result = new ArrayList<>(); List<BizAgentApplicationLargeModelListDto> result = new ArrayList<>();
for (String owner : map.keySet()) { for (String owner : map.keySet()) {
BizAgentApplicationLargeModelListDto dto = new BizAgentApplicationLargeModelListDto(); BizAgentApplicationLargeModelListDto dto = new BizAgentApplicationLargeModelListDto();
List<BizAgentApplicationLargeModelListEntity> modelListEntities = map.get(owner);
dto.setOwner(owner); dto.setOwner(owner);
dto.setModels(map.get(owner)); dto.setModels(modelListEntities.stream().map(BizAgentApplicationLargeModelListEntity::getModelNickName).collect(Collectors.toList()));
dto.setIcon(modelListEntities.get(0).getIconUrl());
result.add(dto); result.add(dto);
} }
return result; return result;
} }
@Override
public BizAgentApplicationLargeModelListDto getLargeModelInfo(String query) throws Exception {
Assert.notNull(query);
BizAgentApplicationLargeModelListEntity bizAgentApplicationLargeModelListEntity = new BizAgentApplicationLargeModelListEntity();
bizAgentApplicationLargeModelListEntity.setModelNickName(query);
List<BizAgentApplicationLargeModelListEntity> entities = bizAgentApplicationLargeModelListService.findByExample(bizAgentApplicationLargeModelListEntity, null);
if (CollectionUtils.isEmpty(entities)) {
throw new BusinessException("模型不存在");
}
BizAgentApplicationLargeModelListEntity entity = entities.get(0);
BizAgentApplicationLargeModelListDto result = new BizAgentApplicationLargeModelListDto();
result.setModels(ListUtil.toList(entity.getModelNickName()));
result.setOwner(entity.getOwner());
result.setIcon(entity.getIconUrl());
return result;
}
@Override @Override
public void createAgentSystem(AgentApplicationGCDto dto, HttpServletResponse response) throws Exception { public void createAgentSystem(AgentApplicationGCDto dto, HttpServletResponse response) throws Exception {
......
package cn.com.poc.agent_application.service; package cn.com.poc.agent_application.service;
import cn.com.poc.agent_application.query.MemberDialoguesQueryItem;
import cn.com.yict.framemax.core.service.BaseService; import cn.com.yict.framemax.core.service.BaseService;
import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.Collection;
import java.util.List; import java.util.List;
public interface BizAgentApplicationDialoguesRecordService extends BaseService { public interface BizAgentApplicationDialoguesRecordService extends BaseService {
...@@ -21,4 +21,12 @@ public interface BizAgentApplicationDialoguesRecordService extends BaseService { ...@@ -21,4 +21,12 @@ public interface BizAgentApplicationDialoguesRecordService extends BaseService {
List<BizAgentApplicationDialoguesRecordEntity> getRecord(String agentId, Integer turn); List<BizAgentApplicationDialoguesRecordEntity> getRecord(String agentId, Integer turn);
/**
* 获取用户的对话【组】
*
* @param memberId 用户id
* @return
*/
List<MemberDialoguesQueryItem> memberDialoguesQuery(Long memberId, PagingInfo pagingInfo);
} }
\ No newline at end of file
package cn.com.poc.agent_application.service; package cn.com.poc.agent_application.service;
import cn.com.yict.framemax.core.service.BaseService;
import cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity;
import cn.com.yict.framemax.core.service.BaseService;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.Collection;
import java.util.List; import java.util.List;
public interface BizAgentApplicationLargeModelListService extends BaseService { public interface BizAgentApplicationLargeModelListService extends BaseService {
BizAgentApplicationLargeModelListEntity findByModelNickName(String modelNickName);
BizAgentApplicationLargeModelListEntity get(java.lang.Integer id) throws Exception; BizAgentApplicationLargeModelListEntity get(java.lang.Integer id) throws Exception;
List<BizAgentApplicationLargeModelListEntity> findByExample(BizAgentApplicationLargeModelListEntity example,PagingInfo pagingInfo) throws Exception; List<BizAgentApplicationLargeModelListEntity> findByExample(BizAgentApplicationLargeModelListEntity example,PagingInfo pagingInfo) throws Exception;
......
package cn.com.poc.agent_application.service; package cn.com.poc.agent_application.service;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryCondition;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem;
import cn.com.yict.framemax.core.service.BaseService; import cn.com.yict.framemax.core.service.BaseService;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.Collection;
import java.util.List; import java.util.List;
public interface BizAgentApplicationPublishService extends BaseService { public interface BizAgentApplicationPublishService extends BaseService {
...@@ -12,8 +14,8 @@ public interface BizAgentApplicationPublishService extends BaseService { ...@@ -12,8 +14,8 @@ public interface BizAgentApplicationPublishService extends BaseService {
BizAgentApplicationPublishEntity getByAgentId(String agentId) throws Exception; BizAgentApplicationPublishEntity getByAgentId(String agentId) throws Exception;
List<BizAgentApplicationPublishEntity> findByExample(BizAgentApplicationPublishEntity example,PagingInfo pagingInfo) throws Exception; List<BizAgentApplicationPublishEntity> findByExample(BizAgentApplicationPublishEntity example, PagingInfo pagingInfo) throws Exception;
BizAgentApplicationPublishEntity save(BizAgentApplicationPublishEntity entity) throws Exception; BizAgentApplicationPublishEntity save(BizAgentApplicationPublishEntity entity) throws Exception;
BizAgentApplicationPublishEntity update(BizAgentApplicationPublishEntity entity) throws Exception; BizAgentApplicationPublishEntity update(BizAgentApplicationPublishEntity entity) throws Exception;
...@@ -21,5 +23,6 @@ public interface BizAgentApplicationPublishService extends BaseService { ...@@ -21,5 +23,6 @@ public interface BizAgentApplicationPublishService extends BaseService {
void deletedById(java.lang.Integer id) throws Exception; void deletedById(java.lang.Integer id) throws Exception;
void deleteByAgentId(String agentId) throws Exception; void deleteByAgentId(String agentId) throws Exception;
List<PublishAgentApplicationQueryItem> query(PublishAgentApplicationQueryCondition condition, PagingInfo pagingInfo) throws Exception;
} }
\ No newline at end of file
package cn.com.poc.agent_application.service.impl; package cn.com.poc.agent_application.service.impl;
import cn.com.poc.agent_application.query.MemberDialoguesQueryCondition;
import cn.com.poc.agent_application.query.MemberDialoguesQueryItem;
import cn.com.yict.framemax.core.service.impl.BaseServiceImpl; import cn.com.yict.framemax.core.service.impl.BaseServiceImpl;
import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService; import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService;
import cn.com.poc.agent_application.model.BizAgentApplicationDialoguesRecordModel; import cn.com.poc.agent_application.model.BizAgentApplicationDialoguesRecordModel;
...@@ -116,4 +118,11 @@ public class BizAgentApplicationDialoguesRecordServiceImpl extends BaseServiceIm ...@@ -116,4 +118,11 @@ public class BizAgentApplicationDialoguesRecordServiceImpl extends BaseServiceIm
public List<BizAgentApplicationDialoguesRecordEntity> getRecord(String agentId, Integer turn) { public List<BizAgentApplicationDialoguesRecordEntity> getRecord(String agentId, Integer turn) {
return null; return null;
} }
@Override
public List<MemberDialoguesQueryItem> memberDialoguesQuery(Long memberId, PagingInfo pagingInfo) {
MemberDialoguesQueryCondition condition = new MemberDialoguesQueryCondition();
condition.setMemberId(memberId);
return this.sqlDao.query(condition, MemberDialoguesQueryItem.class,pagingInfo);
}
} }
\ No newline at end of file
package cn.com.poc.agent_application.service.impl; package cn.com.poc.agent_application.service.impl;
import cn.com.yict.framemax.core.service.impl.BaseServiceImpl; import cn.com.yict.framemax.core.service.impl.BaseServiceImpl;
import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListService; import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListService;
...@@ -10,70 +10,85 @@ import cn.com.yict.framemax.data.model.PagingInfo; ...@@ -10,70 +10,85 @@ import cn.com.yict.framemax.data.model.PagingInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@Service @Service
public class BizAgentApplicationLargeModelListServiceImpl extends BaseServiceImpl public class BizAgentApplicationLargeModelListServiceImpl extends BaseServiceImpl
implements BizAgentApplicationLargeModelListService { implements BizAgentApplicationLargeModelListService {
@Resource @Resource
private BizAgentApplicationLargeModelListRepository repository; private BizAgentApplicationLargeModelListRepository repository;
public BizAgentApplicationLargeModelListEntity get(java.lang.Integer id) throws Exception{ @Override
public BizAgentApplicationLargeModelListEntity findByModelNickName(String modelNickName) {
Assert.notNull(modelNickName);
BizAgentApplicationLargeModelListModel bizAgentApplicationLargeModelListModel = new BizAgentApplicationLargeModelListModel();
bizAgentApplicationLargeModelListModel.setModelNickName(modelNickName);
List<BizAgentApplicationLargeModelListModel> models = this.repository.findByExample(bizAgentApplicationLargeModelListModel);
if (CollectionUtils.isNotEmpty(models)) {
return BizAgentApplicationLargeModelListConvert.modelToEntity(models.get(0));
}
return null;
}
public BizAgentApplicationLargeModelListEntity get(java.lang.Integer id) throws Exception {
Assert.notNull(id); Assert.notNull(id);
BizAgentApplicationLargeModelListModel model = this.repository.get(id); BizAgentApplicationLargeModelListModel model = this.repository.get(id);
if (model == null){ if (model == null) {
return null; return null;
} }
return BizAgentApplicationLargeModelListConvert.modelToEntity(model); return BizAgentApplicationLargeModelListConvert.modelToEntity(model);
} }
public List<BizAgentApplicationLargeModelListEntity> findByExample(BizAgentApplicationLargeModelListEntity example,PagingInfo pagingInfo) throws Exception{ public List<BizAgentApplicationLargeModelListEntity> findByExample(BizAgentApplicationLargeModelListEntity example, PagingInfo pagingInfo) throws Exception {
List<BizAgentApplicationLargeModelListEntity> result = new ArrayList<BizAgentApplicationLargeModelListEntity>(); List<BizAgentApplicationLargeModelListEntity> result = new ArrayList<BizAgentApplicationLargeModelListEntity>();
BizAgentApplicationLargeModelListModel model = new BizAgentApplicationLargeModelListModel(); BizAgentApplicationLargeModelListModel model = new BizAgentApplicationLargeModelListModel();
if (example != null){ if (example != null) {
model = BizAgentApplicationLargeModelListConvert.entityToModel(example); model = BizAgentApplicationLargeModelListConvert.entityToModel(example);
} }
List<BizAgentApplicationLargeModelListModel> models = this.repository.findByExample(model,pagingInfo); List<BizAgentApplicationLargeModelListModel> models = this.repository.findByExample(model, pagingInfo);
if (CollectionUtils.isNotEmpty(models)) { if (CollectionUtils.isNotEmpty(models)) {
result = models.stream().map(BizAgentApplicationLargeModelListConvert::modelToEntity).collect(Collectors.toList()); result = models.stream().map(BizAgentApplicationLargeModelListConvert::modelToEntity).collect(Collectors.toList());
} }
return result; return result;
} }
public BizAgentApplicationLargeModelListEntity save(BizAgentApplicationLargeModelListEntity entity) throws Exception{ public BizAgentApplicationLargeModelListEntity save(BizAgentApplicationLargeModelListEntity entity) throws Exception {
Assert.notNull(entity); Assert.notNull(entity);
entity.setId(null); entity.setId(null);
BizAgentApplicationLargeModelListModel model = BizAgentApplicationLargeModelListConvert.entityToModel(entity); BizAgentApplicationLargeModelListModel model = BizAgentApplicationLargeModelListConvert.entityToModel(entity);
BizAgentApplicationLargeModelListModel saveModel = this.repository.save(model); BizAgentApplicationLargeModelListModel saveModel = this.repository.save(model);
return BizAgentApplicationLargeModelListConvert.modelToEntity(saveModel); return BizAgentApplicationLargeModelListConvert.modelToEntity(saveModel);
} }
public BizAgentApplicationLargeModelListEntity update(BizAgentApplicationLargeModelListEntity entity) throws Exception{ public BizAgentApplicationLargeModelListEntity update(BizAgentApplicationLargeModelListEntity entity) throws Exception {
Assert.notNull(entity); Assert.notNull(entity);
Assert.notNull(entity.getId(),"update pk can not be null"); Assert.notNull(entity.getId(), "update pk can not be null");
BizAgentApplicationLargeModelListModel model = this.repository.get(entity.getId()); BizAgentApplicationLargeModelListModel model = this.repository.get(entity.getId());
if (entity.getModelName() != null){ if (entity.getModelName() != null) {
model.setModelName(entity.getModelName()); model.setModelName(entity.getModelName());
} }
if (entity.getOwner() != null){ if (entity.getOwner() != null) {
model.setOwner(entity.getOwner()); model.setOwner(entity.getOwner());
} }
BizAgentApplicationLargeModelListModel saveModel = this.repository.save(model); BizAgentApplicationLargeModelListModel saveModel = this.repository.save(model);
return BizAgentApplicationLargeModelListConvert.modelToEntity(saveModel); return BizAgentApplicationLargeModelListConvert.modelToEntity(saveModel);
} }
public void deletedById(java.lang.Integer id) throws Exception{ public void deletedById(java.lang.Integer id) throws Exception {
Assert.notNull(id); Assert.notNull(id);
BizAgentApplicationLargeModelListModel model = this.repository.get(id); BizAgentApplicationLargeModelListModel model = this.repository.get(id);
if (model != null){ if (model != null) {
} }
} }
} }
\ No newline at end of file
package cn.com.poc.agent_application.service.impl; package cn.com.poc.agent_application.service.impl;
import cn.com.poc.agent_application.constant.AgentApplicationConstants; import cn.com.poc.agent_application.constant.AgentApplicationConstants;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryCondition;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
...@@ -120,6 +122,11 @@ public class BizAgentApplicationPublishServiceImpl extends BaseServiceImpl ...@@ -120,6 +122,11 @@ public class BizAgentApplicationPublishServiceImpl extends BaseServiceImpl
} }
} }
@Override
public List<PublishAgentApplicationQueryItem> query(PublishAgentApplicationQueryCondition condition, PagingInfo pagingInfo) throws Exception {
return this.sqlDao.query(condition, PublishAgentApplicationQueryItem.class, pagingInfo);
}
/** /**
* 参数验证和转换 Entity To Model * 参数验证和转换 Entity To Model
* *
......
...@@ -13,6 +13,21 @@ import java.util.UUID; ...@@ -13,6 +13,21 @@ import java.util.UUID;
*/ */
public class FileUtils { public class FileUtils {
/**
* 格式化文件大小
*/
public static String formatFileSize(long bytes) {
if (bytes < 1024) {
return bytes + " B";
} else if (bytes < 1024 * 1024) {
return String.format("%.2f KB", bytes / 1024.0);
} else if (bytes < 1024 * 1024 * 1024) {
return String.format("%.2f MB", bytes / (1024.0 * 1024));
} else {
return String.format("%.2f GB", bytes / (1024.0 * 1024 * 1024));
}
}
public static File multipartFileToFile(MultipartFile multiFile) { public static File multipartFileToFile(MultipartFile multiFile) {
// 获取文件名 // 获取文件名
...@@ -36,7 +51,7 @@ public class FileUtils { ...@@ -36,7 +51,7 @@ public class FileUtils {
* @param data * @param data
* @throws Exception * @throws Exception
*/ */
public static File createTempFile(byte[] data,String fileSuffix) throws IOException { public static File createTempFile(byte[] data, String fileSuffix) throws IOException {
if (data != null) { if (data != null) {
File file = File.createTempFile(UUID.randomUUID().toString(), fileSuffix); File file = File.createTempFile(UUID.randomUUID().toString(), fileSuffix);
if (file.exists()) { if (file.exists()) {
......
...@@ -14,6 +14,11 @@ import cn.com.poc.common.constant.CommonConstant; ...@@ -14,6 +14,11 @@ import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.expose.aggregate.AgentApplicationService; import cn.com.poc.expose.aggregate.AgentApplicationService;
import cn.com.poc.expose.dto.AgentApplicationDto;
import cn.com.poc.expose.rest.AgentApplicationRest;
import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent;
...@@ -23,6 +28,7 @@ import cn.com.poc.thirdparty.service.LLMService; ...@@ -23,6 +28,7 @@ import cn.com.poc.thirdparty.service.LLMService;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -38,6 +44,10 @@ import java.util.List; ...@@ -38,6 +44,10 @@ import java.util.List;
public class AgentApplicationServiceImpl implements AgentApplicationService { public class AgentApplicationServiceImpl implements AgentApplicationService {
final private Logger logger = LoggerFactory.getLogger(AgentApplicationService.class); final private Logger logger = LoggerFactory.getLogger(AgentApplicationService.class);
@Resource
private KnowledgeService knowledgeService;
@Resource @Resource
private BizAgentApplicationPublishService bizAgentApplicationPublishService; private BizAgentApplicationPublishService bizAgentApplicationPublishService;
...@@ -71,19 +81,16 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -71,19 +81,16 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
throw new BusinessException("未找到应用"); throw new BusinessException("未找到应用");
} }
//todo 这个agent 会开启那些 function //获取知识库配置
List<Integer> kdIdList = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
//todo 假设 1. 【变量】
//todo [变量] function_name , function_name
// 构造对话参数 // 构造对话参数
List<Message> messages = new ArrayList<>(); List<Message> messages = new ArrayList<>();
buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), messages, input); buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), messages, input);
// function_name -- List<>
String output = agentApplicationInfoService.callAgentApplication(infoEntity.getLargeModel(), infoEntity.getUnitIds() String output = agentApplicationInfoService.callAgentApplication(infoEntity.getLargeModel(), infoEntity.getUnitIds()
, infoEntity.getAgentSystem(), infoEntity.getKnowledgeIds(), infoEntity.getCommunicationTurn(), infoEntity.getTopP() , infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getTopP()
, messages, infoEntity.getIsLongMemory().equals(CommonConstant.IsDeleted.Y), infoEntity.getVariableStructure(), infoEntity.getIsFunction().equals(CommonConstant.IsDeleted.Y), infoEntity.getFunctionName(), null, AgentApplicationConstants.USE_AGENT_STATUS.PUBLISH, httpServletResponse); , messages, infoEntity.getIsLongMemory().equals(CommonConstant.IsDeleted.Y), infoEntity.getVariableStructure(), infoEntity.getIsFunction().equals(CommonConstant.IsDeleted.Y), infoEntity.getFunctionName(), null, AgentApplicationConstants.USE_AGENT_STATUS.PUBLISH, httpServletResponse);
......
package cn.com.poc.expose.dto;
import java.io.Serializable;
public class DialoguesContextDto implements Serializable {
/** role
*角色 user-用户 assistant-助手
*/
private java.lang.String role;
public java.lang.String getRole(){
return this.role;
}
public void setRole(java.lang.String role){
this.role = role;
}
/** agent_id
*agent应用ID
*/
private java.lang.String agentId;
public java.lang.String getAgentId(){
return this.agentId;
}
public void setAgentId(java.lang.String agentId){
this.agentId = agentId;
}
/** content
*内容
*/
private java.lang.String content;
public java.lang.String getContent(){
return this.content;
}
public void setContent(java.lang.String content){
this.content = content;
}
/** timestamp
*时间戳
*/
private java.lang.Long timestamp;
public java.lang.Long getTimestamp(){
return this.timestamp;
}
public void setTimestamp(java.lang.Long timestamp){
this.timestamp = timestamp;
}
}
package cn.com.poc.expose.dto;
import java.io.Serializable;
import java.util.Date;
public class SearchAgentApplicationDto implements Serializable {
/**
* 应用id
*/
private String agentId;
/**
* 应用名称
*/
private String agentTitle;
/**
* 应用描述
*/
private String agentDesc;
/**
* 应用头像
*/
private String agentAvatar;
/**
* 发布时间
*/
private Date publishedTime;
/**
* 创建人
*/
private String creator;
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public String getAgentTitle() {
return agentTitle;
}
public void setAgentTitle(String agentTitle) {
this.agentTitle = agentTitle;
}
public String getAgentDesc() {
return agentDesc;
}
public void setAgentDesc(String agentDesc) {
this.agentDesc = agentDesc;
}
public String getAgentAvatar() {
return agentAvatar;
}
public void setAgentAvatar(String agentAvatar) {
this.agentAvatar = agentAvatar;
}
public Date getPublishedTime() {
return publishedTime;
}
public void setPublishedTime(Date publishedTime) {
this.publishedTime = publishedTime;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
}
package cn.com.poc.expose.dto;
import java.io.Serializable;
public class UserDialoguesDto implements Serializable {
/**
* 会话ID
*/
private java.lang.String dialogsId;
/**
* 内容
*/
private String content;
public String getDialogsId() {
return dialogsId;
}
public void setDialogsId(String dialogsId) {
this.dialogsId = dialogsId;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package cn.com.poc.expose.rest; package cn.com.poc.expose.rest;
import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto; import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
import cn.com.poc.expose.dto.AgentApplicationDto; import cn.com.poc.expose.dto.AgentApplicationDto;
import cn.com.poc.expose.dto.DialoguesContextDto;
import cn.com.poc.expose.dto.SearchAgentApplicationDto;
import cn.com.poc.expose.dto.UserDialoguesDto;
import cn.com.yict.framemax.core.rest.BaseRest; import cn.com.yict.framemax.core.rest.BaseRest;
import cn.com.yict.framemax.data.model.PagingInfo;
import cn.com.yict.framemax.web.permission.Access; import cn.com.yict.framemax.web.permission.Access;
import cn.com.yict.framemax.web.permission.Permission; import cn.com.yict.framemax.web.permission.Permission;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -19,7 +24,7 @@ public interface AgentApplicationRest extends BaseRest { ...@@ -19,7 +24,7 @@ public interface AgentApplicationRest extends BaseRest {
/** /**
* 创建对话 * 创建对话
*/ */
String createDialogues(); String createDialogues(@RequestParam String agentId) throws Exception;
/** /**
* 调用 已发布Agent应用 * 调用 已发布Agent应用
...@@ -27,12 +32,13 @@ public interface AgentApplicationRest extends BaseRest { ...@@ -27,12 +32,13 @@ public interface AgentApplicationRest extends BaseRest {
void callAgentApplication(@RequestBody AgentApplicationDto dto, HttpServletResponse httpServletResponse) throws Exception; void callAgentApplication(@RequestBody AgentApplicationDto dto, HttpServletResponse httpServletResponse) throws Exception;
/** /**
* 获取 已发布Agent应用 * 获取 已发布Agent应用列表
*/ */
List<BizAgentApplicationPublishDto> getAgentApplication(@RequestBody AgentApplicationInfoSearchDto dto, HttpServletResponse httpServletResponse) throws Exception; @Permission(value = Access.Anonymous)
List<SearchAgentApplicationDto> agentApplicationList(@RequestBody AgentApplicationInfoSearchDto dto, PagingInfo pagingInfo) throws Exception;
/** /**
* 获取应用详情 * 获取 已发布应用详情
*/ */
@Permission(value = Access.Anonymous) @Permission(value = Access.Anonymous)
BizAgentApplicationPublishDto getInfo(@RequestParam String agentId) throws Exception; BizAgentApplicationPublishDto getInfo(@RequestParam String agentId) throws Exception;
...@@ -42,4 +48,19 @@ public interface AgentApplicationRest extends BaseRest { ...@@ -42,4 +48,19 @@ public interface AgentApplicationRest extends BaseRest {
*/ */
List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto) throws Exception; List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto) throws Exception;
/**
* 获取用户已创建的对话记录
*/
List<UserDialoguesDto> getUserDialogues() throws Exception;
/**
* 关闭对话
*/
void closeDialogues(@RequestParam String dialogueId) throws Exception;
/**
* 获取对话上下文
*/
List<DialoguesContextDto> getDialogueContext(@RequestParam String dialogueId) throws Exception;
} }
package cn.com.poc.expose.rest.impl; package cn.com.poc.expose.rest.impl;
import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert;
import cn.com.poc.agent_application.convert.BizAgentApplicationDialoguesRecordConvert;
import cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert; import cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert;
import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto; import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationDialoguesRecordDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.poc.agent_application.query.MemberDialoguesQueryItem;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryCondition;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem;
import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.Assert; import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.common.utils.UUIDTool; import cn.com.poc.common.utils.UUIDTool;
import cn.com.poc.expose.aggregate.AgentApplicationService; import cn.com.poc.expose.aggregate.AgentApplicationService;
import cn.com.poc.expose.dto.AgentApplicationDto; import cn.com.poc.expose.dto.AgentApplicationDto;
import cn.com.poc.expose.dto.DialoguesContextDto;
import cn.com.poc.expose.dto.SearchAgentApplicationDto;
import cn.com.poc.expose.dto.UserDialoguesDto;
import cn.com.poc.expose.rest.AgentApplicationRest; import cn.com.poc.expose.rest.AgentApplicationRest;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class AgentApplicationRestImpl implements AgentApplicationRest { public class AgentApplicationRestImpl implements AgentApplicationRest {
...@@ -30,8 +49,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -30,8 +49,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
@Resource @Resource
private BizAgentApplicationPublishService bizAgentApplicationPublishService; private BizAgentApplicationPublishService bizAgentApplicationPublishService;
@Resource
private BizAgentApplicationDialoguesRecordService bizAgentApplicationDialoguesRecordService;
@Override @Override
public String createDialogues() { public String createDialogues(String agentId) {
return "DIA_" + UUIDTool.getUUID(); return "DIA_" + UUIDTool.getUUID();
} }
...@@ -53,8 +75,17 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -53,8 +75,17 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
} }
@Override @Override
public List<BizAgentApplicationPublishDto> getAgentApplication(AgentApplicationInfoSearchDto dto, HttpServletResponse httpServletResponse) throws Exception { public List<SearchAgentApplicationDto> agentApplicationList(AgentApplicationInfoSearchDto dto, PagingInfo pagingInfo) throws Exception {
return null; PublishAgentApplicationQueryCondition condition = new PublishAgentApplicationQueryCondition();
if (StringUtils.isNotBlank(dto.getQuery())) {
condition.setQuery(dto.getQuery());
}
List<SearchAgentApplicationDto> result = new ArrayList<>();
List<PublishAgentApplicationQueryItem> items = bizAgentApplicationPublishService.query(condition, pagingInfo);
if (CollectionUtils.isNotEmpty(items)) {
result = items.stream().map(AgentApplicationInfoConvert::itemToSearchDto).collect(Collectors.toList());
}
return result;
} }
@Override @Override
...@@ -72,4 +103,59 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -72,4 +103,59 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
cn.com.poc.common.utils.Assert.notNull(dto.getInput(), "input不能为空"); cn.com.poc.common.utils.Assert.notNull(dto.getInput(), "input不能为空");
return agentApplicationService.createContinueQuestions(dto.getInput()); return agentApplicationService.createContinueQuestions(dto.getInput());
} }
@Override
public List<UserDialoguesDto> getUserDialogues() throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) {
throw new BusinessException("用户未登录");
}
Long userId = userBaseEntity.getUserId();
List<UserDialoguesDto> result = new ArrayList<>();
List<MemberDialoguesQueryItem> memberDialoguesQueryItems = bizAgentApplicationDialoguesRecordService.memberDialoguesQuery(userId, null);
if (CollectionUtils.isNotEmpty(memberDialoguesQueryItems)) {
result = memberDialoguesQueryItems.stream().map(item -> {
UserDialoguesDto userDialoguesDto = new UserDialoguesDto();
userDialoguesDto.setDialogsId(item.getDialogsId());
userDialoguesDto.setContent(item.getContent());
return userDialoguesDto;
}).collect(Collectors.toList());
}
return result;
}
@Override
public void closeDialogues(String dialogueId) throws Exception {
Assert.notBlank(dialogueId, "对话ID不能为空");
BizAgentApplicationDialoguesRecordEntity recordEntity = new BizAgentApplicationDialoguesRecordEntity();
recordEntity.setDialogsId(dialogueId);
recordEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizAgentApplicationDialoguesRecordEntity> entities = bizAgentApplicationDialoguesRecordService.findByExample(recordEntity, null);
if (CollectionUtils.isNotEmpty(entities)) {
for (BizAgentApplicationDialoguesRecordEntity entity : entities) {
bizAgentApplicationDialoguesRecordService.deletedById(entity.getId());
}
}
}
@Override
public List<DialoguesContextDto> getDialogueContext(String dialogueId) throws Exception {
Assert.notBlank(dialogueId, "对话ID不能为空");
BizAgentApplicationDialoguesRecordEntity recordEntity = new BizAgentApplicationDialoguesRecordEntity();
recordEntity.setDialogsId(dialogueId);
recordEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizAgentApplicationDialoguesRecordEntity> entities = bizAgentApplicationDialoguesRecordService.findByExample(recordEntity, null);
if (CollectionUtils.isNotEmpty(entities)) {
return entities.stream().map(value -> {
DialoguesContextDto dto = new DialoguesContextDto();
dto.setRole(value.getRole());
dto.setAgentId(value.getAgentId());
dto.setContent(value.getContent());
dto.setTimestamp(value.getTimestamp());
return dto;
}
).collect(Collectors.toList());
}
return null;
}
} }
package cn.com.poc.knowledge.aggregate; package cn.com.poc.knowledge.aggregate;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.GetKnowledgeChunkInfoResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -19,10 +21,11 @@ public interface KnowledgeService { ...@@ -19,10 +21,11 @@ public interface KnowledgeService {
/** /**
* 删除文档 * 删除文档
* *
* @param kdId 主键ID * @param knowledgeInfoId 知识库ID
* @param kdId 文档ID
* @return 是否成功 * @return 是否成功
*/ */
Boolean delDocument(Integer kdId); Boolean delDocument(Integer knowledgeInfoId, Integer kdId);
/** /**
...@@ -42,17 +45,64 @@ public interface KnowledgeService { ...@@ -42,17 +45,64 @@ public interface KnowledgeService {
/** /**
* 开启训练 * 开启训练
*/ */
Boolean trainKnowledge(List<Integer> kdId) throws Exception; Boolean trainKnowledge(Integer knowledgeInfoId, List<Integer> kdId, SegmentationConfigRequest segmentationConfig) throws Exception;
/** /**
* 获取用户知识库 * 获取用户知识库
*/ */
List<BizKnowledgeDocumentEntity> getList(String search, String trainStatus, PagingInfo pagingInfo) throws Exception; List<BizKnowledgeDocumentEntity> searchDocuments(String search, String trainStatus, List<Integer> kdIds, String memberId, PagingInfo pagingInfo);
/** /**
* 获取用户知识库 * 获取用户知识库文档
*/ */
List<BizKnowledgeDocumentEntity> getListByKdIds(List<Integer> kdIds); List<BizKnowledgeDocumentEntity> getListByKdIds(List<Integer> kdIds);
/**
* 获取知识库分片
*/
GetKnowledgeChunkInfoResult getChunkInfo(List<Integer> kdIds, PagingInfo pagingInfo);
/**
* 开关知识库分片
*
* @param kdId 知识库id
* @param chunkRelationId 分片关系id
* @param isOpen 是否开启 Y/N
*/
void openKnowledgeChunk(Integer kdId, String chunkRelationId, String isOpen);
/**
* 删除知识库分片
*
* @param kdId 知识库id
* @param chunkRelationId 分片关系id
*/
void deleteKnowledgeChunk(Integer kdId, String chunkRelationId);
/**
* 更新知识库分片内容
*
* @param kdId 知识库id
* @param chunkRelationId 分片关系id
* @param content 分片内容
*/
void updateKnowledgeChunkDoc(Integer kdId, String chunkRelationId, String content);
/**
* 新增知识库分片
*
* @param kdId 知识库id
* @param content 分片内容
* @param chunkSort 分片排序
*/
void addKnowledgeChunk(Integer kdId, String content, Integer chunkSort);
/**
* 获取知识库文档ID列表
*
* @param knowledgeInfoIds 知识库信息ID列表
*/
List<Integer> getKdIdsByKnowledgeInfoIds(String[] knowledgeInfoIds) throws Exception;
} }
...@@ -7,17 +7,24 @@ import cn.com.poc.common.utils.*; ...@@ -7,17 +7,24 @@ import cn.com.poc.common.utils.*;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.constant.KnowledgeConstant; import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.entity.BizMemberKnowledgeRelationEntity; import cn.com.poc.knowledge.entity.BizMemberKnowledgeRelationEntity;
import cn.com.poc.knowledge.query.KnowledgeQueryItem; import cn.com.poc.knowledge.query.KnowledgeQueryItem;
import cn.com.poc.knowledge.service.BizKnowledgeDocumentService; import cn.com.poc.knowledge.service.BizKnowledgeDocumentService;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.knowledge.service.BizMemberKnowledgeRelationService; import cn.com.poc.knowledge.service.BizMemberKnowledgeRelationService;
import cn.com.poc.message.entity.TrainKnowledgeMessage; import cn.com.poc.message.entity.TrainKnowledgeMessage;
import cn.com.poc.message.service.KnowledgeProducerService; import cn.com.poc.message.service.KnowledgeProducerService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.GetKnowledgeChunkInfoResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -42,6 +49,11 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -42,6 +49,11 @@ public class KnowledgeServiceImpl implements KnowledgeService {
@Resource @Resource
private KnowledgeProducerService knowledgeProducerService; private KnowledgeProducerService knowledgeProducerService;
@Resource
private DemandKnowledgeService demandKnowledgeService;
@Resource
private BizKnowledgeInfoService bizKnowledgeInfoService;
@Resource @Resource
private BosConfigService bosConfigService; private BosConfigService bosConfigService;
...@@ -61,12 +73,6 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -61,12 +73,6 @@ public class KnowledgeServiceImpl implements KnowledgeService {
//获取文件名 //获取文件名
String documentName = documentFile.getOriginalFilename(); String documentName = documentFile.getOriginalFilename();
// 查看是否有重名
List<KnowledgeQueryItem> knowledgeQueryItems = bizKnowledgeDocumentService.searchKnowledge(null, null, memberId, documentName, null);
if (CollectionUtils.isNotEmpty(knowledgeQueryItems)) {
throw new BusinessException("上传文件存在重名,文件名:" + documentName);
}
// 统计文件字符数 // 统计文件字符数
String type = documentFile.getOriginalFilename().substring(documentFile.getOriginalFilename().lastIndexOf(".") + 1, documentFile.getOriginalFilename().length()); String type = documentFile.getOriginalFilename().substring(documentFile.getOriginalFilename().lastIndexOf(".") + 1, documentFile.getOriginalFilename().length());
File file = File.createTempFile(UUIDTool.getUUID(), "." + type); File file = File.createTempFile(UUIDTool.getUUID(), "." + type);
...@@ -74,7 +80,7 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -74,7 +80,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
// 文件大小不能超过10M // 文件大小不能超过10M
long fileSizeInBytes = file.length(); long fileSizeInBytes = file.length();
double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024); double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024);
if (fileSizeInMB > 5) { if (fileSizeInMB > 10) {
throw new BusinessException("上传的文件不能超过5M,文件名:" + documentName); throw new BusinessException("上传的文件不能超过5M,文件名:" + documentName);
} }
...@@ -90,7 +96,7 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -90,7 +96,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
} }
//文件上传 //文件上传
String documentUrl = bosConfigService.upload(Files.newInputStream(file.toPath()),type, documentFile.getContentType()); String documentUrl = bosConfigService.upload(Files.newInputStream(file.toPath()), type, documentFile.getContentType());
//保存记录 //保存记录
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = new BizKnowledgeDocumentEntity(); BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = new BizKnowledgeDocumentEntity();
...@@ -98,6 +104,7 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -98,6 +104,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
bizKnowledgeDocumentEntity.setKnowledgeType(KnowledgeConstant.KnowledgeType.BASE); bizKnowledgeDocumentEntity.setKnowledgeType(KnowledgeConstant.KnowledgeType.BASE);
bizKnowledgeDocumentEntity.setDocumentName(documentName); bizKnowledgeDocumentEntity.setDocumentName(documentName);
bizKnowledgeDocumentEntity.setDocumentUrl(documentUrl); bizKnowledgeDocumentEntity.setDocumentUrl(documentUrl);
bizKnowledgeDocumentEntity.setDocumentSize(fileSizeInBytes);
bizKnowledgeDocumentEntity.setCharCount(charCount); bizKnowledgeDocumentEntity.setCharCount(charCount);
bizKnowledgeDocumentEntity.setUploadTime(uploadTime); bizKnowledgeDocumentEntity.setUploadTime(uploadTime);
bizKnowledgeDocumentEntity.setIsEnable(CommonConstant.YOrN.N); bizKnowledgeDocumentEntity.setIsEnable(CommonConstant.YOrN.N);
...@@ -121,10 +128,11 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -121,10 +128,11 @@ public class KnowledgeServiceImpl implements KnowledgeService {
} }
@Override @Override
public Boolean delDocument(Integer kdId) { public Boolean delDocument(Integer knowledgeInfoId, Integer kdId) {
Assert.notNull(kdId, "kdId cannot be null"); Assert.notNull(kdId, "kdId cannot be null");
bizKnowledgeDocumentService.deleted(kdId); bizKnowledgeDocumentService.deleted(kdId);
bizMemberKnowledgeRelationService.deletedByKdId(kdId); bizMemberKnowledgeRelationService.deletedByKdId(kdId);
bizKnowledgeInfoService.removeDocument(knowledgeInfoId, kdId);
return true; return true;
} }
...@@ -144,6 +152,9 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -144,6 +152,9 @@ public class KnowledgeServiceImpl implements KnowledgeService {
@Override @Override
public String enableKnowledge(Integer kdId) throws Exception { public String enableKnowledge(Integer kdId) throws Exception {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId); BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (bizKnowledgeDocumentEntity == null) {
throw new BusinessException("document not exist");
}
String isEnable = bizKnowledgeDocumentEntity.getIsEnable(); String isEnable = bizKnowledgeDocumentEntity.getIsEnable();
if (CommonConstant.YOrN.N.equals(isEnable)) { if (CommonConstant.YOrN.N.equals(isEnable)) {
...@@ -156,15 +167,16 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -156,15 +167,16 @@ public class KnowledgeServiceImpl implements KnowledgeService {
} }
@Override @Override
public Boolean trainKnowledge(List<Integer> kdIds) throws Exception { public Boolean trainKnowledge(Integer knowledgeInfoId, List<Integer> kdIds, SegmentationConfigRequest segmentationConfig) throws Exception {
Assert.notEmpty(kdIds); Assert.notEmpty(kdIds);
Assert.isTrue(kdIds.size() <= 5, "Training cannot exceed five documents"); Assert.isTrue(kdIds.size() <= 5, "Training cannot exceed five documents");
BizKnowledgeInfoEntity knowledgeInfoEntity = bizKnowledgeInfoService.get(knowledgeInfoId);
if (knowledgeInfoEntity == null) {
throw new BusinessException("Knowledge information does not exist");
}
for (Integer kdId : kdIds) { for (Integer kdId : kdIds) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId); BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
// 扣减次数
// AiGcMemberEntity currentMember = aiGcVipService.getCurrentMember(BlContext.getCurrentUserNotException());
// Map<Integer, Integer> reduced = bizAiGcMemberFreqService.reduceNumber(currentMember.getRelationId(), AiGcPaymentConfigurationConstant.DOMAIN.TRAIN, currentMember.getType(), bizKnowledgeDocumentEntity.getCharCount().intValue());
String currentStatus = bizKnowledgeDocumentEntity.getTrainStatus(); String currentStatus = bizKnowledgeDocumentEntity.getTrainStatus();
if (KnowledgeConstant.TrainStatus.COMPLETE.equals(currentStatus) || if (KnowledgeConstant.TrainStatus.COMPLETE.equals(currentStatus) ||
KnowledgeConstant.TrainStatus.LINE.equals(currentStatus) || KnowledgeConstant.TrainStatus.LINE.equals(currentStatus) ||
...@@ -173,30 +185,42 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -173,30 +185,42 @@ public class KnowledgeServiceImpl implements KnowledgeService {
} }
bizKnowledgeDocumentEntity.setTrainStatus(KnowledgeConstant.TrainStatus.LINE); bizKnowledgeDocumentEntity.setTrainStatus(KnowledgeConstant.TrainStatus.LINE);
bizKnowledgeDocumentEntity.setSegmentationConfig(segmentationConfig);
bizKnowledgeDocumentService.update(kdId, bizKnowledgeDocumentEntity); bizKnowledgeDocumentService.update(kdId, bizKnowledgeDocumentEntity);
TrainKnowledgeMessage message = new TrainKnowledgeMessage(); TrainKnowledgeMessage message = new TrainKnowledgeMessage();
message.setKid(kdId); message.setKid(kdId);
message.setFileUrl(bizKnowledgeDocumentEntity.getDocumentUrl()); message.setFileUrl(bizKnowledgeDocumentEntity.getDocumentUrl());
// message.setReduced(reduced); message.setSegmentationConfig(segmentationConfig);
message.setKnowledgeInfoId(knowledgeInfoId);
knowledgeProducerService.trainKnowledge(message); knowledgeProducerService.trainKnowledge(message);
}
if (StringUtils.isNotBlank(knowledgeInfoEntity.getKdIds())) {
List<Integer> kdIdList = JsonUtils.deSerialize(knowledgeInfoEntity.getKdIds(), new TypeReference<List<Integer>>() {
}.getType());
kdIds.addAll(kdIdList);
} }
knowledgeInfoEntity.setKdIds(JsonUtils.serialize(kdIds));
knowledgeInfoEntity.setId(knowledgeInfoId);
knowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.TRAINING);
knowledgeInfoEntity.setKdIds(JsonUtils.serialize(kdIds));
bizKnowledgeInfoService.update(knowledgeInfoEntity);
return true; return true;
} }
@Override @Override
public List<BizKnowledgeDocumentEntity> getList(String search, String trainStatus, PagingInfo pagingInfo) throws Exception { public List<BizKnowledgeDocumentEntity> searchDocuments(String search, String trainStatus, List<Integer> kdIds, String memberId, PagingInfo pagingInfo) {
List<BizKnowledgeDocumentEntity> result = new ArrayList<>(); List<BizKnowledgeDocumentEntity> result = new ArrayList<>();
String memberId = BlContext.getCurrentUser().getUserId().toString(); List<KnowledgeQueryItem> knowledgeQueryItems = bizKnowledgeDocumentService.searchKnowledge(search, trainStatus, memberId, null, kdIds, pagingInfo);
if (StringUtils.isBlank(memberId)) {
memberId = BlContext.getCurrentUserNotException().getUserId().toString();
}
List<KnowledgeQueryItem> knowledgeQueryItems = bizKnowledgeDocumentService.searchKnowledge(search, trainStatus, memberId, null, pagingInfo);
if (CollectionUtils.isNotEmpty(knowledgeQueryItems)) { if (CollectionUtils.isNotEmpty(knowledgeQueryItems)) {
result = knowledgeQueryItems.stream().map(item -> { result = knowledgeQueryItems.stream().map(item -> {
BizKnowledgeDocumentEntity entity = new BizKnowledgeDocumentEntity(); BizKnowledgeDocumentEntity entity = new BizKnowledgeDocumentEntity();
BeanUtil.copyProperties(item, entity); BeanUtil.copyProperties(item, entity);
if (StringUtils.isNotBlank(item.getSegmentationConfig())) {
SegmentationConfigRequest segmentationConfigRequest = JsonUtils.deSerialize(item.getSegmentationConfig(), SegmentationConfigRequest.class);
entity.setSegmentationConfig(segmentationConfigRequest);
}
return entity; return entity;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
...@@ -209,8 +233,80 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -209,8 +233,80 @@ public class KnowledgeServiceImpl implements KnowledgeService {
List<BizKnowledgeDocumentEntity> res = new ArrayList<>(); List<BizKnowledgeDocumentEntity> res = new ArrayList<>();
for (Integer kdId : kdIds) { for (Integer kdId : kdIds) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId); BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (bizKnowledgeDocumentEntity == null) {
continue;
}
res.add(bizKnowledgeDocumentEntity); res.add(bizKnowledgeDocumentEntity);
} }
return res; return res;
} }
@Override
public GetKnowledgeChunkInfoResult getChunkInfo(List<Integer> kdIds, PagingInfo pagingInfo) {
List<String> knowledgeIds = new ArrayList<>();
for (Integer kdId : kdIds) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId();
knowledgeIds.add(knowledgeId);
}
return demandKnowledgeService.getKnowledgeChunkInfos(knowledgeIds, pagingInfo);
}
@Override
public void openKnowledgeChunk(Integer kdId, String chunkRelationId, String isOpen) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (bizKnowledgeDocumentEntity == null) {
throw new BusinessException("The knowledge does not exist");
}
String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId();
demandKnowledgeService.openKnowledgeChunk(knowledgeId, chunkRelationId, isOpen);
}
@Override
public void deleteKnowledgeChunk(Integer kdId, String chunkRelationId) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (bizKnowledgeDocumentEntity == null) {
throw new BusinessException("The knowledge does not exist");
}
String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId();
demandKnowledgeService.deleteKnowledgeChunk(knowledgeId, chunkRelationId);
}
@Override
public void updateKnowledgeChunkDoc(Integer kdId, String chunkRelationId, String content) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (bizKnowledgeDocumentEntity == null) {
throw new BusinessException("The knowledge does not exist");
}
String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId();
demandKnowledgeService.updateKnowledgeChunkDoc(knowledgeId, chunkRelationId, content);
}
@Override
public void addKnowledgeChunk(Integer kdId, String content, Integer chunkSort) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (bizKnowledgeDocumentEntity == null) {
throw new BusinessException("The knowledge does not exist");
}
String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId();
demandKnowledgeService.addKnowledgeChunk(knowledgeId, content, chunkSort);
}
@Override
public List<Integer> getKdIdsByKnowledgeInfoIds(String[] knowledgeInfoIds) throws Exception {
//获取知识库配置
List<Integer> kdIdList = new ArrayList<>();
if (ArrayUtils.isNotEmpty(knowledgeInfoIds)) {
for (String knowledgeId : knowledgeInfoIds) {
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(Integer.valueOf(knowledgeId));
if (bizKnowledgeInfoEntity == null || org.apache.commons.lang3.StringUtils.isBlank(bizKnowledgeInfoEntity.getKdIds())) {
continue;
}
List<Integer> kdIds = JsonUtils.deSerialize(bizKnowledgeInfoEntity.getKdIds(), new TypeReference<List<Integer>>() {
}.getType());
kdIdList.addAll(kdIds);
}
}
return kdIdList;
}
} }
package cn.com.poc.knowledge.convert;
import cn.com.poc.knowledge.model.BizKnowledgeInfoModel;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.dto.BizKnowledgeInfoDto;
public class BizKnowledgeInfoConvert {
public static BizKnowledgeInfoEntity modelToEntity(BizKnowledgeInfoModel model) {
BizKnowledgeInfoEntity entity = new BizKnowledgeInfoEntity();
entity.setId(model.getId());
entity.setKnowledgeName(model.getKnowledgeName());
entity.setMemberId(model.getMemberId());
entity.setKdIds(model.getKdIds());
entity.setTrainStatus(model.getTrainStatus());
entity.setKnowledgeDesc(model.getKnowledgeDesc());
entity.setIsOpen(model.getIsOpen());
entity.setIsDeleted(model.getIsDeleted());
entity.setCreator(model.getCreator());
entity.setCreatedTime(model.getCreatedTime());
entity.setModifier(model.getModifier());
entity.setModifiedTime(model.getModifiedTime());
entity.setSysVersion(model.getSysVersion());
return entity;
}
public static BizKnowledgeInfoModel entityToModel(BizKnowledgeInfoEntity entity) {
BizKnowledgeInfoModel model = new BizKnowledgeInfoModel();
model.setId(entity.getId());
model.setKnowledgeName(entity.getKnowledgeName());
model.setMemberId(entity.getMemberId());
model.setKdIds(entity.getKdIds());
model.setTrainStatus(entity.getTrainStatus());
model.setKnowledgeDesc(entity.getKnowledgeDesc());
model.setIsOpen(entity.getIsOpen());
model.setIsDeleted(entity.getIsDeleted());
model.setCreator(entity.getCreator());
model.setCreatedTime(entity.getCreatedTime());
model.setModifier(entity.getModifier());
model.setModifiedTime(entity.getModifiedTime());
model.setSysVersion(entity.getSysVersion());
return model;
}
public static BizKnowledgeInfoDto entityToDto(BizKnowledgeInfoEntity entity) {
BizKnowledgeInfoDto dto = new BizKnowledgeInfoDto();
dto.setId(entity.getId());
dto.setKnowledgeName(entity.getKnowledgeName());
dto.setMemberId(entity.getMemberId());
dto.setIsOpen(entity.getIsOpen());
dto.setKdIds(entity.getKdIds());
dto.setTrainStatus(entity.getTrainStatus());
dto.setDesc(entity.getKnowledgeDesc());
dto.setModifiedTime(entity.getModifiedTime());
return dto;
}
public static BizKnowledgeInfoEntity dtoToEntity(BizKnowledgeInfoDto dto) {
BizKnowledgeInfoEntity entity = new BizKnowledgeInfoEntity();
entity.setId(dto.getId());
entity.setKnowledgeName(dto.getKnowledgeName());
entity.setMemberId(dto.getMemberId());
entity.setKdIds(dto.getKdIds());
entity.setIsOpen(dto.getIsOpen());
entity.setTrainStatus(dto.getTrainStatus());
entity.setKnowledgeDesc(dto.getDesc());
return entity;
}
}
\ No newline at end of file
package cn.com.poc.knowledge.convert; package cn.com.poc.knowledge.convert;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.model.BizKnowledgeDocumentModel; import cn.com.poc.knowledge.model.BizKnowledgeDocumentModel;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
public class KnowledgeDocumentConvert { public class KnowledgeDocumentConvert {
...@@ -16,7 +19,12 @@ public class KnowledgeDocumentConvert { ...@@ -16,7 +19,12 @@ public class KnowledgeDocumentConvert {
bizKnowledgeDocumentEntity.setCharCount(model.getCharCount()); bizKnowledgeDocumentEntity.setCharCount(model.getCharCount());
bizKnowledgeDocumentEntity.setUploadTime(model.getUploadTime()); bizKnowledgeDocumentEntity.setUploadTime(model.getUploadTime());
bizKnowledgeDocumentEntity.setIsEnable(model.getIsEnable()); bizKnowledgeDocumentEntity.setIsEnable(model.getIsEnable());
if (StringUtils.isNotBlank(model.getSegmentationConfig())) {
SegmentationConfigRequest segmentationConfigRequest = JsonUtils.deSerialize(model.getSegmentationConfig(), SegmentationConfigRequest.class);
bizKnowledgeDocumentEntity.setSegmentationConfig(segmentationConfigRequest);
}
bizKnowledgeDocumentEntity.setKnowledgeId(model.getKnowledgeId()); bizKnowledgeDocumentEntity.setKnowledgeId(model.getKnowledgeId());
bizKnowledgeDocumentEntity.setDocumentSize(model.getDocumentSize());
bizKnowledgeDocumentEntity.setTrainStatus(model.getTrainStatus()); bizKnowledgeDocumentEntity.setTrainStatus(model.getTrainStatus());
bizKnowledgeDocumentEntity.setIsDeleted(model.getIsDeleted()); bizKnowledgeDocumentEntity.setIsDeleted(model.getIsDeleted());
bizKnowledgeDocumentEntity.setCreator(model.getCreator()); bizKnowledgeDocumentEntity.setCreator(model.getCreator());
...@@ -36,7 +44,9 @@ public class KnowledgeDocumentConvert { ...@@ -36,7 +44,9 @@ public class KnowledgeDocumentConvert {
bizKnowledgeDocumentModel.setDocumentUrl(entity.getDocumentUrl()); bizKnowledgeDocumentModel.setDocumentUrl(entity.getDocumentUrl());
bizKnowledgeDocumentModel.setCharCount(entity.getCharCount()); bizKnowledgeDocumentModel.setCharCount(entity.getCharCount());
bizKnowledgeDocumentModel.setUploadTime(entity.getUploadTime()); bizKnowledgeDocumentModel.setUploadTime(entity.getUploadTime());
bizKnowledgeDocumentModel.setDocumentSize(entity.getDocumentSize());
bizKnowledgeDocumentModel.setIsEnable(entity.getIsEnable()); bizKnowledgeDocumentModel.setIsEnable(entity.getIsEnable());
bizKnowledgeDocumentModel.setSegmentationConfig(JsonUtils.serialize(entity.getSegmentationConfig()));
bizKnowledgeDocumentModel.setKnowledgeId(entity.getKnowledgeId()); bizKnowledgeDocumentModel.setKnowledgeId(entity.getKnowledgeId());
bizKnowledgeDocumentModel.setTrainStatus(entity.getTrainStatus()); bizKnowledgeDocumentModel.setTrainStatus(entity.getTrainStatus());
bizKnowledgeDocumentModel.setIsDeleted(entity.getIsDeleted()); bizKnowledgeDocumentModel.setIsDeleted(entity.getIsDeleted());
......
package cn.com.poc.knowledge.dto; package cn.com.poc.knowledge.dto;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
/** /**
* Model class for biz_knowledge_document * Model class for biz_knowledge_document
* 知识库文件表 * 知识库文件表
...@@ -7,10 +9,10 @@ package cn.com.poc.knowledge.dto; ...@@ -7,10 +9,10 @@ package cn.com.poc.knowledge.dto;
public class BizKnowledgeDocumentDto { public class BizKnowledgeDocumentDto {
/**
/** kd_id * kd_id
*主键 * 主键
*/ */
private Integer kdId; private Integer kdId;
public Integer getKdId() { public Integer getKdId() {
...@@ -21,130 +23,162 @@ public class BizKnowledgeDocumentDto { ...@@ -21,130 +23,162 @@ public class BizKnowledgeDocumentDto {
this.kdId = kdId; this.kdId = kdId;
} }
/** owner /**
*拥有者:System-系统 、User-用户 * owner
*/ * 拥有者:System-系统 、User-用户
*/
private String owner; private String owner;
public String getOwner(){ public String getOwner() {
return this.owner; return this.owner;
} }
public void setOwner(String owner){ public void setOwner(String owner) {
this.owner = owner; this.owner = owner;
} }
/** knowledge_type /**
*知识库类型 QA-问答、Base-基础 * knowledge_type
*/ * 知识库类型 QA-问答、Base-基础
*/
private String knowledgeType; private String knowledgeType;
public String getKnowledgeType(){ public String getKnowledgeType() {
return this.knowledgeType; return this.knowledgeType;
} }
public void setKnowledgeType(String knowledgeType){ public void setKnowledgeType(String knowledgeType) {
this.knowledgeType = knowledgeType; this.knowledgeType = knowledgeType;
} }
/** document_name /**
*文档名 * document_name
*/ * 文档名
*/
private String documentName; private String documentName;
public String getDocumentName(){ public String getDocumentName() {
return this.documentName; return this.documentName;
} }
public void setDocumentName(String documentName){ public void setDocumentName(String documentName) {
this.documentName = documentName; this.documentName = documentName;
} }
/** document_url /**
*文件下载地址 * document_url
*/ * 文件下载地址
*/
private String documentUrl; private String documentUrl;
public String getDocumentUrl(){ public String getDocumentUrl() {
return this.documentUrl; return this.documentUrl;
} }
public void setDocumentUrl(String documentUrl){ public void setDocumentUrl(String documentUrl) {
this.documentUrl = documentUrl; this.documentUrl = documentUrl;
} }
/**
/** char_count * documentSize
*文档字符数 */
*/ private String documentSize;
public String getDocumentSize() {
return documentSize;
}
public void setDocumentSize(String documentSize) {
this.documentSize = documentSize;
}
/**
* char_count
* 文档字符数
*/
private Long charCount; private Long charCount;
public Long getCharCount(){ public Long getCharCount() {
return this.charCount; return this.charCount;
} }
public void setCharCount(Long charCount){ public void setCharCount(Long charCount) {
this.charCount = charCount; this.charCount = charCount;
} }
/** upload_time /**
*上传时间 * upload_time
*/ * 上传时间
*/
private java.util.Date uploadTime; private java.util.Date uploadTime;
public java.util.Date getUploadTime(){ public java.util.Date getUploadTime() {
return this.uploadTime; return this.uploadTime;
} }
public void setUploadTime(java.util.Date uploadTime){ public void setUploadTime(java.util.Date uploadTime) {
this.uploadTime = uploadTime; this.uploadTime = uploadTime;
} }
/** is_enable /**
*是否启用 N-不启用 Y-启用 * is_enable
*/ * 是否启用 N-不启用 Y-启用
*/
private String isEnable; private String isEnable;
public String getIsEnable(){ public String getIsEnable() {
return this.isEnable; return this.isEnable;
} }
public void setIsEnable(String isEnable){ public void setIsEnable(String isEnable) {
this.isEnable = isEnable; this.isEnable = isEnable;
} }
/** knowledge_id /**
*中台知识库ID * knowledge_id
*/ * 中台知识库ID
*/
private String knowledgeId; private String knowledgeId;
public String getKnowledgeId(){ public String getKnowledgeId() {
return this.knowledgeId; return this.knowledgeId;
} }
public void setKnowledgeId(String knowledgeId){ public void setKnowledgeId(String knowledgeId) {
this.knowledgeId = knowledgeId; this.knowledgeId = knowledgeId;
} }
/** train_status /**
*状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail * train_status
*/ * 状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail
*/
private String trainStatus; private String trainStatus;
public String getTrainStatus(){ public String getTrainStatus() {
return this.trainStatus; return this.trainStatus;
} }
public void setTrainStatus(String trainStatus){ public void setTrainStatus(String trainStatus) {
this.trainStatus = trainStatus; this.trainStatus = trainStatus;
} }
/**
* 分片规则
*/
private SegmentationConfigRequest segmentationConfig;
public SegmentationConfigRequest getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(SegmentationConfigRequest segmentationConfig) {
this.segmentationConfig = segmentationConfig;
}
} }
\ No newline at end of file
package cn.com.poc.knowledge.dto;
import javax.persistence.Column;
public class BizKnowledgeInfoDto {
/**
* id
*/
private java.lang.Integer id;
public java.lang.Integer getId() {
return this.id;
}
public void setId(java.lang.Integer id) {
this.id = id;
}
/**
* knowledge_name
* 知识库名字
*/
private java.lang.String knowledgeName;
public java.lang.String getKnowledgeName() {
return this.knowledgeName;
}
public void setKnowledgeName(java.lang.String knowledgeName) {
this.knowledgeName = knowledgeName;
}
/**
* member_id
* 用户ID
*/
private java.lang.String memberId;
public java.lang.String getMemberId() {
return this.memberId;
}
public void setMemberId(java.lang.String memberId) {
this.memberId = memberId;
}
/**
* kd_ids
* 关联的文件ID
*/
private java.lang.String kdIds;
public java.lang.String getKdIds() {
return this.kdIds;
}
public void setKdIds(java.lang.String kdIds) {
this.kdIds = kdIds;
}
/**
* train_status
* 状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail
*/
private java.lang.String trainStatus;
public java.lang.String getTrainStatus() {
return this.trainStatus;
}
public void setTrainStatus(java.lang.String trainStatus) {
this.trainStatus = trainStatus;
}
/**
* desc
*/
private java.lang.String desc;
public java.lang.String getDesc() {
return this.desc;
}
public void setDesc(java.lang.String desc) {
this.desc = desc;
}
/**
* isOpen
*/
private java.lang.String isOpen;
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
/**
* MODIFIED_TIME
* MODIFIED_TIME
*/
private java.util.Date modifiedTime;
@Column(name = "MODIFIED_TIME")
public java.util.Date getModifiedTime() {
return this.modifiedTime;
}
public void setModifiedTime(java.util.Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
}
\ No newline at end of file
package cn.com.poc.knowledge.dto;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
import java.io.Serializable;
import java.util.List;
public class TrainKnowledgeDto implements Serializable {
private Integer knowledgeInfoId;
private List<Integer> kdIds;
private SegmentationConfigRequest segmentationConfig;
public Integer getKnowledgeInfoId() {
return knowledgeInfoId;
}
public void setKnowledgeInfoId(Integer knowledgeInfoId) {
this.knowledgeInfoId = knowledgeInfoId;
}
public List<Integer> getKdIds() {
return kdIds;
}
public void setKdIds(List<Integer> kdIds) {
this.kdIds = kdIds;
}
public SegmentationConfigRequest getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(SegmentationConfigRequest segmentationConfig) {
this.segmentationConfig = segmentationConfig;
}
}
package cn.com.poc.knowledge.dto;
import cn.com.poc.support.dgTools.request.AbstractRequest;
import cn.com.poc.support.dgTools.result.AbstractResult;
import java.io.Serializable;
public class UpsertChunkInfoDto extends AbstractRequest<AbstractResult> implements Serializable {
/**
* 知识库ID
*/
private Integer kdId;
/**
* 大小块关联ID
*/
private String chunkRelationId;
/**
* 分片内容
*/
private String chunkContent;
/**
* 分片是否开启
*/
private String isOpen;
/**
* 分片排序
*/
private Integer chunkSort;
public Integer getKdId() {
return kdId;
}
public void setKdId(Integer kdId) {
this.kdId = kdId;
}
public String getChunkRelationId() {
return chunkRelationId;
}
public void setChunkRelationId(String chunkRelationId) {
this.chunkRelationId = chunkRelationId;
}
public String getChunkContent() {
return chunkContent;
}
public void setChunkContent(String chunkContent) {
this.chunkContent = chunkContent;
}
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
public Integer getChunkSort() {
return chunkSort;
}
public void setChunkSort(Integer chunkSort) {
this.chunkSort = chunkSort;
}
@Override
public String getMethod() throws Exception {
return null;
}
}
package cn.com.poc.knowledge.entity; package cn.com.poc.knowledge.entity;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
import javax.persistence.Column;
/** /**
* Model class for biz_knowledge_document * Model class for biz_knowledge_document
* 知识库文件表 * 知识库文件表
...@@ -145,8 +149,34 @@ public class BizKnowledgeDocumentEntity{ ...@@ -145,8 +149,34 @@ public class BizKnowledgeDocumentEntity{
public void setTrainStatus(String trainStatus){ public void setTrainStatus(String trainStatus){
this.trainStatus = trainStatus; this.trainStatus = trainStatus;
} }
/**
* 文档大小【单位:字节】
*/
private Long documentSize;
public Long getDocumentSize() {
return documentSize;
}
public void setDocumentSize(Long documentSize) {
this.documentSize = documentSize;
}
/**
* 分片规则
*/
private SegmentationConfigRequest segmentationConfig;
public SegmentationConfigRequest getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(SegmentationConfigRequest segmentationConfig) {
this.segmentationConfig = segmentationConfig;
}
/** is_deleted /** is_deleted
*是否删除 Y 是 N 否 *是否删除 Y 是 N 否
*/ */
......
package cn.com.poc.knowledge.entity;
public class BizKnowledgeInfoEntity {
private static final long serialVersionUID = 1L;
/** id
*
*/
private java.lang.Integer id;
public java.lang.Integer getId(){
return this.id;
}
public void setId(java.lang.Integer id){
this.id = id;
}
/** knowledge_name
*知识库名字
*/
private java.lang.String knowledgeName;
public java.lang.String getKnowledgeName(){
return this.knowledgeName;
}
public void setKnowledgeName(java.lang.String knowledgeName){
this.knowledgeName = knowledgeName;
}
/** member_id
*用户ID
*/
private java.lang.String memberId;
public java.lang.String getMemberId(){
return this.memberId;
}
public void setMemberId(java.lang.String memberId){
this.memberId = memberId;
}
/** kd_ids
*关联的文件ID
*/
private java.lang.String kdIds;
public java.lang.String getKdIds(){
return this.kdIds;
}
public void setKdIds(java.lang.String kdIds){
this.kdIds = kdIds;
}
/** train_status
*状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail
*/
private java.lang.String trainStatus;
public java.lang.String getTrainStatus(){
return this.trainStatus;
}
public void setTrainStatus(java.lang.String trainStatus){
this.trainStatus = trainStatus;
}
/** knowledgeDesc
*
*/
private java.lang.String knowledgeDesc;
public String getKnowledgeDesc() {
return knowledgeDesc;
}
public void setKnowledgeDesc(String knowledgeDesc) {
this.knowledgeDesc = knowledgeDesc;
}
/**
* is_open
*/
private String isOpen;
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
/** is_deleted
*是否删除 Y 是 N 否
*/
private java.lang.String isDeleted;
public java.lang.String getIsDeleted(){
return this.isDeleted;
}
public void setIsDeleted(java.lang.String isDeleted){
this.isDeleted = isDeleted;
}
/** CREATOR
*创建人
*/
private java.lang.String creator;
public java.lang.String getCreator(){
return this.creator;
}
public void setCreator(java.lang.String creator){
this.creator = creator;
}
/** CREATED_TIME
*创建时间
*/
private java.util.Date createdTime;
public java.util.Date getCreatedTime(){
return this.createdTime;
}
public void setCreatedTime(java.util.Date createdTime){
this.createdTime = createdTime;
}
/** MODIFIER
*修改人
*/
private java.lang.String modifier;
public java.lang.String getModifier(){
return this.modifier;
}
public void setModifier(java.lang.String modifier){
this.modifier = modifier;
}
/** MODIFIED_TIME
*修改时间
*/
private java.util.Date modifiedTime;
public java.util.Date getModifiedTime(){
return this.modifiedTime;
}
public void setModifiedTime(java.util.Date modifiedTime){
this.modifiedTime = modifiedTime;
}
/** SYS_VERSION
*乐观锁,版本号
*/
private java.lang.Integer sysVersion;
public java.lang.Integer getSysVersion(){
return this.sysVersion;
}
public void setSysVersion(java.lang.Integer sysVersion){
this.sysVersion = sysVersion;
}
}
\ No newline at end of file
...@@ -18,264 +18,309 @@ import java.io.Serializable; ...@@ -18,264 +18,309 @@ import java.io.Serializable;
public class BizKnowledgeDocumentModel extends BaseModelClass implements Serializable { public class BizKnowledgeDocumentModel extends BaseModelClass implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** kd_id /**
*主键 * kd_id
*/ * 主键
*/
private Integer kdId; private Integer kdId;
@Column(name = "kd_id",length = 10) @Column(name = "kd_id", length = 10)
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Id
public Integer getKdId(){ @GeneratedValue(strategy = GenerationType.AUTO)
public Integer getKdId() {
return this.kdId; return this.kdId;
} }
public void setKdId(Integer kdId){ public void setKdId(Integer kdId) {
this.kdId = kdId; this.kdId = kdId;
super.addValidField("kdId"); super.addValidField("kdId");
} }
/** owner /**
*拥有者:System-系统 、User-用户 * owner
*/ * 拥有者:System-系统 、User-用户
*/
private String owner; private String owner;
@Column(name = "owner",length = 10) @Column(name = "owner", length = 10)
public String getOwner(){ public String getOwner() {
return this.owner; return this.owner;
} }
public void setOwner(String owner){ public void setOwner(String owner) {
this.owner = owner; this.owner = owner;
super.addValidField("owner"); super.addValidField("owner");
} }
/** knowledge_type /**
*知识库类型 QA-问答、Base-基础 * knowledge_type
*/ * 知识库类型 QA-问答、Base-基础
*/
private String knowledgeType; private String knowledgeType;
@Column(name = "knowledge_type",length = 10) @Column(name = "knowledge_type", length = 10)
public String getKnowledgeType(){ public String getKnowledgeType() {
return this.knowledgeType; return this.knowledgeType;
} }
public void setKnowledgeType(String knowledgeType){ public void setKnowledgeType(String knowledgeType) {
this.knowledgeType = knowledgeType; this.knowledgeType = knowledgeType;
super.addValidField("knowledgeType"); super.addValidField("knowledgeType");
} }
/** document_name /**
*文档名 * document_name
*/ * 文档名
*/
private String documentName; private String documentName;
@Column(name = "document_name",length = 100) @Column(name = "document_name", length = 100)
public String getDocumentName(){ public String getDocumentName() {
return this.documentName; return this.documentName;
} }
public void setDocumentName(String documentName){ public void setDocumentName(String documentName) {
this.documentName = documentName; this.documentName = documentName;
super.addValidField("documentName"); super.addValidField("documentName");
} }
/** document_url /**
*文件下载地址 * document_url
*/ * 文件下载地址
*/
private String documentUrl; private String documentUrl;
@Column(name = "document_url",length = 225) @Column(name = "document_url", length = 225)
public String getDocumentUrl(){ public String getDocumentUrl() {
return this.documentUrl; return this.documentUrl;
} }
public void setDocumentUrl(String documentUrl){ public void setDocumentUrl(String documentUrl) {
this.documentUrl = documentUrl; this.documentUrl = documentUrl;
super.addValidField("documentUrl"); super.addValidField("documentUrl");
} }
/** char_count /**
*文档字符数 * char_count
*/ * 文档字符数
*/
private Long charCount; private Long charCount;
@Column(name = "char_count",length = 19) @Column(name = "char_count", length = 19)
public Long getCharCount(){ public Long getCharCount() {
return this.charCount; return this.charCount;
} }
public void setCharCount(Long charCount){ public void setCharCount(Long charCount) {
this.charCount = charCount; this.charCount = charCount;
super.addValidField("charCount"); super.addValidField("charCount");
} }
/** upload_time /**
*上传时间 * upload_time
*/ * 上传时间
*/
private java.util.Date uploadTime; private java.util.Date uploadTime;
@Column(name = "upload_time",length = 19) @Column(name = "upload_time", length = 19)
public java.util.Date getUploadTime(){ public java.util.Date getUploadTime() {
return this.uploadTime; return this.uploadTime;
} }
public void setUploadTime(java.util.Date uploadTime){ public void setUploadTime(java.util.Date uploadTime) {
this.uploadTime = uploadTime; this.uploadTime = uploadTime;
super.addValidField("uploadTime"); super.addValidField("uploadTime");
} }
/**
/** is_enable * 分片规则
*是否启用 N-不启用 Y-启用 */
*/ private String segmentationConfig;
@Column(name = "segmentation_config", length = 1073741824)
public String getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(String segmentationConfig) {
this.segmentationConfig = segmentationConfig;
super.addValidField("segmentationConfig");
}
/**
* is_enable
* 是否启用 N-不启用 Y-启用
*/
private String isEnable; private String isEnable;
@Column(name = "is_enable",length = 1) @Column(name = "is_enable", length = 1)
public String getIsEnable(){ public String getIsEnable() {
return this.isEnable; return this.isEnable;
} }
public void setIsEnable(String isEnable){ public void setIsEnable(String isEnable) {
this.isEnable = isEnable; this.isEnable = isEnable;
super.addValidField("isEnable"); super.addValidField("isEnable");
} }
/** knowledge_id /**
*中台知识库ID * knowledge_id
*/ * 中台知识库ID
*/
private String knowledgeId; private String knowledgeId;
@Column(name = "knowledge_id",length = 225) @Column(name = "knowledge_id", length = 225)
public String getKnowledgeId(){ public String getKnowledgeId() {
return this.knowledgeId; return this.knowledgeId;
} }
public void setKnowledgeId(String knowledgeId){ public void setKnowledgeId(String knowledgeId) {
this.knowledgeId = knowledgeId; this.knowledgeId = knowledgeId;
super.addValidField("knowledgeId"); super.addValidField("knowledgeId");
} }
/**
/** train_status * 文档大小【单位:字节】
*状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail */
*/ private Long documentSize;
@Column(name = "document_size", length = 19)
public Long getDocumentSize() {
return documentSize;
}
public void setDocumentSize(Long documentSize) {
this.documentSize = documentSize;
super.addValidField("documentSize");
}
/**
* train_status
* 状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail
*/
private String trainStatus; private String trainStatus;
@Column(name = "train_status",length = 15) @Column(name = "train_status", length = 15)
public String getTrainStatus(){ public String getTrainStatus() {
return this.trainStatus; return this.trainStatus;
} }
public void setTrainStatus(String trainStatus){ public void setTrainStatus(String trainStatus) {
this.trainStatus = trainStatus; this.trainStatus = trainStatus;
super.addValidField("trainStatus"); super.addValidField("trainStatus");
} }
/** is_deleted /**
*是否删除 Y 是 N 否 * is_deleted
*/ * 是否删除 Y 是 N 否
*/
private String isDeleted; private String isDeleted;
@Column(name = "is_deleted",length = 1) @Column(name = "is_deleted", length = 1)
public String getIsDeleted(){ public String getIsDeleted() {
return this.isDeleted; return this.isDeleted;
} }
public void setIsDeleted(String isDeleted){ public void setIsDeleted(String isDeleted) {
this.isDeleted = isDeleted; this.isDeleted = isDeleted;
super.addValidField("isDeleted"); super.addValidField("isDeleted");
} }
/** CREATOR /**
*创建人 * CREATOR
*/ * 创建人
*/
private String creator; private String creator;
@Column(name = "CREATOR",length = 50) @Column(name = "CREATOR", length = 50)
public String getCreator(){ public String getCreator() {
return this.creator; return this.creator;
} }
public void setCreator(String creator){ public void setCreator(String creator) {
this.creator = creator; this.creator = creator;
super.addValidField("creator"); super.addValidField("creator");
} }
/** CREATED_TIME /**
*创建时间 * CREATED_TIME
*/ * 创建时间
*/
private java.util.Date createdTime; private java.util.Date createdTime;
@Column(name = "CREATED_TIME",length = 19) @Column(name = "CREATED_TIME", length = 19)
public java.util.Date getCreatedTime(){ public java.util.Date getCreatedTime() {
return this.createdTime; return this.createdTime;
} }
public void setCreatedTime(java.util.Date createdTime){ public void setCreatedTime(java.util.Date createdTime) {
this.createdTime = createdTime; this.createdTime = createdTime;
super.addValidField("createdTime"); super.addValidField("createdTime");
} }
/** MODIFIER /**
*修改人 * MODIFIER
*/ * 修改人
*/
private String modifier; private String modifier;
@Column(name = "MODIFIER",length = 50) @Column(name = "MODIFIER", length = 50)
public String getModifier(){ public String getModifier() {
return this.modifier; return this.modifier;
} }
public void setModifier(String modifier){ public void setModifier(String modifier) {
this.modifier = modifier; this.modifier = modifier;
super.addValidField("modifier"); super.addValidField("modifier");
} }
/** MODIFIED_TIME /**
*修改时间 * MODIFIED_TIME
*/ * 修改时间
*/
private java.util.Date modifiedTime; private java.util.Date modifiedTime;
@Column(name = "MODIFIED_TIME",length = 19) @Column(name = "MODIFIED_TIME", length = 19)
public java.util.Date getModifiedTime(){ public java.util.Date getModifiedTime() {
return this.modifiedTime; return this.modifiedTime;
} }
public void setModifiedTime(java.util.Date modifiedTime){ public void setModifiedTime(java.util.Date modifiedTime) {
this.modifiedTime = modifiedTime; this.modifiedTime = modifiedTime;
super.addValidField("modifiedTime"); super.addValidField("modifiedTime");
} }
/** SYS_VERSION /**
*乐观锁,版本号 * SYS_VERSION
*/ * 乐观锁,版本号
*/
private Integer sysVersion; private Integer sysVersion;
@Column(name = "SYS_VERSION",length = 10) @Column(name = "SYS_VERSION", length = 10)
@Version @Version
public Integer getSysVersion(){ public Integer getSysVersion() {
return this.sysVersion; return this.sysVersion;
} }
public void setSysVersion(Integer sysVersion){ public void setSysVersion(Integer sysVersion) {
this.sysVersion = sysVersion; this.sysVersion = sysVersion;
super.addValidField("sysVersion"); super.addValidField("sysVersion");
} }
} }
\ No newline at end of file
package cn.com.poc.knowledge.model;
import java.io.Serializable;
import cn.com.yict.framemax.data.model.BaseModelClass;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Version;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
/**
* Model class for biz_knowledge_info
* 知识库信息配置
*/
@Entity
@Table(name = "biz_knowledge_info")
@DynamicInsert
@DynamicUpdate
public class BizKnowledgeInfoModel extends BaseModelClass implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private java.lang.Integer id;
@Column(name = "id", length = 10)
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public java.lang.Integer getId() {
return this.id;
}
public void setId(java.lang.Integer id) {
this.id = id;
super.addValidField("id");
}
/**
* knowledge_name
* 知识库名字
*/
private java.lang.String knowledgeName;
@Column(name = "knowledge_name", length = 100)
public java.lang.String getKnowledgeName() {
return this.knowledgeName;
}
public void setKnowledgeName(java.lang.String knowledgeName) {
this.knowledgeName = knowledgeName;
super.addValidField("knowledgeName");
}
/**
* member_id
* 用户ID
*/
private java.lang.String memberId;
@Column(name = "member_id", length = 100)
public java.lang.String getMemberId() {
return this.memberId;
}
public void setMemberId(java.lang.String memberId) {
this.memberId = memberId;
super.addValidField("memberId");
}
/**
* kd_ids
* 关联的文件ID
*/
private java.lang.String kdIds;
@Column(name = "kd_ids", length = 1073741824)
public java.lang.String getKdIds() {
return this.kdIds;
}
public void setKdIds(java.lang.String kdIds) {
this.kdIds = kdIds;
super.addValidField("kdIds");
}
/**
* train_status
* 状态:未执行-Unopened、 排队-Line 、训练中-Training、 完成-Complete、失败-Fail
*/
private java.lang.String trainStatus;
@Column(name = "train_status", length = 15)
public java.lang.String getTrainStatus() {
return this.trainStatus;
}
public void setTrainStatus(java.lang.String trainStatus) {
this.trainStatus = trainStatus;
super.addValidField("trainStatus");
}
/**
* knowledge_desc
*/
private java.lang.String knowledgeDesc;
@Column(name = "knowledge_desc", length = 500)
public java.lang.String getKnowledgeDesc() {
return this.knowledgeDesc;
}
public void setKnowledgeDesc(java.lang.String knowledgeDesc) {
this.knowledgeDesc = knowledgeDesc;
super.addValidField("knowledgeDesc");
}
/**
* is_open
* 是否开启 Y 是 N 否
*/
private java.lang.String isOpen;
@Column(name = "is_open", length = 1)
public java.lang.String getIsOpen() {
return this.isOpen;
}
public void setIsOpen(java.lang.String isOpen) {
this.isOpen = isOpen;
super.addValidField("isOpen");
}
/**
* is_deleted
* 是否删除 Y 是 N 否
*/
private java.lang.String isDeleted;
@Column(name = "is_deleted", length = 1)
public java.lang.String getIsDeleted() {
return this.isDeleted;
}
public void setIsDeleted(java.lang.String isDeleted) {
this.isDeleted = isDeleted;
super.addValidField("isDeleted");
}
/**
* CREATOR
* 创建人
*/
private java.lang.String creator;
@Column(name = "CREATOR", length = 50)
public java.lang.String getCreator() {
return this.creator;
}
public void setCreator(java.lang.String creator) {
this.creator = creator;
super.addValidField("creator");
}
/**
* CREATED_TIME
* 创建时间
*/
private java.util.Date createdTime;
@Column(name = "CREATED_TIME", length = 19)
public java.util.Date getCreatedTime() {
return this.createdTime;
}
public void setCreatedTime(java.util.Date createdTime) {
this.createdTime = createdTime;
super.addValidField("createdTime");
}
/**
* MODIFIER
* 修改人
*/
private java.lang.String modifier;
@Column(name = "MODIFIER", length = 50)
public java.lang.String getModifier() {
return this.modifier;
}
public void setModifier(java.lang.String modifier) {
this.modifier = modifier;
super.addValidField("modifier");
}
/**
* MODIFIED_TIME
* 修改时间
*/
private java.util.Date modifiedTime;
@Column(name = "MODIFIED_TIME", length = 19)
public java.util.Date getModifiedTime() {
return this.modifiedTime;
}
public void setModifiedTime(java.util.Date modifiedTime) {
this.modifiedTime = modifiedTime;
super.addValidField("modifiedTime");
}
/**
* SYS_VERSION
* 乐观锁,版本号
*/
private java.lang.Integer sysVersion;
@Column(name = "SYS_VERSION", length = 10)
@Version
public java.lang.Integer getSysVersion() {
return this.sysVersion;
}
public void setSysVersion(java.lang.Integer sysVersion) {
this.sysVersion = sysVersion;
super.addValidField("sysVersion");
}
}
\ No newline at end of file
select
id,
knowledge_name,
member_id,
kd_ids,
train_status,
knowledge_desc,
is_open,
is_deleted,
CREATOR,
CREATED_TIME,
MODIFIER,
MODIFIED_TIME
from
biz_knowledge_info
where
is_deleted = 'N'
<< and member_id = :memberId>>
<< and LOCATE(:query ,knowledge_name) >>
<< and train_status = :trainStatus>>
order by MODIFIED_TIME
\ No newline at end of file
package cn.com.poc.knowledge.query;
import java.io.Serializable;
/**
* Query Condition class for KnowledgeInfosQuery
*/
public class KnowledgeInfosQueryCondition implements Serializable{
private static final long serialVersionUID = 1L;
private java.lang.String memberId;
public java.lang.String getMemberId(){
return this.memberId;
}
public void setMemberId(java.lang.String memberId){
this.memberId = memberId;
}
private java.lang.String query;
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
private java.lang.String trainStatus;
public java.lang.String getTrainStatus(){
return this.trainStatus;
}
public void setTrainStatus(java.lang.String trainStatus){
this.trainStatus = trainStatus;
}
}
\ No newline at end of file
package cn.com.poc.knowledge.query;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import cn.com.yict.framemax.data.model.BaseItemClass;
/**
* Query Item class for KnowledgeInfosQuery
*/
@Entity
public class KnowledgeInfosQueryItem extends BaseItemClass implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
* id
*/
private java.lang.Integer id;
@Column(name = "id")
public java.lang.Integer getId() {
return this.id;
}
public void setId(java.lang.Integer id) {
this.id = id;
}
/**
* knowledge_name
* knowledge_name
*/
private java.lang.String knowledgeName;
@Column(name = "knowledge_name")
public java.lang.String getKnowledgeName() {
return this.knowledgeName;
}
public void setKnowledgeName(java.lang.String knowledgeName) {
this.knowledgeName = knowledgeName;
}
/**
* member_id
* member_id
*/
private java.lang.String memberId;
@Column(name = "member_id")
public java.lang.String getMemberId() {
return this.memberId;
}
public void setMemberId(java.lang.String memberId) {
this.memberId = memberId;
}
/**
* kd_ids
* kd_ids
*/
private java.lang.String kdIds;
@Column(name = "kd_ids")
public java.lang.String getKdIds() {
return this.kdIds;
}
public void setKdIds(java.lang.String kdIds) {
this.kdIds = kdIds;
}
/**
* train_status
* train_status
*/
private java.lang.String trainStatus;
@Column(name = "train_status")
public java.lang.String getTrainStatus() {
return this.trainStatus;
}
public void setTrainStatus(java.lang.String trainStatus) {
this.trainStatus = trainStatus;
}
/**
* knowledge_desc
* knowledge_desc
*/
private java.lang.String knowledgeDesc;
@Column(name = "knowledge_desc")
public java.lang.String getKnowledgeDesc() {
return this.knowledgeDesc;
}
public void setKnowledgeDesc(java.lang.String knowledgeDesc) {
this.knowledgeDesc = knowledgeDesc;
}
/**
* is_open
*/
private java.lang.String isOpen;
@Column(name = "is_open")
public java.lang.String getIsOpen() {
return isOpen;
}
public void setIsOpen(java.lang.String isOpen) {
this.isOpen = isOpen;
}
/**
* is_deleted
* is_deleted
*/
private java.lang.String isDeleted;
@Column(name = "is_deleted")
public java.lang.String getIsDeleted() {
return this.isDeleted;
}
public void setIsDeleted(java.lang.String isDeleted) {
this.isDeleted = isDeleted;
}
/**
* CREATOR
* CREATOR
*/
private java.lang.String creator;
@Column(name = "CREATOR")
public java.lang.String getCreator() {
return this.creator;
}
public void setCreator(java.lang.String creator) {
this.creator = creator;
}
/**
* CREATED_TIME
* CREATED_TIME
*/
private java.util.Date createdTime;
@Column(name = "CREATED_TIME")
public java.util.Date getCreatedTime() {
return this.createdTime;
}
public void setCreatedTime(java.util.Date createdTime) {
this.createdTime = createdTime;
}
/**
* MODIFIER
* MODIFIER
*/
private java.lang.String modifier;
@Column(name = "MODIFIER")
public java.lang.String getModifier() {
return this.modifier;
}
public void setModifier(java.lang.String modifier) {
this.modifier = modifier;
}
/**
* MODIFIED_TIME
* MODIFIED_TIME
*/
private java.util.Date modifiedTime;
@Column(name = "MODIFIED_TIME")
public java.util.Date getModifiedTime() {
return this.modifiedTime;
}
public void setModifiedTime(java.util.Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
}
\ No newline at end of file
...@@ -5,6 +5,8 @@ select ...@@ -5,6 +5,8 @@ select
bkd.document_name, bkd.document_name,
bkd.document_url, bkd.document_url,
bkd.char_count, bkd.char_count,
bkd.segmentation_config,
bkd.document_size,
bkd.upload_time, bkd.upload_time,
bkd.is_enable, bkd.is_enable,
bkd.knowledge_id, bkd.knowledge_id,
...@@ -17,4 +19,5 @@ where bkd.is_deleted = 'N' ...@@ -17,4 +19,5 @@ where bkd.is_deleted = 'N'
<<and bkd.document_name = :documentName>> <<and bkd.document_name = :documentName>>
<<and bkd.train_status =:trainStatus>> <<and bkd.train_status =:trainStatus>>
<<and locate(:searchDocumentName,bkd.document_name) >> <<and locate(:searchDocumentName,bkd.document_name) >>
<<and bkd.kd_id in (:kdIds)>>
order by bkd.upload_time desc order by bkd.upload_time desc
\ No newline at end of file
package cn.com.poc.knowledge.query; package cn.com.poc.knowledge.query;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* Query Condition class for KnowledgeQuery * Query Condition class for KnowledgeQuery
...@@ -50,4 +51,14 @@ public class KnowledgeQueryCondition implements Serializable{ ...@@ -50,4 +51,14 @@ public class KnowledgeQueryCondition implements Serializable{
public void setSearchDocumentName(String searchDocumentName) { public void setSearchDocumentName(String searchDocumentName) {
this.searchDocumentName = searchDocumentName; this.searchDocumentName = searchDocumentName;
} }
private List<Integer> kdIds;
public List<Integer> getKdIds() {
return kdIds;
}
public void setKdIds(List<Integer> kdIds) {
this.kdIds = kdIds;
}
} }
\ No newline at end of file
...@@ -10,148 +10,183 @@ import java.io.Serializable; ...@@ -10,148 +10,183 @@ import java.io.Serializable;
* Query Item class for KnowledgeQuery * Query Item class for KnowledgeQuery
*/ */
@Entity @Entity
public class KnowledgeQueryItem extends BaseItemClass implements Serializable{ public class KnowledgeQueryItem extends BaseItemClass implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** kd_id /**
*kd_id * kd_id
*/ * kd_id
*/
private Integer kdId; private Integer kdId;
@Column(name = "kd_id") @Column(name = "kd_id")
public Integer getKdId(){ public Integer getKdId() {
return this.kdId; return this.kdId;
} }
public void setKdId(Integer kdId){ public void setKdId(Integer kdId) {
this.kdId = kdId; this.kdId = kdId;
} }
/** owner /**
*owner * owner
*/ * owner
*/
private String owner; private String owner;
@Column(name = "owner") @Column(name = "owner")
public String getOwner(){ public String getOwner() {
return this.owner; return this.owner;
} }
public void setOwner(String owner){ public void setOwner(String owner) {
this.owner = owner; this.owner = owner;
} }
/** knowledge_type /**
*knowledge_type * knowledge_type
*/ * knowledge_type
*/
private String knowledgeType; private String knowledgeType;
@Column(name = "knowledge_type") @Column(name = "knowledge_type")
public String getKnowledgeType(){ public String getKnowledgeType() {
return this.knowledgeType; return this.knowledgeType;
} }
public void setKnowledgeType(String knowledgeType){ public void setKnowledgeType(String knowledgeType) {
this.knowledgeType = knowledgeType; this.knowledgeType = knowledgeType;
} }
/** document_name /**
*document_name * document_name
*/ * document_name
*/
private String documentName; private String documentName;
@Column(name = "document_name") @Column(name = "document_name")
public String getDocumentName(){ public String getDocumentName() {
return this.documentName; return this.documentName;
} }
public void setDocumentName(String documentName){ public void setDocumentName(String documentName) {
this.documentName = documentName; this.documentName = documentName;
} }
/** document_url /**
*document_url * document_url
*/ * document_url
*/
private String documentUrl; private String documentUrl;
@Column(name = "document_url") @Column(name = "document_url")
public String getDocumentUrl(){ public String getDocumentUrl() {
return this.documentUrl; return this.documentUrl;
} }
public void setDocumentUrl(String documentUrl){ public void setDocumentUrl(String documentUrl) {
this.documentUrl = documentUrl; this.documentUrl = documentUrl;
} }
/** char_count /**
*char_count * char_count
*/ * char_count
*/
private Long charCount; private Long charCount;
@Column(name = "char_count") @Column(name = "char_count")
public Long getCharCount(){ public Long getCharCount() {
return this.charCount; return this.charCount;
} }
public void setCharCount(Long charCount){ public void setCharCount(Long charCount) {
this.charCount = charCount; this.charCount = charCount;
} }
/** upload_time /**
*upload_time * document_size
*/ */
private Long documentSize;
@Column(name = "document_size")
public Long getDocumentSize() {
return this.documentSize;
}
public void setDocumentSize(Long documentSize) {
this.documentSize = documentSize;
}
/**
* upload_time
* upload_time
*/
private java.util.Date uploadTime; private java.util.Date uploadTime;
@Column(name = "upload_time") @Column(name = "upload_time")
public java.util.Date getUploadTime(){ public java.util.Date getUploadTime() {
return this.uploadTime; return this.uploadTime;
} }
public void setUploadTime(java.util.Date uploadTime){ public void setUploadTime(java.util.Date uploadTime) {
this.uploadTime = uploadTime; this.uploadTime = uploadTime;
} }
/** is_enable private String segmentationConfig;
*is_enable
*/ @Column(name = "segmentation_config")
public String getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(String segmentationConfig) {
this.segmentationConfig = segmentationConfig;
}
/**
* is_enable
* is_enable
*/
private String isEnable; private String isEnable;
@Column(name = "is_enable") @Column(name = "is_enable")
public String getIsEnable(){ public String getIsEnable() {
return this.isEnable; return this.isEnable;
} }
public void setIsEnable(String isEnable){ public void setIsEnable(String isEnable) {
this.isEnable = isEnable; this.isEnable = isEnable;
} }
/** knowledge_id /**
*knowledge_id * knowledge_id
*/ * knowledge_id
*/
private String knowledgeId; private String knowledgeId;
@Column(name = "knowledge_id") @Column(name = "knowledge_id")
public String getKnowledgeId(){ public String getKnowledgeId() {
return this.knowledgeId; return this.knowledgeId;
} }
public void setKnowledgeId(String knowledgeId){ public void setKnowledgeId(String knowledgeId) {
this.knowledgeId = knowledgeId; this.knowledgeId = knowledgeId;
} }
/** train_status /**
*train_status * train_status
*/ * train_status
*/
private String trainStatus; private String trainStatus;
@Column(name = "train_status") @Column(name = "train_status")
public String getTrainStatus(){ public String getTrainStatus() {
return this.trainStatus; return this.trainStatus;
} }
public void setTrainStatus(String trainStatus){ public void setTrainStatus(String trainStatus) {
this.trainStatus = trainStatus; this.trainStatus = trainStatus;
} }
} }
\ No newline at end of file
package cn.com.poc.knowledge.repository;
import cn.com.yict.framemax.data.repository.Repository;
import cn.com.poc.knowledge.model.BizKnowledgeInfoModel;
public interface BizKnowledgeInfoRepository extends Repository<BizKnowledgeInfoModel,java.lang.Integer> {
}
\ No newline at end of file
package cn.com.poc.knowledge.rest; package cn.com.poc.knowledge.rest;
import cn.com.poc.knowledge.dto.BizKnowledgeDocumentDto; import cn.com.poc.knowledge.dto.BizKnowledgeDocumentDto;
import cn.com.poc.knowledge.dto.BizKnowledgeInfoDto;
import cn.com.poc.knowledge.dto.TrainKnowledgeDto;
import cn.com.poc.knowledge.dto.UpsertChunkInfoDto;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.GetKnowledgeChunkInfoResult;
import cn.com.yict.framemax.core.rest.BaseRest; import cn.com.yict.framemax.core.rest.BaseRest;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import cn.com.yict.framemax.web.permission.Access; import cn.com.yict.framemax.web.permission.Access;
...@@ -14,7 +18,6 @@ import java.util.List; ...@@ -14,7 +18,6 @@ import java.util.List;
@Permission(Access.Safety) @Permission(Access.Safety)
public interface KnowledgeRest extends BaseRest { public interface KnowledgeRest extends BaseRest {
/** /**
* 上传文档 * 上传文档
* *
...@@ -26,10 +29,20 @@ public interface KnowledgeRest extends BaseRest { ...@@ -26,10 +29,20 @@ public interface KnowledgeRest extends BaseRest {
/** /**
* 删除文档 * 删除文档
* *
* @param kdId 主键ID * @param knowledgeInfoId 知识库ID
* @param kdId 文档ID
* @return 是否成功
*/
Boolean delDocument(@RequestParam Integer knowledgeInfoId, @RequestParam Integer kdId);
/**
* 批量删除文档
*
* @param knowledgeInfoId
* @param kdId 主键ID
* @return 是否成功 * @return 是否成功
*/ */
Boolean delDocument(@RequestParam Integer kdId); Boolean batchDelDocument(@RequestParam Integer knowledgeInfoId, @RequestBody List<Integer> kdId);
/** /**
...@@ -39,24 +52,33 @@ public interface KnowledgeRest extends BaseRest { ...@@ -39,24 +52,33 @@ public interface KnowledgeRest extends BaseRest {
/** /**
* 启用 / 关闭 * 启用 / 关闭
*
* @
*/ */
String enableKnowledge(@RequestParam Integer kdId) throws Exception; String enableKnowledge(@RequestParam Integer kdId) throws Exception;
/** /**
* 开启训练 * 开启训练
*/ */
Boolean trainKnowledge(@RequestBody List<Integer> kdIds) throws Exception; Boolean trainKnowledge(@RequestBody TrainKnowledgeDto dto) throws Exception;
/** /**
* 获取用户知识库 * 模糊查询知识库文档
*/ */
List<BizKnowledgeDocumentDto> getList(@RequestParam(required = false) String search, @RequestParam(required = false) String trainStatus, PagingInfo pagingInfo) throws Exception; List<BizKnowledgeDocumentDto> searchDocuments(@RequestParam(required = false) String search,
@RequestParam(required = false) String trainStatus,
@RequestParam Integer knowledgeInfoId,
PagingInfo pagingInfo) throws Exception;
/**
* 获取知识库的文档列表
*
* @param knowledgeInfoId
* @return
* @throws Exception
*/
List<BizKnowledgeDocumentDto> getKdIdsByKnowledgeInfoId(@RequestParam Integer knowledgeInfoId) throws Exception;
/** /**
* 获取知识库 * 获取知识库的文档列表
* *
* @param kdIds * @param kdIds
* @return * @return
...@@ -64,5 +86,61 @@ public interface KnowledgeRest extends BaseRest { ...@@ -64,5 +86,61 @@ public interface KnowledgeRest extends BaseRest {
*/ */
List<BizKnowledgeDocumentDto> getListByKdIds(@RequestBody List<Integer> kdIds); List<BizKnowledgeDocumentDto> getListByKdIds(@RequestBody List<Integer> kdIds);
/**
* 获取知识库详情
*/
BizKnowledgeInfoDto getKnowledgeDetail(@RequestParam Integer knowledgeInfoId) throws Exception;
/**
* 获取用户知识库列表
*
* @param search 搜索条件
* @param trainStatus 训练状态
*/
List<BizKnowledgeInfoDto> getKnowledgeList(@RequestParam(required = false) String search, @RequestParam(required = false) String trainStatus, PagingInfo pagingInfo) throws Exception;
/**
* 创建知识库
*/
BizKnowledgeInfoDto createKnowledge(@RequestBody BizKnowledgeInfoDto dto) throws Exception;
/**
* 更新知识库
*/
BizKnowledgeInfoDto updateKnowledgeInfo(@RequestBody BizKnowledgeInfoDto dto) throws Exception;
/**
* 开启关闭知识库
*/
void enableKnowledgeInfo(@RequestParam Integer knowledgeInfoId, @RequestParam String isOpen) throws Exception;
/**
* 删除知识库
*/
void deleteKnowledgeInfo(@RequestParam Integer knowledgeInfoId) throws Exception;
/**
* 开关知识库分片
*/
void openKnowledgeChunk(@RequestBody UpsertChunkInfoDto dto);
/**
* 删除知识库分片
*/
void deleteKnowledgeChunk(@RequestBody UpsertChunkInfoDto dto);
/**
* 更新知识库分片内容
*/
void updateKnowledgeChunkDoc(@RequestBody UpsertChunkInfoDto dto);
/**
* 新增知识库分片
*/
void addKnowledgeChunk(@RequestBody UpsertChunkInfoDto dto);
/**
* 获取知识库分片信息
*/
GetKnowledgeChunkInfoResult getChunks(@RequestParam List<Integer> kdIds, PagingInfo pagingInfo);
} }
package cn.com.poc.knowledge.rest.impl; package cn.com.poc.knowledge.rest.impl;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.FileUtils;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.convert.BizKnowledgeInfoConvert;
import cn.com.poc.knowledge.dto.BizKnowledgeDocumentDto; import cn.com.poc.knowledge.dto.BizKnowledgeDocumentDto;
import cn.com.poc.knowledge.dto.BizKnowledgeInfoDto;
import cn.com.poc.knowledge.dto.TrainKnowledgeDto;
import cn.com.poc.knowledge.dto.UpsertChunkInfoDto;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem;
import cn.com.poc.knowledge.rest.KnowledgeRest; import cn.com.poc.knowledge.rest.KnowledgeRest;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.GetKnowledgeChunkInfoResult;
import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.TypeReference;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -22,50 +40,89 @@ public class KnowledgeRestImpl implements KnowledgeRest { ...@@ -22,50 +40,89 @@ public class KnowledgeRestImpl implements KnowledgeRest {
@Resource @Resource
private KnowledgeService knowledgeService; private KnowledgeService knowledgeService;
@Resource
private BizKnowledgeInfoService bizKnowledgeInfoService;
@Override @Override
public List<BizKnowledgeDocumentDto> uploadDocument(MultipartFile[] documentFiles) throws Exception { public List<BizKnowledgeDocumentDto> uploadDocument(MultipartFile[] documentFiles) throws Exception {
Assert.notEmpty(documentFiles); Assert.notEmpty(documentFiles);
Assert.isTrue(documentFiles.length <= 5, "Uploaded files can be no larger than five"); Assert.isTrue(documentFiles.length <= 5, "Uploaded files can be no larger than five");
List<BizKnowledgeDocumentDto> result = new ArrayList<>();
List<BizKnowledgeDocumentEntity> entities = knowledgeService.uploadDocument(documentFiles); List<BizKnowledgeDocumentEntity> entities = knowledgeService.uploadDocument(documentFiles);
result = entities.stream().map(entity -> { List<BizKnowledgeDocumentDto> result = entities.stream().map(entity -> {
BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto(); BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto();
BeanUtil.copyProperties(entity, dto); BeanUtil.copyProperties(entity, dto);
dto.setDocumentSize(FileUtils.formatFileSize(entity.getDocumentSize()));
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return result; return result;
} }
@Override @Override
public Boolean delDocument(Integer kdId) { public Boolean delDocument(Integer knowledgeInfoId, Integer kdId) {
return knowledgeService.delDocument(kdId); Assert.notNull(knowledgeInfoId);
Assert.notNull(kdId);
return knowledgeService.delDocument(knowledgeInfoId, kdId);
}
@Override
public Boolean batchDelDocument(Integer knowledgeInfoId, List<Integer> kdId) {
Assert.notEmpty(kdId);
Assert.notNull(knowledgeInfoId);
boolean result = true;
for (Integer id : kdId) {
result = result && knowledgeService.delDocument(knowledgeInfoId, id);
}
return result;
} }
@Override @Override
public Boolean renameDocument(Integer kdId, String rename) throws Exception { public Boolean renameDocument(Integer kdId, String rename) throws Exception {
Assert.notNull(kdId);
Assert.notEmpty(rename);
return knowledgeService.renameDocument(kdId, rename); return knowledgeService.renameDocument(kdId, rename);
} }
@Override @Override
public String enableKnowledge(Integer kdId) throws Exception { public String enableKnowledge(Integer kdId) throws Exception {
Assert.notNull(kdId);
return knowledgeService.enableKnowledge(kdId); return knowledgeService.enableKnowledge(kdId);
} }
@Override @Override
public Boolean trainKnowledge(List<Integer> kdIds) throws Exception { public Boolean trainKnowledge(TrainKnowledgeDto dto) throws Exception {
//执行任务 Assert.notNull(dto);
knowledgeService.trainKnowledge(kdIds); Assert.notNull(dto.getKnowledgeInfoId());
return true; Assert.notNull(dto.getKdIds());
Assert.notNull(dto.getSegmentationConfig());
return knowledgeService.trainKnowledge(dto.getKnowledgeInfoId(), dto.getKdIds(), dto.getSegmentationConfig());
} }
@Override @Override
public List<BizKnowledgeDocumentDto> getList(String search,String trainStatus, PagingInfo pagingInfo) throws Exception { public List<BizKnowledgeDocumentDto> searchDocuments(String search, String trainStatus, Integer knowledgeInfoId, PagingInfo pagingInfo) throws Exception {
Assert.notNull(knowledgeInfoId);
List<BizKnowledgeDocumentDto> result = new ArrayList<>(); List<BizKnowledgeDocumentDto> result = new ArrayList<>();
List<BizKnowledgeDocumentEntity> entities = knowledgeService.getList(search, trainStatus, pagingInfo); BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(knowledgeInfoId);
if (bizKnowledgeInfoEntity == null) {
throw new BusinessException("知识库不存在");
}
String kdIds = bizKnowledgeInfoEntity.getKdIds();
if (StringUtils.isBlank(kdIds)) {
return result;
}
List<Integer> kdIdList = JsonUtils.deSerialize(kdIds, new TypeReference<List<Integer>>() {
}.getType());
if (CollectionUtils.isEmpty(kdIdList)) {
return result;
}
UserBaseEntity currentUser = BlContext.getCurrentUserNotException();
List<BizKnowledgeDocumentEntity> entities = knowledgeService.searchDocuments(search, trainStatus, kdIdList, currentUser.getUserId().toString(), pagingInfo);
if (CollectionUtils.isNotEmpty(entities)) { if (CollectionUtils.isNotEmpty(entities)) {
result = entities.stream().map(entity -> { result = entities.stream().map(entity -> {
BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto(); BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto();
BeanUtil.copyProperties(entity, dto); BeanUtil.copyProperties(entity, dto);
dto.setDocumentSize(FileUtils.formatFileSize(entity.getDocumentSize()));
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
...@@ -73,17 +130,156 @@ public class KnowledgeRestImpl implements KnowledgeRest { ...@@ -73,17 +130,156 @@ public class KnowledgeRestImpl implements KnowledgeRest {
} }
@Override @Override
public List<BizKnowledgeDocumentDto> getListByKdIds(List<Integer> kdIds) { public List<BizKnowledgeDocumentDto> getKdIdsByKnowledgeInfoId(Integer knowledgeInfoId) throws Exception {
Assert.notNull(knowledgeInfoId);
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(knowledgeInfoId);
if (bizKnowledgeInfoEntity == null) {
throw new BusinessException("知识库不存在");
}
List<BizKnowledgeDocumentDto> res = new ArrayList<>(); List<BizKnowledgeDocumentDto> res = new ArrayList<>();
String kdIds = bizKnowledgeInfoEntity.getKdIds();
if (StringUtils.isNotBlank(kdIds)) {
List<Integer> kdIdList = JsonUtils.deSerialize(kdIds, new TypeReference<List<Integer>>() {
}.getType());
if (CollectionUtils.isEmpty(kdIdList)) {
return res;
}
List<BizKnowledgeDocumentEntity> entities = knowledgeService.getListByKdIds(kdIdList);
if (CollectionUtils.isNotEmpty(entities)) {
res = entities.stream().map(entity -> {
BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto();
BeanUtil.copyProperties(entity, dto);
dto.setDocumentSize(FileUtils.formatFileSize(entity.getDocumentSize()));
return dto;
}).collect(Collectors.toList());
}
}
return res;
}
@Override
public List<BizKnowledgeDocumentDto> getListByKdIds(List<Integer> kdIds) {
Assert.notEmpty(kdIds); Assert.notEmpty(kdIds);
List<BizKnowledgeDocumentDto> res = new ArrayList<>();
List<BizKnowledgeDocumentEntity> entities = knowledgeService.getListByKdIds(kdIds); List<BizKnowledgeDocumentEntity> entities = knowledgeService.getListByKdIds(kdIds);
if (CollectionUtils.isNotEmpty(entities)) { if (CollectionUtils.isNotEmpty(entities)) {
res = entities.stream().map(entity -> { res = entities.stream().map(entity -> {
BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto(); BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto();
BeanUtil.copyProperties(entity, dto); BeanUtil.copyProperties(entity, dto);
dto.setDocumentSize(FileUtils.formatFileSize(entity.getDocumentSize()));
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
return res; return res;
} }
@Override
public BizKnowledgeInfoDto getKnowledgeDetail(Integer knowledgeInfoId) throws Exception {
Assert.notNull(knowledgeInfoId);
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(knowledgeInfoId);
return BizKnowledgeInfoConvert.entityToDto(bizKnowledgeInfoEntity);
}
@Override
public List<BizKnowledgeInfoDto> getKnowledgeList(String search, String trainStatus, PagingInfo pagingInfo) throws Exception {
List<BizKnowledgeInfoDto> result = new ArrayList<>();
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
KnowledgeInfosQueryCondition condition = new KnowledgeInfosQueryCondition();
condition.setMemberId(userBaseEntity.getUserId().toString());
if (StringUtils.isNoneBlank(search)) {
condition.setQuery(search);
}
if (StringUtils.isNoneBlank(trainStatus)) {
condition.setTrainStatus(trainStatus);
}
List<KnowledgeInfosQueryItem> items = bizKnowledgeInfoService.knowledgeInfos(condition, pagingInfo);
if (CollectionUtils.isNotEmpty(items)) {
result = items.stream().map(item -> {
BizKnowledgeInfoDto dto = new BizKnowledgeInfoDto();
BeanUtil.copyProperties(item, dto);
dto.setDesc(item.getKnowledgeDesc());
return dto;
}).collect(Collectors.toList());
}
return result;
}
@Override
public BizKnowledgeInfoDto createKnowledge(BizKnowledgeInfoDto dto) throws Exception {
Assert.notNull(dto.getKnowledgeName(), "知识库名称不能为空");
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = new BizKnowledgeInfoEntity();
bizKnowledgeInfoEntity.setKnowledgeName(dto.getKnowledgeName());
bizKnowledgeInfoEntity.setMemberId(userBaseEntity.getUserId().toString());
bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.UNOPENED);
bizKnowledgeInfoEntity.setKnowledgeDesc(dto.getDesc());
BizKnowledgeInfoEntity entity = bizKnowledgeInfoService.save(bizKnowledgeInfoEntity);
return BizKnowledgeInfoConvert.entityToDto(entity);
}
@Override
public BizKnowledgeInfoDto updateKnowledgeInfo(BizKnowledgeInfoDto dto) throws Exception {
Assert.notNull(dto.getId());
Assert.notBlank(dto.getKnowledgeName(), "知识库名称不能为空");
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = new BizKnowledgeInfoEntity();
bizKnowledgeInfoEntity.setId(dto.getId());
bizKnowledgeInfoEntity.setKnowledgeName(dto.getKnowledgeName());
bizKnowledgeInfoEntity.setKnowledgeDesc(dto.getDesc());
BizKnowledgeInfoEntity entity = bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
return BizKnowledgeInfoConvert.entityToDto(entity);
}
@Override
public void enableKnowledgeInfo(Integer knowledgeInfoId, String isOpen) throws Exception {
Assert.notNull(knowledgeInfoId);
Assert.notBlank(isOpen);
Assert.isTrue(isOpen.equals(CommonConstant.IsDeleted.N) || isOpen.equals(CommonConstant.IsDeleted.Y), "isOpen must Y or N");
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = new BizKnowledgeInfoEntity();
bizKnowledgeInfoEntity.setId(knowledgeInfoId);
bizKnowledgeInfoEntity.setIsOpen(isOpen);
bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
}
@Override
public void deleteKnowledgeInfo(Integer knowledgeInfoId) throws Exception {
Assert.notNull(knowledgeInfoId);
bizKnowledgeInfoService.deletedById(knowledgeInfoId);
}
@Override
public void openKnowledgeChunk(UpsertChunkInfoDto dto) {
Assert.notNull(dto.getIsOpen());
Assert.notNull(dto.getChunkRelationId());
Assert.notNull(dto.getKdId());
knowledgeService.openKnowledgeChunk(dto.getKdId(), dto.getChunkRelationId(), dto.getIsOpen());
}
@Override
public void deleteKnowledgeChunk(UpsertChunkInfoDto dto) {
Assert.notNull(dto.getKdId());
Assert.notNull(dto.getChunkRelationId());
knowledgeService.deleteKnowledgeChunk(dto.getKdId(), dto.getChunkRelationId());
}
@Override
public void updateKnowledgeChunkDoc(UpsertChunkInfoDto dto) {
Assert.notNull(dto.getChunkContent());
Assert.notNull(dto.getChunkRelationId());
Assert.notNull(dto.getKdId());
knowledgeService.updateKnowledgeChunkDoc(dto.getKdId(), dto.getChunkRelationId(), dto.getChunkContent());
}
@Override
public void addKnowledgeChunk(UpsertChunkInfoDto dto) {
Assert.notNull(dto.getChunkContent());
Assert.notNull(dto.getKdId());
Assert.notNull(dto.getChunkSort());
knowledgeService.addKnowledgeChunk(dto.getKdId(), dto.getChunkContent(), dto.getChunkSort());
}
@Override
public GetKnowledgeChunkInfoResult getChunks(List<Integer> kdIds, PagingInfo pagingInfo) {
Assert.notEmpty(kdIds);
return knowledgeService.getChunkInfo(kdIds, pagingInfo);
}
} }
package cn.com.poc.knowledge.scheduler;
import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.message.entity.KnowledgeTrainStatusMessage;
import cn.com.poc.message.service.KnowledgeProducerService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Component
public class KnowledgeInfoScheduler {
@Resource
private KnowledgeProducerService knowledgeProducerService;
@Resource
private BizKnowledgeInfoService bizKnowledgeInfoService;
@Scheduled(cron = "0 0/1 * * * ?")
public void knowledgeInfoStatusUpdateScheduler() throws Exception {
KnowledgeInfosQueryCondition condition = new KnowledgeInfosQueryCondition();
condition.setTrainStatus(KnowledgeConstant.TrainStatus.TRAINING);
List<KnowledgeInfosQueryItem> items = bizKnowledgeInfoService.knowledgeInfos(condition, null);
for (KnowledgeInfosQueryItem item : items) {
KnowledgeTrainStatusMessage knowledgeTrainStatusMessage = new KnowledgeTrainStatusMessage();
knowledgeTrainStatusMessage.setKnowledgeInfoId(item.getId());
knowledgeProducerService.knowledgeInfoStatusCheck(knowledgeTrainStatusMessage);
}
}
}
...@@ -19,5 +19,5 @@ public interface BizKnowledgeDocumentService extends BaseService { ...@@ -19,5 +19,5 @@ public interface BizKnowledgeDocumentService extends BaseService {
Boolean deleted(Integer kdId); Boolean deleted(Integer kdId);
List<KnowledgeQueryItem> searchKnowledge(String document,String trainStatus, String memberId, String documentName, PagingInfo pagingInfo); List<KnowledgeQueryItem> searchKnowledge(String document, String trainStatus, String memberId, String documentName, List<Integer> kdIds, PagingInfo pagingInfo);
} }
\ No newline at end of file
package cn.com.poc.knowledge.service;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem;
import cn.com.poc.knowledge.query.KnowledgeQueryItem;
import cn.com.yict.framemax.core.service.BaseService;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.Collection;
import java.util.List;
public interface BizKnowledgeInfoService extends BaseService {
BizKnowledgeInfoEntity get(java.lang.Integer id) throws Exception;
List<BizKnowledgeInfoEntity> findByExample(BizKnowledgeInfoEntity example, PagingInfo pagingInfo) throws Exception;
BizKnowledgeInfoEntity save(BizKnowledgeInfoEntity entity) throws Exception;
BizKnowledgeInfoEntity update(BizKnowledgeInfoEntity entity) throws Exception;
void deletedById(java.lang.Integer id) throws Exception;
List<KnowledgeInfosQueryItem> knowledgeInfos(KnowledgeInfosQueryCondition condition, PagingInfo pagingInfo) throws Exception;
void removeDocument(Integer knowledgeInfoId, Integer kdId);
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ package cn.com.poc.knowledge.service.impl; ...@@ -2,6 +2,7 @@ package cn.com.poc.knowledge.service.impl;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.Assert; import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.knowledge.convert.KnowledgeDocumentConvert; import cn.com.poc.knowledge.convert.KnowledgeDocumentConvert;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.model.BizKnowledgeDocumentModel; import cn.com.poc.knowledge.model.BizKnowledgeDocumentModel;
...@@ -64,6 +65,10 @@ public class BizKnowledgeDocumentServiceImpl extends BaseServiceImpl ...@@ -64,6 +65,10 @@ public class BizKnowledgeDocumentServiceImpl extends BaseServiceImpl
BeanUtil.copyProperties(entity, bizKnowledgeDocumentModel, new CopyOptions() {{ BeanUtil.copyProperties(entity, bizKnowledgeDocumentModel, new CopyOptions() {{
setIgnoreNullValue(true); setIgnoreNullValue(true);
}}); }});
if (null != entity.getSegmentationConfig()) {
String config = JsonUtils.serialize(entity.getSegmentationConfig());
bizKnowledgeDocumentModel.setSegmentationConfig(config);
}
BizKnowledgeDocumentModel updateModel = this.repository.save(bizKnowledgeDocumentModel); BizKnowledgeDocumentModel updateModel = this.repository.save(bizKnowledgeDocumentModel);
return KnowledgeDocumentConvert.modelToEntity(updateModel); return KnowledgeDocumentConvert.modelToEntity(updateModel);
} }
...@@ -81,12 +86,13 @@ public class BizKnowledgeDocumentServiceImpl extends BaseServiceImpl ...@@ -81,12 +86,13 @@ public class BizKnowledgeDocumentServiceImpl extends BaseServiceImpl
} }
@Override @Override
public List<KnowledgeQueryItem> searchKnowledge(String searchDocumentName, String trainStatus, String memberId, String documentName, PagingInfo pagingInfo) { public List<KnowledgeQueryItem> searchKnowledge(String searchDocumentName, String trainStatus, String memberId, String documentName, List<Integer> kdIds, PagingInfo pagingInfo) {
KnowledgeQueryCondition condition = new KnowledgeQueryCondition(); KnowledgeQueryCondition condition = new KnowledgeQueryCondition();
condition.setMemberId(memberId); condition.setMemberId(memberId);
condition.setDocumentName(documentName); condition.setDocumentName(documentName);
condition.setTrainStatus(trainStatus); condition.setTrainStatus(trainStatus);
condition.setSearchDocumentName(searchDocumentName); condition.setSearchDocumentName(searchDocumentName);
condition.setKdIds(kdIds);
return this.sqlDao.query(condition, KnowledgeQueryItem.class, pagingInfo); return this.sqlDao.query(condition, KnowledgeQueryItem.class, pagingInfo);
} }
} }
\ No newline at end of file
package cn.com.poc.knowledge.service.impl;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem;
import cn.com.yict.framemax.core.service.impl.BaseServiceImpl;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.knowledge.model.BizKnowledgeInfoModel;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.convert.BizKnowledgeInfoConvert;
import cn.com.poc.knowledge.repository.BizKnowledgeInfoRepository;
import cn.com.yict.framemax.data.model.PagingInfo;
import com.alibaba.fastjson.TypeReference;
import org.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Service;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.util.Assert;
@Service
public class BizKnowledgeInfoServiceImpl extends BaseServiceImpl
implements BizKnowledgeInfoService {
@Resource
private BizKnowledgeInfoRepository repository;
public BizKnowledgeInfoEntity get(java.lang.Integer id) throws Exception {
Assert.notNull(id);
BizKnowledgeInfoModel model = this.repository.get(id);
if (model == null) {
return null;
}
if ("Y".equals(model.getIsDeleted())) {
return null;
}
return BizKnowledgeInfoConvert.modelToEntity(model);
}
public List<BizKnowledgeInfoEntity> findByExample(BizKnowledgeInfoEntity example, PagingInfo pagingInfo) throws Exception {
List<BizKnowledgeInfoEntity> result = new ArrayList<BizKnowledgeInfoEntity>();
BizKnowledgeInfoModel model = new BizKnowledgeInfoModel();
if (example != null) {
model = BizKnowledgeInfoConvert.entityToModel(example);
}
model.setIsDeleted("N");
List<BizKnowledgeInfoModel> models = this.repository.findByExample(model, pagingInfo);
if (CollectionUtils.isNotEmpty(models)) {
result = models.stream().map(BizKnowledgeInfoConvert::modelToEntity).collect(Collectors.toList());
}
return result;
}
public BizKnowledgeInfoEntity save(BizKnowledgeInfoEntity entity) throws Exception {
Assert.notNull(entity);
entity.setId(null);
entity.setIsDeleted("N");
BizKnowledgeInfoModel model = BizKnowledgeInfoConvert.entityToModel(entity);
BizKnowledgeInfoModel saveModel = this.repository.save(model);
return BizKnowledgeInfoConvert.modelToEntity(saveModel);
}
public BizKnowledgeInfoEntity update(BizKnowledgeInfoEntity entity) throws Exception {
Assert.notNull(entity);
Assert.notNull(entity.getId(), "update pk can not be null");
BizKnowledgeInfoModel model = this.repository.get(entity.getId());
if (entity.getKnowledgeName() != null) {
model.setKnowledgeName(entity.getKnowledgeName());
}
if (entity.getMemberId() != null) {
model.setMemberId(entity.getMemberId());
}
if (entity.getKdIds() != null) {
model.setKdIds(entity.getKdIds());
}
if (entity.getTrainStatus() != null) {
model.setTrainStatus(entity.getTrainStatus());
}
if (entity.getKnowledgeDesc() != null) {
model.setKnowledgeDesc(entity.getKnowledgeDesc());
}
if (entity.getIsDeleted() != null) {
model.setIsDeleted(entity.getIsDeleted());
}
if (entity.getIsOpen() != null) {
model.setIsOpen(entity.getIsOpen());
}
if (entity.getSysVersion() != null) {
model.setSysVersion(entity.getSysVersion());
}
BizKnowledgeInfoModel saveModel = this.repository.save(model);
return BizKnowledgeInfoConvert.modelToEntity(saveModel);
}
public void deletedById(java.lang.Integer id) throws Exception {
Assert.notNull(id);
BizKnowledgeInfoModel model = this.repository.get(id);
if (model != null) {
if ("N".equals(model.getIsDeleted())) {
model.setIsDeleted("Y");
this.repository.save(model);
}
}
}
@Override
public List<KnowledgeInfosQueryItem> knowledgeInfos(KnowledgeInfosQueryCondition condition, PagingInfo pagingInfo) throws Exception {
return this.sqlDao.query(condition, KnowledgeInfosQueryItem.class, "MODIFIED_TIME DESC",pagingInfo);
}
@Override
public void removeDocument(Integer knowledgeInfoId, Integer kdId) {
BizKnowledgeInfoModel bizKnowledgeInfoModel = this.repository.get(knowledgeInfoId);
if (bizKnowledgeInfoModel != null) {
String kdIds = bizKnowledgeInfoModel.getKdIds();
if (!StringUtils.isEmpty(kdIds)) {
List<String> kdIdList = JsonUtils.deSerialize(kdIds, new TypeReference<List<String>>() {
}.getType());
kdIdList.remove(kdId.toString());
kdIds = JsonUtils.serialize(kdIdList.stream().map(Integer::valueOf).collect(Collectors.toList()));
bizKnowledgeInfoModel.setKdIds(kdIds);
this.repository.save(bizKnowledgeInfoModel);
}
}
}
}
\ No newline at end of file
...@@ -4,12 +4,22 @@ import java.io.Serializable; ...@@ -4,12 +4,22 @@ import java.io.Serializable;
public class KnowledgeTrainStatusMessage implements Serializable { public class KnowledgeTrainStatusMessage implements Serializable {
private Integer knowledgeInfoId;
private Integer kdId; private Integer kdId;
private String status; private String status;
private String knowledgeId; private String knowledgeId;
public Integer getKnowledgeInfoId() {
return knowledgeInfoId;
}
public void setKnowledgeInfoId(Integer knowledgeInfoId) {
this.knowledgeInfoId = knowledgeInfoId;
}
public String getKnowledgeId() { public String getKnowledgeId() {
return knowledgeId; return knowledgeId;
} }
......
package cn.com.poc.message.entity; package cn.com.poc.message.entity;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
public class TrainKnowledgeMessage implements Serializable { public class TrainKnowledgeMessage implements Serializable {
private Integer knowledgeInfoId;
private Integer kid; private Integer kid;
...@@ -12,6 +15,24 @@ public class TrainKnowledgeMessage implements Serializable { ...@@ -12,6 +15,24 @@ public class TrainKnowledgeMessage implements Serializable {
private Map<Integer, Integer> reduced; private Map<Integer, Integer> reduced;
private SegmentationConfigRequest segmentationConfig;
public Integer getKnowledgeInfoId() {
return knowledgeInfoId;
}
public void setKnowledgeInfoId(Integer knowledgeInfoId) {
this.knowledgeInfoId = knowledgeInfoId;
}
public SegmentationConfigRequest getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(SegmentationConfigRequest segmentationConfig) {
this.segmentationConfig = segmentationConfig;
}
public Map<Integer, Integer> getReduced() { public Map<Integer, Integer> getReduced() {
return reduced; return reduced;
} }
...@@ -42,6 +63,7 @@ public class TrainKnowledgeMessage implements Serializable { ...@@ -42,6 +63,7 @@ public class TrainKnowledgeMessage implements Serializable {
"kid=" + kid + "kid=" + kid +
", fileUrl='" + fileUrl + '\'' + ", fileUrl='" + fileUrl + '\'' +
", reduced=" + reduced + ", reduced=" + reduced +
", segmentationConfig=" + segmentationConfig +
'}'; '}';
} }
} }
...@@ -19,4 +19,10 @@ public interface KnowledgeConsumerService extends BaseService { ...@@ -19,4 +19,10 @@ public interface KnowledgeConsumerService extends BaseService {
* 训练状态更新 * 训练状态更新
*/ */
void trainStatusUpdate(KnowledgeTrainStatusMessage message) throws Exception; void trainStatusUpdate(KnowledgeTrainStatusMessage message) throws Exception;
/**
* 检查知识库信息状态改变
*/
void knowledgeInfoStatusCheck(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage) throws Exception;
} }
...@@ -21,4 +21,10 @@ public interface KnowledgeProducerService extends BaseService { ...@@ -21,4 +21,10 @@ public interface KnowledgeProducerService extends BaseService {
*/ */
KnowledgeTrainStatusMessage trainStatusUpdate(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage); KnowledgeTrainStatusMessage trainStatusUpdate(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage);
/**
* 检查知识库信息状态改变
*/
KnowledgeTrainStatusMessage knowledgeInfoStatusCheck(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage);
} }
...@@ -2,13 +2,15 @@ package cn.com.poc.message.service.impl; ...@@ -2,13 +2,15 @@ package cn.com.poc.message.service.impl;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.knowledge.constant.KnowledgeConstant; import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.entity.BizKnowledgeTrainLogEntity; import cn.com.poc.knowledge.entity.BizKnowledgeTrainLogEntity;
import cn.com.poc.knowledge.entity.BizMemberKnowledgeRelationEntity;
import cn.com.poc.knowledge.service.BizKnowledgeDocumentService; import cn.com.poc.knowledge.service.BizKnowledgeDocumentService;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.knowledge.service.BizKnowledgeTrainLogService; import cn.com.poc.knowledge.service.BizKnowledgeTrainLogService;
import cn.com.poc.knowledge.service.BizMemberKnowledgeRelationService;
import cn.com.poc.message.entity.KnowledgeTrainStatusMessage; import cn.com.poc.message.entity.KnowledgeTrainStatusMessage;
import cn.com.poc.message.entity.TrainKnowledgeMessage; import cn.com.poc.message.entity.TrainKnowledgeMessage;
import cn.com.poc.message.service.KnowledgeConsumerService; import cn.com.poc.message.service.KnowledgeConsumerService;
...@@ -17,13 +19,13 @@ import cn.com.poc.message.topic.KnowledgeTopic; ...@@ -17,13 +19,13 @@ import cn.com.poc.message.topic.KnowledgeTopic;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService; import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.tumbleweed.client.annotation.Consumer; import cn.com.yict.framemax.tumbleweed.client.annotation.Consumer;
import org.apache.commons.collections4.MapUtils; import com.alibaba.fastjson.TypeReference;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.List; import java.util.List;
...@@ -42,16 +44,10 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -42,16 +44,10 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
private DemandKnowledgeService demandKnowledgeService; private DemandKnowledgeService demandKnowledgeService;
@Resource @Resource
private BizMemberKnowledgeRelationService bizMemberKnowledgeRelationService; private KnowledgeProducerService knowledgeProducerService;
// @Resource
// private BizAiGcMemberUsageDetailsService bizAiGcMemberUsageDetailsService;
//
// @Resource
// private AiGcMemberFreqProducerService aiGcMemberFreqProducerService;
@Resource @Resource
private KnowledgeProducerService knowledgeProducerService; private BizKnowledgeInfoService bizKnowledgeInfoService;
/** /**
...@@ -61,15 +57,16 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -61,15 +57,16 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
* @return * @return
*/ */
@Override @Override
@Consumer(topic = KnowledgeTopic.TRAIN_KNOWLEDGE, scale = 5, retry = false) @Consumer(topic = KnowledgeTopic.TRAIN_KNOWLEDGE, scale = 3, retry = true)
public void trainKnowledge(TrainKnowledgeMessage message) throws Exception { public void trainKnowledge(TrainKnowledgeMessage message) throws Exception {
//修改训练状态 //修改训练状态
KnowledgeTrainStatusMessage trainStatusMessage = new KnowledgeTrainStatusMessage(); KnowledgeTrainStatusMessage trainStatusMessage = new KnowledgeTrainStatusMessage();
trainStatusMessage.setStatus(KnowledgeConstant.TrainStatus.TRAINING); trainStatusMessage.setStatus(KnowledgeConstant.TrainStatus.TRAINING);
trainStatusMessage.setKdId(message.getKid()); trainStatusMessage.setKdId(message.getKid());
trainStatusMessage.setKnowledgeInfoId(message.getKnowledgeInfoId());
knowledgeProducerService.trainStatusUpdate(trainStatusMessage); knowledgeProducerService.trainStatusUpdate(trainStatusMessage);
try { try {
String knowledgeId = demandKnowledgeService.trainKnowledge(message.getFileUrl()); String knowledgeId = demandKnowledgeService.trainKnowledge(message.getFileUrl(), message.getSegmentationConfig());
//训练日志 //训练日志
BizKnowledgeTrainLogEntity bizKnowledgeTrainLogEntity = new BizKnowledgeTrainLogEntity(); BizKnowledgeTrainLogEntity bizKnowledgeTrainLogEntity = new BizKnowledgeTrainLogEntity();
...@@ -85,9 +82,8 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -85,9 +82,8 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
completeMessage.setStatus(KnowledgeConstant.TrainStatus.COMPLETE); completeMessage.setStatus(KnowledgeConstant.TrainStatus.COMPLETE);
completeMessage.setKdId(message.getKid()); completeMessage.setKdId(message.getKid());
completeMessage.setKnowledgeId(knowledgeId); completeMessage.setKnowledgeId(knowledgeId);
completeMessage.setKnowledgeInfoId(message.getKnowledgeInfoId());
knowledgeProducerService.trainStatusUpdate(completeMessage); knowledgeProducerService.trainStatusUpdate(completeMessage);
//保存明细
// saveUsageDetailByKnowledgeTrain(message.getKid());
} catch (BusinessException e) { } catch (BusinessException e) {
logger.warn("--------------message:{},知识库训练失败:{}------------", message, e.getMessage()); logger.warn("--------------message:{},知识库训练失败:{}------------", message, e.getMessage());
...@@ -107,14 +103,12 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -107,14 +103,12 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
bizKnowledgeTrainLogService.save(bizKnowledgeTrainLogEntity); bizKnowledgeTrainLogService.save(bizKnowledgeTrainLogEntity);
logger.warn("-------保存知识库训练失败日志----------"); logger.warn("-------保存知识库训练失败日志----------");
//次数回滚
// if (MapUtils.isNotEmpty(message.getReduced())) { BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(message.getKnowledgeInfoId());
// logger.warn("----------知识库训练失败,训练次数回滚【开始】-------------"); bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.FAIL);
// AiGcMemberFreqMessage aiGcMemberFreqMessage = new AiGcMemberFreqMessage(); bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
// aiGcMemberFreqMessage.setReduceMap(message.getReduced()); logger.warn("-------保存知识库训练失败状态----------");
// aiGcMemberFreqProducerService.rollbackNum(aiGcMemberFreqMessage);
// logger.warn("----------知识库训练失败,训练次数回滚【结束】-------------");
// }
} }
} }
...@@ -126,28 +120,38 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -126,28 +120,38 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
bizKnowledgeDocumentEntity.setTrainStatus(message.getStatus()); bizKnowledgeDocumentEntity.setTrainStatus(message.getStatus());
bizKnowledgeDocumentEntity.setKnowledgeId(message.getKnowledgeId()); bizKnowledgeDocumentEntity.setKnowledgeId(message.getKnowledgeId());
bizKnowledgeDocumentService.update(message.getKdId(), bizKnowledgeDocumentEntity); bizKnowledgeDocumentService.update(message.getKdId(), bizKnowledgeDocumentEntity);
knowledgeProducerService.knowledgeInfoStatusCheck(message);
} }
private void saveUsageDetailByKnowledgeTrain(Integer kdId) throws Exception {
BizMemberKnowledgeRelationEntity bizMemberKnowledgeRelationEntity = new BizMemberKnowledgeRelationEntity();
bizMemberKnowledgeRelationEntity.setMemberType("system");
bizMemberKnowledgeRelationEntity.setKdId(kdId);
bizMemberKnowledgeRelationEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizMemberKnowledgeRelationEntity> entities = bizMemberKnowledgeRelationService.findByExample(bizMemberKnowledgeRelationEntity, null);
// BizMemberKnowledgeRelationEntity memberKnowledgeRelationEntity = entities.get(0);
//
// BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
// AiGcMemberUsageDetailsEntity aiGcMemberUsageDetailsEntity = new AiGcMemberUsageDetailsEntity();
// aiGcMemberUsageDetailsEntity.setRelationId(memberKnowledgeRelationEntity.getMemberId());
// aiGcMemberUsageDetailsEntity.setDomain(AiGcPaymentConfigurationConstant.DOMAIN.TRAIN);
// aiGcMemberUsageDetailsEntity.setTitile(bizKnowledgeDocumentEntity.getDocumentName());
// aiGcMemberUsageDetailsEntity.setDate(new Date());
// aiGcMemberUsageDetailsEntity.setScenes(null);
// aiGcMemberUsageDetailsEntity.setDetailType("知识库训练");
// aiGcMemberUsageDetailsEntity.setOperation(AiGcMemberUsageDetailsConstant.Operation.USE);
// aiGcMemberUsageDetailsEntity.setNum(bizKnowledgeDocumentEntity.getCharCount().intValue());
// aiGcMemberUsageDetailsEntity.setIsDeleted(MkpCommonConstant.IsDeleted.N);
// bizAiGcMemberUsageDetailsService.save(aiGcMemberUsageDetailsEntity);
}
@Override
@Consumer(topic = KnowledgeTopic.KNOWLEDGE_INFO_STATUS_CHECK, scale = 3, retry = true)
public void knowledgeInfoStatusCheck(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage) throws Exception {
Assert.notNull(knowledgeTrainStatusMessage.getKnowledgeInfoId());
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(knowledgeTrainStatusMessage.getKnowledgeInfoId());
if (!KnowledgeConstant.TrainStatus.TRAINING.equals(bizKnowledgeInfoEntity.getTrainStatus())) {
return;
}
String kdIds = bizKnowledgeInfoEntity.getKdIds();
List<Integer> kdIdList = JsonUtils.deSerialize(kdIds, new TypeReference<List<Integer>>() {
}.getType());
boolean isAllComplete = true;
logger.info("-------知识库训练状态检查,kdIds:{}-------", kdIds);
for (Integer kdId : kdIdList) {
BizKnowledgeDocumentEntity documentEntity = bizKnowledgeDocumentService.get(kdId);
if (!documentEntity.getTrainStatus().equals(KnowledgeConstant.TrainStatus.COMPLETE)) {
isAllComplete = false;
break;
}
}
if (isAllComplete) {
logger.info("-------知识库训练状态检查,全部完成, knowledgeInfoId:{}-------", knowledgeTrainStatusMessage.getKnowledgeInfoId());
bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.COMPLETE);
bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
}
}
} }
...@@ -31,4 +31,10 @@ public class KnowledgeProducerServiceImpl implements KnowledgeProducerService { ...@@ -31,4 +31,10 @@ public class KnowledgeProducerServiceImpl implements KnowledgeProducerService {
public KnowledgeTrainStatusMessage trainStatusUpdate(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage) { public KnowledgeTrainStatusMessage trainStatusUpdate(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage) {
return knowledgeTrainStatusMessage; return knowledgeTrainStatusMessage;
} }
@Override
@Producer(topic = KnowledgeTopic.KNOWLEDGE_INFO_STATUS_CHECK, publishPoint = PublishPoint.PUBLISH_REAL_TIME)
public KnowledgeTrainStatusMessage knowledgeInfoStatusCheck(KnowledgeTrainStatusMessage knowledgeTrainStatusMessage) {
return knowledgeTrainStatusMessage;
}
} }
...@@ -7,5 +7,7 @@ public interface KnowledgeTopic { ...@@ -7,5 +7,7 @@ public interface KnowledgeTopic {
String TRAIN_STATUS = "TRAIN_STATUS"; String TRAIN_STATUS = "TRAIN_STATUS";
String KNOWLEDGE_INFO_STATUS_CHECK = "KNOWLEDGE_INFO_STATUS_CHECK";
} }
...@@ -11,6 +11,7 @@ import cn.com.poc.support.dgTools.result.AbstractResult; ...@@ -11,6 +11,7 @@ import cn.com.poc.support.dgTools.result.AbstractResult;
import cn.com.poc.support.dgTools.result.DgtoolsApiResult; import cn.com.poc.support.dgTools.result.DgtoolsApiResult;
import cn.com.poc.support.dgTools.utils.AesEncodeUtil; import cn.com.poc.support.dgTools.utils.AesEncodeUtil;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo;
import cn.com.yict.framemax.frame.service.FmxParamConfigService; import cn.com.yict.framemax.frame.service.FmxParamConfigService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -63,6 +64,19 @@ public class DgtoolsAbstractHttpClient { ...@@ -63,6 +64,19 @@ public class DgtoolsAbstractHttpClient {
* @param headers 请求头列表 * @param headers 请求头列表
*/ */
public <T extends AbstractResult> T doRequest(String url, AbstractRequest<T> abstractRequest, List<Header> headers) { public <T extends AbstractResult> T doRequest(String url, AbstractRequest<T> abstractRequest, List<Header> headers) {
return doRequest(url, abstractRequest, headers, null);
}
/**
* 调用中台接口通用请求
* <br/>注:基于fastjson对JSON数据转换
*
* @param url 请求全路径
* @param abstractRequest 请求实体,需要继承响应体泛型的AbstractRequest
* @param headers 请求头列表
* @param pagingInfo 分页信息
*/
public <T extends AbstractResult> T doRequest(String url, AbstractRequest<T> abstractRequest, List<Header> headers, PagingInfo pagingInfo) {
Class<T> responseClass = abstractRequest.getResponseClass(); Class<T> responseClass = abstractRequest.getResponseClass();
...@@ -97,6 +111,11 @@ public class DgtoolsAbstractHttpClient { ...@@ -97,6 +111,11 @@ public class DgtoolsAbstractHttpClient {
post.addHeader(header); post.addHeader(header);
} }
} }
// 配置分页参数
if (pagingInfo != null) {
url = url + "?pageSize=" + pagingInfo.getPageSize() + "&pageNo=" + pagingInfo.getPageNo();
}
HttpUriRequest httpUriRequest = post HttpUriRequest httpUriRequest = post
.setHeader(DgtoolsApiConstants.JSON_HEADER) .setHeader(DgtoolsApiConstants.JSON_HEADER)
.setUri(dgtoolsDomainurl + DgtoolsApiConstants.BASE_URL + url) .setUri(dgtoolsDomainurl + DgtoolsApiConstants.BASE_URL + url)
...@@ -112,6 +131,10 @@ public class DgtoolsAbstractHttpClient { ...@@ -112,6 +131,10 @@ public class DgtoolsAbstractHttpClient {
//调用服务超时 2000毫秒 //调用服务超时 2000毫秒
throw new BusinessException(dgtoolsApiResult.getMessage()); throw new BusinessException(dgtoolsApiResult.getMessage());
} }
if (dgtoolsApiResult.getPagingInfo() != null) {
pagingInfo.setTotalRows(dgtoolsApiResult.getPagingInfo().getTotalRows());
pagingInfo.setPageSize(dgtoolsApiResult.getPagingInfo().getPageSize());
}
return JSON.parseObject(JSON.toJSONString(dgtoolsApiResult.getData()), responseClass); return JSON.parseObject(JSON.toJSONString(dgtoolsApiResult.getData()), responseClass);
} }
......
...@@ -236,11 +236,19 @@ public interface DgtoolsApiConstants { ...@@ -236,11 +236,19 @@ public interface DgtoolsApiConstants {
String BAIDU_HANDWRITING = "aIRest/handWriting.json"; String BAIDU_HANDWRITING = "aIRest/handWriting.json";
/**
* 知识库
*/
String TRAIN_KNOWLEDGE = "knowLedgeRest/trainKnowLedge.json"; String TRAIN_KNOWLEDGE = "knowLedgeRest/trainKnowLedge.json";
String DEL_KNOWLEDGE = "knowLedgeRest/delKnowLedge.json"; String DEL_KNOWLEDGE = "knowLedgeRest/delKnowLedge.json";
String SEARCH_KNOWLEDGE = "knowLedgeRest/searchKnowledge.json"; String SEARCH_KNOWLEDGE = "knowLedgeRest/searchKnowledge.json";
String GET_KNOWLEDGE_CHUNK_INFOS = "/knowLedgeRest/getKnowledgeChunkInfos.json";
String OPEN_KNOWLEDGE_CHUNK = "/knowLedgeRest/openKnowledgeChunk.json";
String DELETE_KNOWLEDGE_CHUNK = "/knowLedgeRest/deleteKnowledgeChunk.json";
String UPDATE_KNOWLEDGE_CHUNK_DOC = "/knowLedgeRest/updateKnowledgeChunkDoc.json";
String ADD_KNOWLEDGE_CHUNK = "/knowLedgeRest/addKnowledgeChunk.json";
/** /**
* 大模型【通用】 * 大模型【通用】
...@@ -248,7 +256,7 @@ public interface DgtoolsApiConstants { ...@@ -248,7 +256,7 @@ public interface DgtoolsApiConstants {
String LARGE_MODEL = "largeModelRest/completion.json"; String LARGE_MODEL = "largeModelRest/completion.json";
} }
interface ClickHouse{ interface ClickHouse {
String WEB_BROWSE_HARVEST_REPORT = "webBrowseHarvest/report.json"; String WEB_BROWSE_HARVEST_REPORT = "webBrowseHarvest/report.json";
} }
......
package cn.com.poc.support.dgTools.result; package cn.com.poc.support.dgTools.result;
import cn.com.poc.support.dgTools.constants.ErrorCodeEnum; import cn.com.poc.support.dgTools.constants.ErrorCodeEnum;
import cn.com.yict.framemax.data.model.PagingInfo;
/** /**
* @author Roger Wu * @author Roger Wu
...@@ -13,6 +14,16 @@ public class DgtoolsApiResult { ...@@ -13,6 +14,16 @@ public class DgtoolsApiResult {
private Object data; private Object data;
private PagingInfo pagingInfo;
public PagingInfo getPagingInfo() {
return pagingInfo;
}
public void setPagingInfo(PagingInfo pagingInfo) {
this.pagingInfo = pagingInfo;
}
public String getCode() { public String getCode() {
return code; return code;
} }
......
package cn.com.poc.thirdparty.resource.demand.ai.aggregate; package cn.com.poc.thirdparty.resource.demand.ai.aggregate;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.GetKnowledgeChunkInfoResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.SegmentationConfigRequest;
import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.List; import java.util.List;
/** /**
...@@ -13,7 +17,7 @@ public interface DemandKnowledgeService { ...@@ -13,7 +17,7 @@ public interface DemandKnowledgeService {
* @param fileURL 训练文档 * @param fileURL 训练文档
* @return 知识库id * @return 知识库id
*/ */
String trainKnowledge(String fileURL); String trainKnowledge(String fileURL, SegmentationConfigRequest segmentationConfig);
/** /**
* 删除知识库 * 删除知识库
...@@ -32,4 +36,47 @@ public interface DemandKnowledgeService { ...@@ -32,4 +36,47 @@ public interface DemandKnowledgeService {
*/ */
List<String> searchKnowledge(String query, List<String> knowledgeIds, Integer topK); List<String> searchKnowledge(String query, List<String> knowledgeIds, Integer topK);
/**
* 获取知识库分片
*
* @param knowledgeIds 知识库id
* @param pagingInfo 分页信息
*/
GetKnowledgeChunkInfoResult getKnowledgeChunkInfos(List<String> knowledgeIds, PagingInfo pagingInfo);
/**
* 开关知识库分片
*
* @param knowledgeId 知识库id
* @param chunkRelationId 分片关系id
* @param isOpen 是否开启 Y/N
*/
void openKnowledgeChunk(String knowledgeId, String chunkRelationId, String isOpen);
/**
* 删除知识库分片
*
* @param knowledgeId 知识库id
* @param chunkRelationId 分片关系id
*/
void deleteKnowledgeChunk(String knowledgeId, String chunkRelationId);
/**
* 更新知识库分片内容
*
* @param knowledgeId 知识库id
* @param chunkRelationId 分片关系id
* @param content 分片内容
*/
void updateKnowledgeChunkDoc(String knowledgeId, String chunkRelationId, String content);
/**
* 新增知识库分片
*
* @param knowledgeId 知识库id
* @param content 分片内容
* @param chunkSort 分片排序
*/
void addKnowledgeChunk(String knowledgeId, String content, Integer chunkSort);
} }
package cn.com.poc.thirdparty.resource.demand.ai.aggregate.impl; package cn.com.poc.thirdparty.resource.demand.ai.aggregate.impl;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.*;
import cn.com.poc.thirdparty.resource.demand.member.service.DemandAuthService;
import cn.com.poc.support.dgTools.DgtoolsAbstractHttpClient; import cn.com.poc.support.dgTools.DgtoolsAbstractHttpClient;
import cn.com.poc.support.dgTools.constants.DgtoolsApiConstants; import cn.com.poc.support.dgTools.constants.DgtoolsApiConstants;
import cn.com.poc.support.dgTools.result.AbstractResult; import cn.com.poc.support.dgTools.result.AbstractResult;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.*;
import cn.com.poc.thirdparty.resource.demand.member.service.DemandAuthService;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.http.Header; import org.apache.http.Header;
...@@ -27,10 +28,11 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService { ...@@ -27,10 +28,11 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService {
private DemandAuthService demandAuthService; private DemandAuthService demandAuthService;
@Override @Override
public String trainKnowledge(String fileURL) { public String trainKnowledge(String fileURL, SegmentationConfigRequest segmentationConfig) {
Assert.notBlank(fileURL); Assert.notBlank(fileURL);
TrainKnowledgeRequest request = new TrainKnowledgeRequest(); TrainKnowledgeRequest request = new TrainKnowledgeRequest();
request.setDocumentUrl(fileURL); request.setDocumentUrl(fileURL);
request.setSegmentationConfig(segmentationConfig);
TrainKnowledgeResult trainKnowledgeResult = dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.TRAIN_KNOWLEDGE, request, getHeaders()); TrainKnowledgeResult trainKnowledgeResult = dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.TRAIN_KNOWLEDGE, request, getHeaders());
if (null == trainKnowledgeResult) { if (null == trainKnowledgeResult) {
throw new BusinessException("train knowledge error"); throw new BusinessException("train knowledge error");
...@@ -51,13 +53,13 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService { ...@@ -51,13 +53,13 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService {
@Override @Override
public List<String> searchKnowledge(String query, List<String> knowledgeIds, Integer topK) { public List<String> searchKnowledge(String query, List<String> knowledgeIds, Integer topK) {
Assert.notBlank(query);
if (CollectionUtils.isEmpty(knowledgeIds)) { if (CollectionUtils.isEmpty(knowledgeIds)) {
return new ArrayList<String>(); return new ArrayList<String>();
} }
if (topK == null) {
Assert.notBlank(query); topK = 3;
Assert.notNull(topK); }
SearchKnowledgeRequest searchKnowledgeRequest = new SearchKnowledgeRequest(); SearchKnowledgeRequest searchKnowledgeRequest = new SearchKnowledgeRequest();
searchKnowledgeRequest.setQuery(query); searchKnowledgeRequest.setQuery(query);
searchKnowledgeRequest.setKnowLedgeIds(knowledgeIds); searchKnowledgeRequest.setKnowLedgeIds(knowledgeIds);
...@@ -69,6 +71,48 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService { ...@@ -69,6 +71,48 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService {
return searchKnowledgeResult.getDocuments(); return searchKnowledgeResult.getDocuments();
} }
@Override
public GetKnowledgeChunkInfoResult getKnowledgeChunkInfos(List<String> knowledgeIds, PagingInfo pagingInfo) {
GetKnowledgeChunkInfoRequest request = new GetKnowledgeChunkInfoRequest();
request.setKnowledgeIds(knowledgeIds);
return dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.GET_KNOWLEDGE_CHUNK_INFOS, request, getHeaders(), pagingInfo);
}
@Override
public void openKnowledgeChunk(String knowledgeId, String chunkRelationId, String isOpen) {
UpsertChunkInfoRequest request = new UpsertChunkInfoRequest();
request.setKnowledgeId(knowledgeId);
request.setChunkRelationId(chunkRelationId);
request.setIsOpen(isOpen);
dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.OPEN_KNOWLEDGE_CHUNK, request, getHeaders());
}
@Override
public void deleteKnowledgeChunk(String knowledgeId, String chunkRelationId) {
UpsertChunkInfoRequest request = new UpsertChunkInfoRequest();
request.setKnowledgeId(knowledgeId);
request.setChunkRelationId(chunkRelationId);
dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.DELETE_KNOWLEDGE_CHUNK, request, getHeaders());
}
@Override
public void updateKnowledgeChunkDoc(String knowledgeId, String chunkRelationId, String content) {
UpsertChunkInfoRequest request = new UpsertChunkInfoRequest();
request.setKnowledgeId(knowledgeId);
request.setChunkRelationId(chunkRelationId);
request.setChunkContent(content);
dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.UPDATE_KNOWLEDGE_CHUNK_DOC, request, getHeaders());
}
@Override
public void addKnowledgeChunk(String knowledgeId, String content, Integer chunkSort) {
UpsertChunkInfoRequest request = new UpsertChunkInfoRequest();
request.setKnowledgeId(knowledgeId);
request.setChunkSort(chunkSort);
request.setChunkContent(content);
dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.ADD_KNOWLEDGE_CHUNK, request, getHeaders());
}
private List<Header> getHeaders() { private List<Header> getHeaders() {
List<Header> headers = new ArrayList<>(); List<Header> headers = new ArrayList<>();
headers.add(DgtoolsApiConstants.JSON_HEADER); headers.add(DgtoolsApiConstants.JSON_HEADER);
......
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
public class ChunkInfo {
private String knowledgeId;
private String chunkContent;
private String chunkRelationId;
private Integer chunkSort;
private String isOpen;
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
public String getKnowledgeId() {
return knowledgeId;
}
public void setKnowledgeId(String knowledgeId) {
this.knowledgeId = knowledgeId;
}
public String getChunkContent() {
return chunkContent;
}
public void setChunkContent(String chunkContent) {
this.chunkContent = chunkContent;
}
public String getChunkRelationId() {
return chunkRelationId;
}
public void setChunkRelationId(String chunkRelationId) {
this.chunkRelationId = chunkRelationId;
}
public Integer getChunkSort() {
return chunkSort;
}
public void setChunkSort(Integer chunkSort) {
this.chunkSort = chunkSort;
}
@Override
public String toString() {
return "ChunkInfo{" +
"chunkContent='" + chunkContent + '\'' +
", chunkRelationId='" + chunkRelationId + '\'' +
", chunkSort=" + chunkSort +
'}';
}
}
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
import cn.com.poc.support.dgTools.request.AbstractRequest;
import java.io.Serializable;
import java.util.List;
public class GetKnowledgeChunkInfoRequest extends AbstractRequest<GetKnowledgeChunkInfoResult> implements Serializable {
private List<String> knowledgeIds;
public List<String> getKnowledgeIds() {
return knowledgeIds;
}
public void setKnowledgeIds(List<String> knowledgeIds) {
this.knowledgeIds = knowledgeIds;
}
@Override
public String getMethod() throws Exception {
return null;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
import cn.com.poc.support.dgTools.result.AbstractResult;
import java.io.Serializable;
import java.util.List;
public class GetKnowledgeChunkInfoResult extends AbstractResult implements Serializable {
private static final long serialVersionUID = 11243413567468L;
private List<ChunkInfo> chunkInfos;
public List<ChunkInfo> getChunkInfos() {
return chunkInfos;
}
public void setChunkInfos(List<ChunkInfo> chunkInfos) {
this.chunkInfos = chunkInfos;
}
@Override
public String toString() {
return "{" +
"chunkInfos:" + chunkInfos +
'}';
}
}
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
import java.util.List;
public class SegmentationConfigRequest {
/**
* 切分类型
* DEFAULT 默认-分片大小
* IDENTIFIER 标识符或正则表达式
* SEMANTIC 语义切分
*/
private String segmentationType;
/**
* 大分片大小
*/
private int chunkSize;
/**
* 小分片大小
*/
private int scrapSize;
/**
* 分片重复率
*/
private int repetitionRate;
/**
* 关联信息
*/
private List<String> relationInfo;
/**
* 自定义正则
*/
private String regex;
/**
* 标点符号
*/
private List<String> punctuations;
public String getSegmentationType() {
return segmentationType;
}
public void setSegmentationType(String segmentationType) {
this.segmentationType = segmentationType;
}
public int getChunkSize() {
return chunkSize;
}
public void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
public int getScrapSize() {
return scrapSize;
}
public void setScrapSize(int scrapSize) {
this.scrapSize = scrapSize;
}
public int getRepetitionRate() {
return repetitionRate;
}
public void setRepetitionRate(int repetitionRate) {
this.repetitionRate = repetitionRate;
}
public List<String> getRelationInfo() {
return relationInfo;
}
public void setRelationInfo(List<String> relationInfo) {
this.relationInfo = relationInfo;
}
public String getRegex() {
return regex;
}
public void setRegex(String regex) {
this.regex = regex;
}
public List<String> getPunctuations() {
return punctuations;
}
public void setPunctuations(List<String> punctuations) {
this.punctuations = punctuations;
}
}
...@@ -8,6 +8,16 @@ public class TrainKnowledgeRequest extends AbstractRequest<TrainKnowledgeResult> ...@@ -8,6 +8,16 @@ public class TrainKnowledgeRequest extends AbstractRequest<TrainKnowledgeResult>
private String documentUrl; private String documentUrl;
private SegmentationConfigRequest segmentationConfig;
public SegmentationConfigRequest getSegmentationConfig() {
return segmentationConfig;
}
public void setSegmentationConfig(SegmentationConfigRequest segmentationConfig) {
this.segmentationConfig = segmentationConfig;
}
public String getDocumentUrl() { public String getDocumentUrl() {
return documentUrl; return documentUrl;
} }
......
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
import cn.com.poc.support.dgTools.request.AbstractRequest;
import cn.com.poc.support.dgTools.result.AbstractResult;
import java.io.Serializable;
public class UpsertChunkInfoRequest extends AbstractRequest<AbstractResult> implements Serializable {
/**
* 知识库ID
*/
private String knowledgeId;
/**
* 大小块关联ID
*/
private String chunkRelationId;
/**
* 分片内容
*/
private String chunkContent;
/**
* 分片是否开启
*/
private String isOpen;
/**
* 分片排序
*/
private Integer chunkSort;
public String getKnowledgeId() {
return knowledgeId;
}
public void setKnowledgeId(String knowledgeId) {
this.knowledgeId = knowledgeId;
}
public String getChunkRelationId() {
return chunkRelationId;
}
public void setChunkRelationId(String chunkRelationId) {
this.chunkRelationId = chunkRelationId;
}
public String getChunkContent() {
return chunkContent;
}
public void setChunkContent(String chunkContent) {
this.chunkContent = chunkContent;
}
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
public Integer getChunkSort() {
return chunkSort;
}
public void setChunkSort(Integer chunkSort) {
this.chunkSort = chunkSort;
}
@Override
public String getMethod() throws Exception {
return null;
}
}
...@@ -2,7 +2,10 @@ package cn.com.poc; ...@@ -2,7 +2,10 @@ package cn.com.poc;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.yict.framemax.core.spring.SingleContextInitializer; import cn.com.yict.framemax.core.spring.SingleContextInitializer;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.ListUtils;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
...@@ -10,6 +13,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -10,6 +13,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = SingleContextInitializer.class) @ContextConfiguration(initializers = SingleContextInitializer.class)
...@@ -20,6 +27,9 @@ public class AgentApplicationInfoTest { ...@@ -20,6 +27,9 @@ public class AgentApplicationInfoTest {
@Resource @Resource
private AgentApplicationInfoService applicationInfoService; private AgentApplicationInfoService applicationInfoService;
@Resource
private DemandKnowledgeService demandKnowledgeService;
/** /**
* Agent 应用标题,描述生成 * Agent 应用标题,描述生成
*/ */
...@@ -28,4 +38,12 @@ public class AgentApplicationInfoTest { ...@@ -28,4 +38,12 @@ public class AgentApplicationInfoTest {
String input = "测试标题"; String input = "测试标题";
System.out.println(applicationInfoService.createAgentTitleAndDesc(input)); System.out.println(applicationInfoService.createAgentTitleAndDesc(input));
} }
@Test
public void knowledgeTest() {
ArrayList<String> list = new ArrayList<String>() {{
}};
System.out.println(list.toString());
}
} }
package cn.com.poc.knowledge;
import cn.com.poc.common.utils.FileUtils;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent;
import cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge.GetKnowledgeChunkInfoResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse;
import cn.com.poc.thirdparty.service.LLMService;
import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.core.spring.SingleContextInitializer;
import cn.com.yict.framemax.data.model.PagingInfo;
import cn.hutool.core.collection.ListUtil;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = SingleContextInitializer.class)
@WebAppConfiguration
public class Demand {
final private String EVENT_STREAM_PREFIX = "data: ";
@Resource
private DemandKnowledgeService demandKnowledgeService;
@Resource
private LLMService llmService;
@Test
public void test() {
String str = FileUtils.formatFileSize(1024);
System.out.println(str);
// GetKnowledgeChunkInfoResult knowledgeChunkInfos = demandKnowledgeService.getKnowledgeChunkInfos(ListUtil.toList("KnowLedge-1050ef90-7232-487f-ac8b-501002c7b789", "KnowLedge-315f8992-9aa2-4f0b-a06f-9298b1de7504"), new PagingInfo());
// System.out.println(knowledgeChunkInfos);
}
@Test
public void llmTest() throws Exception {
List<Message> messageList = new ArrayList<>();
List<MultiContent> multiContents = new ArrayList<>();
MultiContent multiContent = new MultiContent();
multiContents.add(multiContent);
multiContent.setType("text");
multiContent.setText("Hello, how are you?");
Message userMessage = new Message();
userMessage.setRole("user");
userMessage.setContent(multiContents);
messageList.add(userMessage);
String largeModel = "qwen-max";
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(largeModel);
largeModelResponse.setMessages(messageList.toArray(new Message[0]));
largeModelResponse.setTopP(0F);
largeModelResponse.setStream(true);
largeModelResponse.setUser("POE");
BufferedReader bufferedReader = llmService.chatChunk(largeModelResponse);
String res = "";
bufferedReader.mark(200);
while ((res = bufferedReader.readLine()) != null) {
if (StringUtils.isBlank(res)) {
continue;
}
LargeModelDemandResult result = JsonUtils.deSerialize(res.replaceFirst(EVENT_STREAM_PREFIX, StringUtils.EMPTY), LargeModelDemandResult.class);
if (!"0".equals(result.getCode())) {
BusinessException ex = new BusinessException("ʧ");
throw ex;
}
bufferedReader.reset();
break;
}
while ((res = bufferedReader.readLine()) != null) {
if (StringUtils.isBlank(res)) {
continue;
}
LargeModelDemandResult result = JsonUtils.deSerialize(res.replaceFirst(EVENT_STREAM_PREFIX, StringUtils.EMPTY), LargeModelDemandResult.class);
if (!"0".equals(result.getCode())) {
BusinessException ex = new BusinessException("ʧ");
throw ex;
}
System.out.println("result:" + result);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment