Skip to content

Commit

Permalink
[improvement][launcher]Clean code logic of s2demos and remove tag-rel…
Browse files Browse the repository at this point in the history
…ated constructs.
  • Loading branch information
jerryjzhang committed Nov 16, 2024
1 parent ba1938f commit e8c9855
Show file tree
Hide file tree
Showing 15 changed files with 13,932 additions and 16,305 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tencent.supersonic.headless.api.pojo;

import com.tencent.supersonic.common.pojo.Constants;
import com.tencent.supersonic.headless.api.pojo.enums.DimensionType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -12,7 +13,7 @@ public class Dim {

private String name;

private String type;
private DimensionType type;

private String expr;

Expand All @@ -28,23 +29,15 @@ public class Dim {

private int isTag;

public Dim(String name, String bizName, String type, Integer isCreateDimension) {
public Dim(String name, String bizName, DimensionType type, Integer isCreateDimension) {
this.name = name;
this.type = type;
this.isCreateDimension = isCreateDimension;
this.bizName = bizName;
}

public Dim(String name, String bizName, String type, Integer isCreateDimension, int isTag) {
this.name = name;
this.type = type;
this.isCreateDimension = isCreateDimension;
this.bizName = bizName;
this.isTag = isTag;
}

public Dim(String name, String type, String expr, String dateFormat,
DimensionTimeTypeParams typeParams, Integer isCreateDimension, String bizName) {
public Dim(String name, String bizName, DimensionType type, Integer isCreateDimension,
String expr, String dateFormat, DimensionTimeTypeParams typeParams) {
this.name = name;
this.type = type;
this.expr = expr;
Expand All @@ -55,8 +48,8 @@ public Dim(String name, String type, String expr, String dateFormat,
}

public static Dim getDefault() {
return new Dim("日期", "time", "2023-05-28", Constants.DAY_FORMAT,
new DimensionTimeTypeParams("true", "day"), 0, "imp_date");
return new Dim("数据日期", "imp_date", DimensionType.partition_time, 0, "imp_date",
Constants.DAY_FORMAT, new DimensionTimeTypeParams("false", "day"));
}

public String getFieldName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public List<Dim> filterTimeDims() {
if (CollectionUtils.isEmpty(dimensions)) {
return Lists.newArrayList();
}
return dimensions.stream()
.filter(dim -> DimensionType.partition_time.name().equalsIgnoreCase(dim.getType()))
return dimensions.stream().filter(dim -> DimensionType.partition_time.equals(dim.getType()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class ModelReq extends SchemaItem {

private List<String> adminOrgs;

private Long tagObjectId;

private Map<String, Object> ext;

public String getViewer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void addSysTimeDimension(List<Dim> dims, DbAdaptor engineAdaptor)
private static Dim generateSysDayDimension(Dim timeDim, DbAdaptor engineAdaptor) {
Dim dim = new Dim();
dim.setBizName(TimeDimensionEnum.DAY.getName());
dim.setType(DimensionType.partition_time.name());
dim.setType(DimensionType.partition_time);
dim.setExpr(generateTimeExpr(timeDim, TimeDimensionEnum.DAY.name().toLowerCase(),
engineAdaptor));
DimensionTimeTypeParams typeParams = new DimensionTimeTypeParams();
Expand All @@ -50,7 +50,7 @@ private static Dim generateSysDayDimension(Dim timeDim, DbAdaptor engineAdaptor)
private static Dim generateSysWeekDimension(Dim timeDim, DbAdaptor engineAdaptor) {
Dim dim = new Dim();
dim.setBizName(TimeDimensionEnum.WEEK.getName());
dim.setType(DimensionType.partition_time.name());
dim.setType(DimensionType.partition_time);
dim.setExpr(generateTimeExpr(timeDim, TimeDimensionEnum.WEEK.name().toLowerCase(),
engineAdaptor));
DimensionTimeTypeParams typeParams = new DimensionTimeTypeParams();
Expand All @@ -63,7 +63,7 @@ private static Dim generateSysWeekDimension(Dim timeDim, DbAdaptor engineAdaptor
private static Dim generateSysMonthDimension(Dim timeDim, DbAdaptor engineAdaptor) {
Dim dim = new Dim();
dim.setBizName(TimeDimensionEnum.MONTH.getName());
dim.setType(DimensionType.partition_time.name());
dim.setType(DimensionType.partition_time);
dim.setExpr(generateTimeExpr(timeDim, TimeDimensionEnum.MONTH.name().toLowerCase(),
engineAdaptor));
DimensionTimeTypeParams typeParams = new DimensionTimeTypeParams();
Expand Down Expand Up @@ -92,7 +92,7 @@ private static String generateTimeExpr(Dim timeDim, String dateType, DbAdaptor e

private static Dim getTimeDim(List<Dim> timeDims) {
for (Dim dim : timeDims) {
if (dim.getType().equalsIgnoreCase(DimensionType.partition_time.name())) {
if (dim.getType().equals(DimensionType.partition_time)) {
return dim;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static DimensionReq convert(Dim dim, ModelDO modelDO) {
}
dimensionReq.setModelId(modelDO.getId());
dimensionReq.setExpr(dim.getBizName());
dimensionReq.setType(dim.getType());
dimensionReq.setType(dim.getType().name());
dimensionReq
.setDescription(Objects.isNull(dim.getDescription()) ? "" : dim.getDescription());
dimensionReq.setIsTag(dim.getIsTag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ private ModelReq mockModelReq() {
identifiers.add(new Identify("用户名", IdentifyType.primary.name(), "user_name"));
modelDetail.setIdentifiers(identifiers);
List<Dim> dimensions = new ArrayList<>();
Dim dimension1 = new Dim("", "imp_date", DimensionType.partition_time.name(), 0);
Dim dimension1 = new Dim("", "imp_date", DimensionType.partition_time, 0);
dimension1.setTypeParams(new DimensionTimeTypeParams());
dimensions.add(dimension1);
Dim dimension2 = new Dim("", "page", DimensionType.categorical.name(), 0);
Dim dimension2 = new Dim("", "page", DimensionType.categorical, 0);
dimension2.setExpr("page");
dimensions.add(dimension2);
modelDetail.setDimensions(dimensions);
Expand Down Expand Up @@ -135,10 +135,10 @@ private ModelReq mockModelReq_update() {
modelDetail.setIdentifiers(identifiers);

List<Dim> dimensions = new ArrayList<>();
Dim dimension1 = new Dim("", "imp_date_a", DimensionType.partition_time.name(), 0);
Dim dimension1 = new Dim("", "imp_date_a", DimensionType.partition_time, 0);
dimension1.setTypeParams(new DimensionTimeTypeParams());
dimensions.add(dimension1);
Dim dimension2 = new Dim("", "page_a", DimensionType.categorical.name(), 0);
Dim dimension2 = new Dim("", "page_a", DimensionType.categorical, 0);
dimension2.setExpr("page_a");
dimensions.add(dimension2);
modelDetail.setDimensions(dimensions);
Expand Down Expand Up @@ -170,10 +170,10 @@ private ModelReq mockModelReq_updateAdmin() {
identifiers.add(new Identify("用户名", IdentifyType.primary.name(), "user_name"));
modelDetail.setIdentifiers(identifiers);
List<Dim> dimensions = new ArrayList<>();
Dim dimension1 = new Dim("", "imp_date", DimensionType.partition_time.name(), 0);
Dim dimension1 = new Dim("", "imp_date", DimensionType.partition_time, 0);
dimension1.setTypeParams(new DimensionTimeTypeParams());
dimensions.add(dimension1);
Dim dimension2 = new Dim("", "page", DimensionType.categorical.name(), 0);
Dim dimension2 = new Dim("", "page", DimensionType.categorical, 0);
dimension2.setExpr("page");
dimensions.add(dimension2);
modelDetail.setDimensions(dimensions);
Expand Down Expand Up @@ -208,10 +208,10 @@ private ModelResp buildExpectedModelResp() {
modelDetail.setIdentifiers(identifiers);

List<Dim> dimensions = new ArrayList<>();
Dim dimension1 = new Dim("", "imp_date", DimensionType.partition_time.name(), 0);
Dim dimension1 = new Dim("", "imp_date", DimensionType.partition_time, 0);
dimension1.setTypeParams(new DimensionTimeTypeParams());
dimensions.add(dimension1);
Dim dimension2 = new Dim("", "page", DimensionType.categorical.name(), 0);
Dim dimension2 = new Dim("", "page", DimensionType.categorical, 0);
dimension2.setExpr("page");
dimensions.add(dimension2);
modelDetail.setDimensions(dimensions);
Expand Down Expand Up @@ -253,10 +253,10 @@ private ModelResp buildExpectedModelResp_update() {
modelDetail.setIdentifiers(identifiers);

List<Dim> dimensions = new ArrayList<>();
Dim dimension1 = new Dim("", "imp_date_a", DimensionType.partition_time.name(), 0);
Dim dimension1 = new Dim("", "imp_date_a", DimensionType.partition_time, 0);
dimension1.setTypeParams(new DimensionTimeTypeParams());
dimensions.add(dimension1);
Dim dimension2 = new Dim("", "page_a", DimensionType.categorical.name(), 0);
Dim dimension2 = new Dim("", "page_a", DimensionType.categorical, 0);
dimension2.setExpr("page_a");
dimensions.add(dimension2);
modelDetail.setDimensions(dimensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.service.ChatManageService;
import com.tencent.supersonic.chat.server.service.ChatQueryService;
Expand All @@ -17,16 +18,23 @@
import com.tencent.supersonic.headless.api.pojo.MetaFilter;
import com.tencent.supersonic.headless.api.pojo.RelateDimension;
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
import com.tencent.supersonic.headless.api.pojo.request.DatabaseReq;
import com.tencent.supersonic.headless.api.pojo.request.DictItemReq;
import com.tencent.supersonic.headless.api.pojo.request.DictSingleTaskReq;
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
import com.tencent.supersonic.headless.api.pojo.response.DimensionResp;
import com.tencent.supersonic.headless.api.pojo.response.MetricResp;
import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
import com.tencent.supersonic.headless.server.service.*;
import com.tencent.supersonic.headless.server.service.DataSetService;
import com.tencent.supersonic.headless.server.service.DatabaseService;
import com.tencent.supersonic.headless.server.service.DictConfService;
import com.tencent.supersonic.headless.server.service.DictTaskService;
import com.tencent.supersonic.headless.server.service.DimensionService;
import com.tencent.supersonic.headless.server.service.DomainService;
import com.tencent.supersonic.headless.server.service.MetricService;
import com.tencent.supersonic.headless.server.service.ModelRelaService;
import com.tencent.supersonic.headless.server.service.ModelService;
import com.tencent.supersonic.headless.server.service.TermService;
import com.tencent.supersonic.headless.server.service.impl.DictWordService;
import dev.langchain4j.provider.ModelProvider;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -61,8 +69,6 @@ public abstract class S2BaseDemo implements CommandLineRunner {
@Autowired
protected MetricService metricService;
@Autowired
protected TagMetaService tagMetaService;
@Autowired
protected AuthService authService;
@Autowired
protected DataSetService dataSetService;
Expand All @@ -73,8 +79,6 @@ public abstract class S2BaseDemo implements CommandLineRunner {
@Autowired
protected DataSourceProperties dataSourceProperties;
@Autowired
protected TagObjectService tagObjectService;
@Autowired
protected ChatQueryService chatQueryService;
@Autowired
protected ChatManageService chatManageService;
Expand Down Expand Up @@ -133,7 +137,7 @@ protected DatabaseResp addDatabaseIfNotExist() {

protected ChatModel addChatModelIfNotExist() {
List<ChatModel> chatModels = chatModelService.getChatModels();
if (chatModels.size() > 0) {
if (!chatModels.isEmpty()) {
return chatModels.get(0);
} else {
ChatModel chatModel = new ChatModel();
Expand Down Expand Up @@ -180,13 +184,6 @@ protected List<DataSetModelConfig> getDataSetModelConfigs(Long domainId) {
return dataSetModelConfigs;
}

protected void addTag(Long itemId, TagDefineType tagDefineType) {
TagReq tagReq = new TagReq();
tagReq.setTagDefineType(tagDefineType);
tagReq.setItemId(itemId);
tagMetaService.create(tagReq, User.getDefaultUser());
}

protected DimensionResp getDimension(String bizName, ModelResp model) {
return dimensionService.getDimension(bizName, model.getId());
}
Expand All @@ -209,4 +206,13 @@ protected void enableDimensionValue(DimensionResp dimension) {
dictTaskService.addDictTask(DictSingleTaskReq.builder().itemId(dimension.getId())
.type(TypeEnums.DIMENSION).build(), defaultUser);
}

protected void submitText(int chatId, int agentId, String queryText) {
chatQueryService.parseAndExecute(ChatParseReq.builder().chatId(chatId).agentId(agentId)
.queryText(queryText).user(defaultUser).disableLLM(true).build());
}

protected void loadDictWord() {
dictWordService.loadDictWord();
}
}
Loading

0 comments on commit e8c9855

Please sign in to comment.