Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improvement](Headless) Adding change event to tags and integrating tag into embeddings #792

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void parse(QueryContext queryCtx, ChatContext chatCtx) {
return;
}
try {
//2.get modelId from queryCtx and chatCtx.
//2.get dataSetId from queryCtx and chatCtx.
Long dataSetId = requestService.getDataSetId(queryCtx);
if (dataSetId == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ private static SchemaElement getEntity(DataSetSchemaResp resp) {

private static Set<SchemaElement> getTags(DataSetSchemaResp resp) {
Set<SchemaElement> tags = new HashSet<>();
List<TagResp> tagResps = resp.getTags();

for (TagResp tagResp : tagResps) {
for (TagResp tagResp : resp.getTags()) {
SchemaElement element = SchemaElement.builder()
.dataSet(resp.getId())
.model(tagResp.getModelId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public RecommendResp recommend(RecommendReq recommendReq, Long limit) {
if (Objects.isNull(limit) || limit <= 0) {
limit = Long.MAX_VALUE;
}
log.debug("limit:{}", limit);
Long modelId = recommendReq.getModelId();
if (Objects.isNull(modelId)) {
return new RecommendResp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public enum DictWordType {

DIMENSION("dimension"),

VALUE("value"),
VALUE("v"),

VIEW("view"),

ENTITY("entity"),

NUMBER("m"),

TAG("tag"),
TAG("t"),

SUFFIX("suffix");

Expand All @@ -45,7 +45,7 @@ public static DictWordType getNatureType(String nature) {
return dictWordType;
}
}
//domain
//view
String[] natures = nature.split(DictWordType.NATURE_SPILT);
if (natures.length == 2 && StringUtils.isNumeric(natures[1])) {
return VIEW;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.tencent.supersonic.headless.api.pojo.response;

import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;

import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
import com.tencent.supersonic.headless.api.pojo.ItemValueConfig;
import lombok.Data;

import javax.validation.constraints.NotNull;

import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
import lombok.Data;

@Data
public class DictItemResp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public DataSetSchemaResp fetchDataSetSchema(Long dataSetId) {
}

public List<DataSetSchemaResp> buildDataSetSchema(DataSetFilterReq filter) {

MetaFilter metaFilter = new MetaFilter();
metaFilter.setStatus(StatusEnum.ONLINE.getCode());
metaFilter.setIds(filter.getDataSetIds());
Expand All @@ -141,7 +140,7 @@ public List<DataSetSchemaResp> buildDataSetSchema(DataSetFilterReq filter) {

TagFilter tagFilter = new TagFilter();
tagFilter.setModelIds(modelIds);
List<TagResp> tagResps = tagService.getTags(tagFilter);
List<TagResp> tagRespList = tagService.getTags(tagFilter);

List<DataSetSchemaResp> dataSetSchemaResps = new ArrayList<>();
for (Long dataSetId : dataSetRespMap.keySet()) {
Expand All @@ -160,8 +159,8 @@ public List<DataSetSchemaResp> buildDataSetSchema(DataSetFilterReq filter) {
dataSetSchemaResp.setModelResps(modelResps.stream().filter(modelResp ->
dataSetResp.getAllModels().contains(modelResp.getId())).collect(Collectors.toList()));

tagResps = TagConverter.filterByDataSet(tagResps, dataSetResp);
dataSetSchemaResp.setTags(tagResps);
tagRespList = TagConverter.filterByDataSet(tagRespList, dataSetResp);
dataSetSchemaResp.setTags(tagRespList);
dataSetSchemaResps.add(dataSetSchemaResp);
}
fillStaticInfo(dataSetSchemaResps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.pojo.Constants;
import com.tencent.supersonic.common.pojo.DataEvent;
import com.tencent.supersonic.common.pojo.DataItem;
import com.tencent.supersonic.common.pojo.enums.AuthType;
import com.tencent.supersonic.common.pojo.enums.EventType;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
import com.tencent.supersonic.headless.api.pojo.TagDefineParams;
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
import com.tencent.supersonic.headless.api.pojo.request.TagReq;

import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
import com.tencent.supersonic.headless.server.persistence.dataobject.CollectDO;
Expand All @@ -25,7 +28,6 @@
import com.tencent.supersonic.headless.server.service.ModelService;
import com.tencent.supersonic.headless.server.service.TagService;
import com.tencent.supersonic.headless.server.utils.NameCheckUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand All @@ -34,12 +36,12 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -49,12 +51,14 @@ public class TagServiceImpl implements TagService {
private final TagRepository tagRepository;
private final ModelService modelService;
private final CollectService collectService;
private ApplicationEventPublisher eventPublisher;

public TagServiceImpl(TagRepository tagRepository, ModelService modelService,
CollectService collectService) {
CollectService collectService, ApplicationEventPublisher eventPublisher) {
this.tagRepository = tagRepository;
this.modelService = modelService;
this.collectService = collectService;
this.eventPublisher = eventPublisher;
}

@Override
Expand All @@ -72,21 +76,45 @@ public TagResp create(TagReq tagReq, User user) {
} else {
tagDO.setStatus(StatusEnum.ONLINE.getCode());
}

tagRepository.create(tagDO);
sendEventBatch(Lists.newArrayList(tagDO), EventType.ADD);
return convert(tagDO);
}

private void sendEventBatch(List<TagDO> tagDOS, EventType eventType) {
List<DataItem> dataItems = tagDOS.stream().map(this::getDataItem)
.collect(Collectors.toList());
eventPublisher.publishEvent(new DataEvent(this, dataItems, eventType));
}

private void sendEvent(DataItem dataItem, EventType eventType) {
eventPublisher.publishEvent(new DataEvent(this,
Lists.newArrayList(dataItem), eventType));
}

private DataItem getDataItem(TagDO tagDO) {
return DataItem.builder().id(tagDO.getId() + Constants.UNDERLINE).name(tagDO.getName())
.bizName(tagDO.getBizName()).modelId(tagDO.getModelId() + Constants.UNDERLINE)
.type(TypeEnums.TAG).build();
}

@Override
public TagResp update(TagReq tagReq, User user) {
if (Objects.isNull(tagReq.getId()) || tagReq.getId() <= 0) {
throw new RuntimeException("id is empty");
}
TagDO tagDO = tagRepository.getTagById(tagReq.getId());
String oldName = tagDO.getName();
tagDO = fillUpdateInfo(tagReq, tagDO);
tagDO.setUpdatedBy(user.getName());
tagDO.setUpdatedAt(new Date());
tagRepository.update(tagDO);
if (!oldName.equals(tagReq.getName())) {
DataItem dataItem = getDataItem(tagDO);
dataItem.setName(oldName);
dataItem.setNewName(tagReq.getName());
sendEvent(getDataItem(tagDO), EventType.UPDATE);
}
return convert(tagDO);
}

Expand All @@ -100,6 +128,7 @@ public void delete(Long id, User user) {
tagDO.setUpdatedBy(user.getName());
tagDO.setUpdatedAt(new Date());
tagRepository.update(tagDO);
sendEventBatch(Lists.newArrayList(tagDO), EventType.DELETE);
}

@Override
Expand Down Expand Up @@ -142,7 +171,7 @@ public PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user) {
}

PageInfo<TagDO> tagDOPageInfo = PageHelper.startPage(tagFilterPage.getCurrent(),
tagFilterPage.getPageSize())
tagFilterPage.getPageSize())
.doSelectPageInfo(() -> getTags(tagFilter));
PageInfo<TagResp> pageInfo = new PageInfo<>();
BeanUtils.copyProperties(tagDOPageInfo, pageInfo);
Expand Down Expand Up @@ -173,8 +202,12 @@ public Boolean batchUpdateStatus(MetaBatchReq metaBatchReq, User user) {
});

tagRepository.batchUpdateStatus(tagDOList);
// todo sendEventBatch

if (StatusEnum.OFFLINE.getCode().equals(metaBatchReq.getStatus())
|| StatusEnum.DELETED.getCode().equals(metaBatchReq.getStatus())) {
sendEventBatch(tagDOList, EventType.DELETE);
} else if (StatusEnum.ONLINE.getCode().equals(metaBatchReq.getStatus())) {
sendEventBatch(tagDOList, EventType.ADD);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ s2:
chat-model:
provider: open_ai
openai:
api-key: app_key
api-key: api_key
model-name: gpt-3.5-turbo-16k
temperature: 0.0
timeout: PT60S
Expand Down
Loading