mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
[improvement][chat]Rename SemanticLayer to SemanticInterpreter
This commit is contained in:
@@ -40,7 +40,7 @@ The high-level architecture and main process flow is as follows:
|
|||||||
|
|
||||||
- **Semantic Corrector:** checks validity of extracted semantic information and performs correction and optimization if needed.
|
- **Semantic Corrector:** checks validity of extracted semantic information and performs correction and optimization if needed.
|
||||||
|
|
||||||
- **Semantic Layer:** performs execution according to extracted semantic information. It generates SQL queries and executes them against physical data models.
|
- **Semantic Interpreter:** performs execution according to extracted semantic information. It generates SQL statements and executes them against physical data models.
|
||||||
|
|
||||||
- **Chat Plugin:** extends functionality with third-party tools. The LLM is going to select the most suitable one, given all configured plugins with function description and sample questions.
|
- **Chat Plugin:** extends functionality with third-party tools. The LLM is going to select the most suitable one, given all configured plugins with function description and sample questions.
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
- **语义修正器(Semantic Corrector):** 检查语义信息的合法性,对不合法的信息做修正和优化处理。
|
- **语义修正器(Semantic Corrector):** 检查语义信息的合法性,对不合法的信息做修正和优化处理。
|
||||||
|
|
||||||
- **语义翻译器(Semantic Layer):** 根据语义信息生成物理SQL执行查询。
|
- **语义解释器(Semantic Interpreter):** 根据语义信息生成物理SQL执行查询。
|
||||||
|
|
||||||
- **问答插件(Chat Plugin):** 通过第三方工具扩展功能。给定所有配置的插件及其功能描述和示例问题,大语言模型将选择最合适的插件。
|
- **问答插件(Chat Plugin):** 通过第三方工具扩展功能。给定所有配置的插件及其功能描述和示例问题,大语言模型将选择最合适的插件。
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
* as proxy to a remote semantic service.
|
* as proxy to a remote semantic service.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public interface SemanticLayer {
|
public interface SemanticInterpreter {
|
||||||
|
|
||||||
QueryResultWithSchemaResp queryByStruct(QueryStructReq queryStructReq, User user);
|
QueryResultWithSchemaResp queryByStruct(QueryStructReq queryStructReq, User user);
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@ import com.google.common.collect.Sets;
|
|||||||
import com.tencent.supersonic.chat.agent.Agent;
|
import com.tencent.supersonic.chat.agent.Agent;
|
||||||
import com.tencent.supersonic.chat.agent.tool.AgentToolType;
|
import com.tencent.supersonic.chat.agent.tool.AgentToolType;
|
||||||
import com.tencent.supersonic.chat.agent.tool.MetricInterpretTool;
|
import com.tencent.supersonic.chat.agent.tool.MetricInterpretTool;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
@@ -82,8 +82,8 @@ public class MetricInterpretParser implements SemanticParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<SchemaElement> getMetrics(List<Long> metricIds, Long modelId) {
|
public Set<SchemaElement> getMetrics(List<Long> metricIds, Long modelId) {
|
||||||
SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
ModelSchema modelSchema = semanticLayer.getModelSchema(modelId, true);
|
ModelSchema modelSchema = semanticInterpreter.getModelSchema(modelId, true);
|
||||||
Set<SchemaElement> metrics = modelSchema.getMetrics();
|
Set<SchemaElement> metrics = modelSchema.getMetrics();
|
||||||
return metrics.stream().filter(schemaElement -> metricIds.contains(schemaElement.getId()))
|
return metrics.stream().filter(schemaElement -> metricIds.contains(schemaElement.getId()))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tencent.supersonic.chat.query.llm.dsl;
|
package com.tencent.supersonic.chat.query.llm.dsl;
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.EntityInfo;
|
import com.tencent.supersonic.chat.api.pojo.response.EntityInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryState;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryState;
|
||||||
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
|
|||||||
public class DslQuery extends PluginSemanticQuery {
|
public class DslQuery extends PluginSemanticQuery {
|
||||||
|
|
||||||
public static final String QUERY_MODE = "DSL";
|
public static final String QUERY_MODE = "DSL";
|
||||||
protected SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
protected SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
public DslQuery() {
|
public DslQuery() {
|
||||||
QueryManager.register(this);
|
QueryManager.register(this);
|
||||||
@@ -49,7 +49,7 @@ public class DslQuery extends PluginSemanticQuery {
|
|||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
QueryDslReq queryDslReq = getQueryDslReq(llmResp);
|
QueryDslReq queryDslReq = getQueryDslReq(llmResp);
|
||||||
QueryResultWithSchemaResp queryResp = semanticLayer.queryByDsl(queryDslReq, user);
|
QueryResultWithSchemaResp queryResp = semanticInterpreter.queryByDsl(queryDslReq, user);
|
||||||
|
|
||||||
log.info("queryByDsl cost:{},querySql:{}", System.currentTimeMillis() - startTime, llmResp.getSqlOutput());
|
log.info("queryByDsl cost:{},querySql:{}", System.currentTimeMillis() - startTime, llmResp.getSqlOutput());
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class DslQuery extends PluginSemanticQuery {
|
|||||||
.queryTypeEnum(QueryTypeEnum.SQL)
|
.queryTypeEnum(QueryTypeEnum.SQL)
|
||||||
.queryReq(getQueryDslReq(getLlmResp()))
|
.queryReq(getQueryDslReq(getLlmResp()))
|
||||||
.build();
|
.build();
|
||||||
return semanticLayer.explain(explainSqlReq, user);
|
return semanticInterpreter.explain(explainSqlReq, user);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("explain error explainSqlReq:{}", explainSqlReq, e);
|
log.error("explain error explainSqlReq:{}", explainSqlReq, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.chat.query.llm.interpret;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
@@ -54,8 +54,8 @@ public class MetricInterpretQuery extends PluginSemanticQuery {
|
|||||||
QueryStructReq queryStructReq = QueryReqBuilder.buildStructReq(parseInfo);
|
QueryStructReq queryStructReq = QueryReqBuilder.buildStructReq(parseInfo);
|
||||||
fillAggregator(queryStructReq, parseInfo.getMetrics());
|
fillAggregator(queryStructReq, parseInfo.getMetrics());
|
||||||
queryStructReq.setNativeQuery(true);
|
queryStructReq.setNativeQuery(true);
|
||||||
SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
QueryResultWithSchemaResp queryResultWithSchemaResp = semanticLayer.queryByStruct(queryStructReq, user);
|
QueryResultWithSchemaResp queryResultWithSchemaResp = semanticInterpreter.queryByStruct(queryStructReq, user);
|
||||||
String text = generateTableText(queryResultWithSchemaResp);
|
String text = generateTableText(queryResultWithSchemaResp);
|
||||||
Map<String, Object> properties = parseInfo.getProperties();
|
Map<String, Object> properties = parseInfo.getProperties();
|
||||||
Map<String, String> replacedMap = new HashMap<>();
|
Map<String, String> replacedMap = new HashMap<>();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
package com.tencent.supersonic.chat.query.rule;
|
package com.tencent.supersonic.chat.query.rule;
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
@@ -45,7 +45,7 @@ public abstract class RuleSemanticQuery implements SemanticQuery, Serializable {
|
|||||||
|
|
||||||
protected SemanticParseInfo parseInfo = new SemanticParseInfo();
|
protected SemanticParseInfo parseInfo = new SemanticParseInfo();
|
||||||
protected QueryMatcher queryMatcher = new QueryMatcher();
|
protected QueryMatcher queryMatcher = new QueryMatcher();
|
||||||
protected SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
protected SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
public RuleSemanticQuery() {
|
public RuleSemanticQuery() {
|
||||||
QueryManager.register(this);
|
QueryManager.register(this);
|
||||||
@@ -196,7 +196,7 @@ public abstract class RuleSemanticQuery implements SemanticQuery, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryResult queryResult = new QueryResult();
|
QueryResult queryResult = new QueryResult();
|
||||||
QueryResultWithSchemaResp queryResp = semanticLayer.queryByStruct(convertQueryStruct(), user);
|
QueryResultWithSchemaResp queryResp = semanticInterpreter.queryByStruct(convertQueryStruct(), user);
|
||||||
|
|
||||||
if (queryResp != null) {
|
if (queryResp != null) {
|
||||||
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
||||||
@@ -227,7 +227,7 @@ public abstract class RuleSemanticQuery implements SemanticQuery, Serializable {
|
|||||||
.queryTypeEnum(QueryTypeEnum.STRUCT)
|
.queryTypeEnum(QueryTypeEnum.STRUCT)
|
||||||
.queryReq(convertQueryStruct())
|
.queryReq(convertQueryStruct())
|
||||||
.build();
|
.build();
|
||||||
return semanticLayer.explain(explainSqlReq, user);
|
return semanticInterpreter.explain(explainSqlReq, user);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("explain error explainSqlReq:{}", explainSqlReq, e);
|
log.error("explain error explainSqlReq:{}", explainSqlReq, e);
|
||||||
}
|
}
|
||||||
@@ -246,7 +246,7 @@ public abstract class RuleSemanticQuery implements SemanticQuery, Serializable {
|
|||||||
|
|
||||||
QueryResult queryResult = new QueryResult();
|
QueryResult queryResult = new QueryResult();
|
||||||
QueryMultiStructReq queryMultiStructReq = convertQueryMultiStruct();
|
QueryMultiStructReq queryMultiStructReq = convertQueryMultiStruct();
|
||||||
QueryResultWithSchemaResp queryResp = semanticLayer.queryByMultiStruct(queryMultiStructReq, user);
|
QueryResultWithSchemaResp queryResp = semanticInterpreter.queryByMultiStruct(queryMultiStructReq, user);
|
||||||
if (queryResp != null) {
|
if (queryResp != null) {
|
||||||
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.chat.rest;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigBaseReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigBaseReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigEditReqReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigEditReqReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
||||||
@@ -41,7 +41,7 @@ public class ChatConfigController {
|
|||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
|
|
||||||
|
|
||||||
private SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@@ -85,35 +85,35 @@ public class ChatConfigController {
|
|||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
return semanticLayer.getModelList(AuthType.ADMIN, domainId, user);
|
return semanticInterpreter.getModelList(AuthType.ADMIN, domainId, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/modelList")
|
@GetMapping("/modelList")
|
||||||
public List<ModelResp> getModelList(HttpServletRequest request,
|
public List<ModelResp> getModelList(HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
return semanticLayer.getModelList(AuthType.ADMIN, null, user);
|
return semanticInterpreter.getModelList(AuthType.ADMIN, null, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/domainList")
|
@GetMapping("/domainList")
|
||||||
public List<DomainResp> getDomainList(HttpServletRequest request,
|
public List<DomainResp> getDomainList(HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
return semanticLayer.getDomainList(user);
|
return semanticInterpreter.getDomainList(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/modelList/view")
|
@GetMapping("/modelList/view")
|
||||||
public List<ModelResp> getModelListVisible(HttpServletRequest request,
|
public List<ModelResp> getModelListVisible(HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
return semanticLayer.getModelList(AuthType.VISIBLE, null, user);
|
return semanticInterpreter.getModelList(AuthType.VISIBLE, null, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/dimension/page")
|
@PostMapping("/dimension/page")
|
||||||
public PageInfo<DimensionResp> getDimension(@RequestBody PageDimensionReq pageDimensionReq,
|
public PageInfo<DimensionResp> getDimension(@RequestBody PageDimensionReq pageDimensionReq,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
return semanticLayer.getDimensionPage(pageDimensionReq);
|
return semanticInterpreter.getDimensionPage(pageDimensionReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/metric/page")
|
@PostMapping("/metric/page")
|
||||||
@@ -121,7 +121,7 @@ public class ChatConfigController {
|
|||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
return semanticLayer.getMetricPage(pageMetricReq, user);
|
return semanticInterpreter.getMetricPage(pageMetricReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
|||||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
@@ -78,7 +78,7 @@ public class SemanticService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AggregatorConfig aggregatorConfig;
|
private AggregatorConfig aggregatorConfig;
|
||||||
|
|
||||||
private SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
public ModelSchema getModelSchema(Long id) {
|
public ModelSchema getModelSchema(Long id) {
|
||||||
ModelSchema modelSchema = schemaService.getModelSchema(id);
|
ModelSchema modelSchema = schemaService.getModelSchema(id);
|
||||||
@@ -227,7 +227,7 @@ public class SemanticService {
|
|||||||
|
|
||||||
QueryResultWithSchemaResp queryResultWithColumns = null;
|
QueryResultWithSchemaResp queryResultWithColumns = null;
|
||||||
try {
|
try {
|
||||||
queryResultWithColumns = semanticLayer.queryByStruct(QueryReqBuilder.buildStructReq(semanticParseInfo),
|
queryResultWithColumns = semanticInterpreter.queryByStruct(QueryReqBuilder.buildStructReq(semanticParseInfo),
|
||||||
user);
|
user);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("setMainModel queryByStruct error, e:", e);
|
log.warn("setMainModel queryByStruct error, e:", e);
|
||||||
@@ -393,7 +393,7 @@ public class SemanticService {
|
|||||||
|
|
||||||
queryStructReq.setGroups(new ArrayList<>(Arrays.asList(dateField)));
|
queryStructReq.setGroups(new ArrayList<>(Arrays.asList(dateField)));
|
||||||
queryStructReq.setDateInfo(getRatioDateConf(aggOperatorEnum, semanticParseInfo, results));
|
queryStructReq.setDateInfo(getRatioDateConf(aggOperatorEnum, semanticParseInfo, results));
|
||||||
QueryResultWithSchemaResp queryResp = semanticLayer.queryByStruct(queryStructReq, user);
|
QueryResultWithSchemaResp queryResp = semanticInterpreter.queryByStruct(queryStructReq, user);
|
||||||
if (Objects.nonNull(queryResp) && !CollectionUtils.isEmpty(queryResp.getResultList())) {
|
if (Objects.nonNull(queryResp) && !CollectionUtils.isEmpty(queryResp.getResultList())) {
|
||||||
|
|
||||||
Map<String, Object> result = queryResp.getResultList().get(0);
|
Map<String, Object> result = queryResp.getResultList().get(0);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.tencent.supersonic.chat.service.impl;
|
|||||||
|
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ItemVisibility;
|
import com.tencent.supersonic.chat.api.pojo.request.ItemVisibility;
|
||||||
@@ -63,7 +63,7 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
private SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
|
|
||||||
public ConfigServiceImpl(ChatConfigRepository chatConfigRepository,
|
public ConfigServiceImpl(ChatConfigRepository chatConfigRepository,
|
||||||
@@ -353,7 +353,7 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
@Override
|
@Override
|
||||||
public List<ChatConfigRichResp> getAllChatRichConfig() {
|
public List<ChatConfigRichResp> getAllChatRichConfig() {
|
||||||
List<ChatConfigRichResp> chatConfigRichInfoList = new ArrayList<>();
|
List<ChatConfigRichResp> chatConfigRichInfoList = new ArrayList<>();
|
||||||
List<ModelSchema> modelSchemas = semanticLayer.getModelSchema();
|
List<ModelSchema> modelSchemas = semanticInterpreter.getModelSchema();
|
||||||
modelSchemas.stream().forEach(modelSchema -> {
|
modelSchemas.stream().forEach(modelSchema -> {
|
||||||
ChatConfigRichResp chatConfigRichInfo = getConfigRichInfo(modelSchema.getModel().getId());
|
ChatConfigRichResp chatConfigRichInfo = getConfigRichInfo(modelSchema.getModel().getId());
|
||||||
if (Objects.nonNull(chatConfigRichInfo)) {
|
if (Objects.nonNull(chatConfigRichInfo)) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.tencent.supersonic.chat.service.impl;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.PluginQueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.PluginQueryReq;
|
||||||
import com.tencent.supersonic.chat.persistence.dataobject.PluginDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.PluginDO;
|
||||||
import com.tencent.supersonic.chat.persistence.dataobject.PluginDOExample;
|
import com.tencent.supersonic.chat.persistence.dataobject.PluginDOExample;
|
||||||
@@ -152,8 +152,8 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Plugin> authCheck(List<Plugin> plugins, User user) {
|
private List<Plugin> authCheck(List<Plugin> plugins, User user) {
|
||||||
SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
List<Long> modelIdAuthorized = semanticLayer.getModelList(AuthType.ADMIN, null, user).stream()
|
List<Long> modelIdAuthorized = semanticInterpreter.getModelList(AuthType.ADMIN, null, user).stream()
|
||||||
.map(ModelResp::getId).collect(Collectors.toList());
|
.map(ModelResp::getId).collect(Collectors.toList());
|
||||||
plugins = plugins.stream().filter(plugin -> {
|
plugins = plugins.stream().filter(plugin -> {
|
||||||
if (CollectionUtils.isEmpty(plugin.getModelList()) || plugin.isContainsAllModel()) {
|
if (CollectionUtils.isEmpty(plugin.getModelList()) || plugin.isContainsAllModel()) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package com.tencent.supersonic.chat.service.impl;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SchemaMapper;
|
import com.tencent.supersonic.chat.api.component.SchemaMapper;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
@@ -407,8 +407,8 @@ public class QueryServiceImpl implements QueryService {
|
|||||||
dimensionFilters.add(dimensionFilter);
|
dimensionFilters.add(dimensionFilter);
|
||||||
queryStructReq.setDimensionFilters(dimensionFilters);
|
queryStructReq.setDimensionFilters(dimensionFilters);
|
||||||
}
|
}
|
||||||
SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
QueryResultWithSchemaResp queryResultWithSchemaResp = semanticLayer.queryByStruct(queryStructReq, user);
|
QueryResultWithSchemaResp queryResultWithSchemaResp = semanticInterpreter.queryByStruct(queryStructReq, user);
|
||||||
Set<String> dimensionValues = new HashSet<>();
|
Set<String> dimensionValues = new HashSet<>();
|
||||||
queryResultWithSchemaResp.getResultList().removeIf(o -> {
|
queryResultWithSchemaResp.getResultList().removeIf(o -> {
|
||||||
if (dimensionValues.contains(o.get(dimensionValueReq.getBizName()))) {
|
if (dimensionValues.contains(o.get(dimensionValueReq.getBizName()))) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tencent.supersonic.chat.utils;
|
package com.tencent.supersonic.chat.utils;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SchemaMapper;
|
import com.tencent.supersonic.chat.api.component.SchemaMapper;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticCorrector;
|
import com.tencent.supersonic.chat.api.component.SemanticCorrector;
|
||||||
@@ -20,7 +20,7 @@ public class ComponentFactory {
|
|||||||
private static List<SemanticParser> semanticParsers = new ArrayList<>();
|
private static List<SemanticParser> semanticParsers = new ArrayList<>();
|
||||||
|
|
||||||
private static List<SemanticCorrector> dslCorrections = new ArrayList<>();
|
private static List<SemanticCorrector> dslCorrections = new ArrayList<>();
|
||||||
private static SemanticLayer semanticLayer;
|
private static SemanticInterpreter semanticInterpreter;
|
||||||
private static QuerySelector querySelector;
|
private static QuerySelector querySelector;
|
||||||
private static ModelResolver modelResolver;
|
private static ModelResolver modelResolver;
|
||||||
public static List<SchemaMapper> getSchemaMappers() {
|
public static List<SchemaMapper> getSchemaMappers() {
|
||||||
@@ -36,15 +36,15 @@ public class ComponentFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static SemanticLayer getSemanticLayer() {
|
public static SemanticInterpreter getSemanticLayer() {
|
||||||
if (Objects.isNull(semanticLayer)) {
|
if (Objects.isNull(semanticInterpreter)) {
|
||||||
semanticLayer = init(SemanticLayer.class);
|
semanticInterpreter = init(SemanticInterpreter.class);
|
||||||
}
|
}
|
||||||
return semanticLayer;
|
return semanticInterpreter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSemanticLayer(SemanticLayer layer) {
|
public static void setSemanticLayer(SemanticInterpreter layer) {
|
||||||
semanticLayer = layer;
|
semanticInterpreter = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QuerySelector getQuerySelector() {
|
public static QuerySelector getQuerySelector() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
|||||||
import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
|
import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeAdvancedConfig;
|
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeAdvancedConfig;
|
||||||
@@ -44,7 +44,7 @@ public class DictMetaHelper {
|
|||||||
private String internalMetricNameSuffix;
|
private String internalMetricNameSuffix;
|
||||||
@Value("${model.internal.day.number:2}")
|
@Value("${model.internal.day.number:2}")
|
||||||
private Integer internalMetricDays;
|
private Integer internalMetricDays;
|
||||||
private SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
public List<DimValueDO> generateDimValueInfo(DimValue2DictCommand dimValue2DictCommend) {
|
public List<DimValueDO> generateDimValueInfo(DimValue2DictCommand dimValue2DictCommend) {
|
||||||
List<DimValueDO> dimValueDOList = new ArrayList<>();
|
List<DimValueDO> dimValueDOList = new ArrayList<>();
|
||||||
@@ -56,7 +56,7 @@ public class DictMetaHelper {
|
|||||||
dimValueDOList = generateDimValueInfoByModel(modelIds);
|
dimValueDOList = generateDimValueInfoByModel(modelIds);
|
||||||
break;
|
break;
|
||||||
case OFFLINE_FULL:
|
case OFFLINE_FULL:
|
||||||
List<ModelSchema> modelSchemaDescList = semanticLayer.getModelSchema();
|
List<ModelSchema> modelSchemaDescList = semanticInterpreter.getModelSchema();
|
||||||
if (CollectionUtils.isEmpty(modelSchemaDescList)) {
|
if (CollectionUtils.isEmpty(modelSchemaDescList)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ public class DictMetaHelper {
|
|||||||
return dimValueDOList;
|
return dimValueDOList;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ModelSchema> modelSchemaDescList = semanticLayer.getModelSchema();
|
List<ModelSchema> modelSchemaDescList = semanticInterpreter.getModelSchema();
|
||||||
if (CollectionUtils.isEmpty(modelSchemaDescList)) {
|
if (CollectionUtils.isEmpty(modelSchemaDescList)) {
|
||||||
return dimValueDOList;
|
return dimValueDOList;
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public class DictMetaHelper {
|
|||||||
|
|
||||||
private List<DimValueDO> generateDimValueInfoByModel(Set<Long> modelIds) {
|
private List<DimValueDO> generateDimValueInfoByModel(Set<Long> modelIds) {
|
||||||
List<DimValueDO> dimValueDOList = new ArrayList<>();
|
List<DimValueDO> dimValueDOList = new ArrayList<>();
|
||||||
List<ModelSchema> modelSchemaDescList = semanticLayer.getModelSchema(new ArrayList<>(modelIds));
|
List<ModelSchema> modelSchemaDescList = semanticInterpreter.getModelSchema(new ArrayList<>(modelIds));
|
||||||
if (CollectionUtils.isEmpty(modelSchemaDescList)) {
|
if (CollectionUtils.isEmpty(modelSchemaDescList)) {
|
||||||
return dimValueDOList;
|
return dimValueDOList;
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ public class DictMetaHelper {
|
|||||||
private String queryDataSourceByDimId(Long id) {
|
private String queryDataSourceByDimId(Long id) {
|
||||||
PageDimensionReq pageDimensionCmd = new PageDimensionReq();
|
PageDimensionReq pageDimensionCmd = new PageDimensionReq();
|
||||||
pageDimensionCmd.setId(id.toString());
|
pageDimensionCmd.setId(id.toString());
|
||||||
PageInfo<DimensionResp> dimensionPage = semanticLayer.getDimensionPage(pageDimensionCmd);
|
PageInfo<DimensionResp> dimensionPage = semanticInterpreter.getDimensionPage(pageDimensionCmd);
|
||||||
if (Objects.nonNull(dimensionPage) && !CollectionUtils.isEmpty(dimensionPage.getList())) {
|
if (Objects.nonNull(dimensionPage) && !CollectionUtils.isEmpty(dimensionPage.getList())) {
|
||||||
List<DimensionResp> list = dimensionPage.getList();
|
List<DimensionResp> list = dimensionPage.getList();
|
||||||
return list.get(0).getDatasourceBizName();
|
return list.get(0).getDatasourceBizName();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tencent.supersonic.chat.utils;
|
package com.tencent.supersonic.chat.utils;
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.config.DefaultMetric;
|
import com.tencent.supersonic.chat.config.DefaultMetric;
|
||||||
import com.tencent.supersonic.chat.config.Dim4Dict;
|
import com.tencent.supersonic.chat.config.Dim4Dict;
|
||||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
@@ -40,7 +40,7 @@ import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE_DOUBLE;
|
|||||||
public class DictQueryHelper {
|
public class DictQueryHelper {
|
||||||
|
|
||||||
private static final Long MAX_FREQUENCY = 99999999L;
|
private static final Long MAX_FREQUENCY = 99999999L;
|
||||||
private SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
@Value("${dimension.multi.value.split:#}")
|
@Value("${dimension.multi.value.split:#}")
|
||||||
private String dimMultiValueSplit;
|
private String dimMultiValueSplit;
|
||||||
@Value("${dimension.value.show:50}")
|
@Value("${dimension.value.show:50}")
|
||||||
@@ -55,7 +55,7 @@ public class DictQueryHelper {
|
|||||||
List<String> data = new ArrayList<>();
|
List<String> data = new ArrayList<>();
|
||||||
QueryStructReq queryStructCmd = generateQueryStructCmd(modelId, defaultMetricDesc, dim4Dict);
|
QueryStructReq queryStructCmd = generateQueryStructCmd(modelId, defaultMetricDesc, dim4Dict);
|
||||||
try {
|
try {
|
||||||
QueryResultWithSchemaResp queryResultWithColumns = semanticLayer.queryByStruct(queryStructCmd, user);
|
QueryResultWithSchemaResp queryResultWithColumns = semanticInterpreter.queryByStruct(queryStructCmd, user);
|
||||||
log.info("fetchDimValueSingle sql:{}", queryResultWithColumns.getSql());
|
log.info("fetchDimValueSingle sql:{}", queryResultWithColumns.getSql());
|
||||||
String nature = String.format("_%d_%d", modelId, dim4Dict.getDimId());
|
String nature = String.format("_%d_%d", modelId, dim4Dict.getDimId());
|
||||||
String dimNameRewrite = rewriteDimName(queryResultWithColumns.getColumns(), dim4Dict.getBizName());
|
String dimNameRewrite = rewriteDimName(queryResultWithColumns.getColumns(), dim4Dict.getBizName());
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.chat.test.context;
|
|||||||
import com.tencent.supersonic.chat.persistence.repository.impl.ChatContextRepositoryImpl;
|
import com.tencent.supersonic.chat.persistence.repository.impl.ChatContextRepositoryImpl;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
import com.tencent.supersonic.chat.persistence.mapper.ChatContextMapper;
|
import com.tencent.supersonic.chat.persistence.mapper.ChatContextMapper;
|
||||||
import com.tencent.supersonic.knowledge.semantic.RemoteSemanticLayer;
|
import com.tencent.supersonic.knowledge.semantic.RemoteSemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.test.ChatBizLauncher;
|
import com.tencent.supersonic.chat.test.ChatBizLauncher;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||||
@@ -24,7 +24,7 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
@MockBean(ModelService.class)
|
@MockBean(ModelService.class)
|
||||||
@MockBean(ChatContextMapper.class)
|
@MockBean(ChatContextMapper.class)
|
||||||
@MockBean(RestTemplate.class)
|
@MockBean(RestTemplate.class)
|
||||||
@MockBean(RemoteSemanticLayer.class)
|
@MockBean(RemoteSemanticInterpreter.class)
|
||||||
@MockBean(ComponentFactory.class)
|
@MockBean(ComponentFactory.class)
|
||||||
//@MybatisTest
|
//@MybatisTest
|
||||||
//@AutoConfigureMybatis
|
//@AutoConfigureMybatis
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import static org.mockito.ArgumentMatchers.anyList;
|
|||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||||
import com.tencent.supersonic.chat.config.DefaultMetric;
|
import com.tencent.supersonic.chat.config.DefaultMetric;
|
||||||
import com.tencent.supersonic.chat.config.DefaultMetricInfo;
|
import com.tencent.supersonic.chat.config.DefaultMetricInfo;
|
||||||
@@ -41,8 +41,8 @@ public class MockBeansConfiguration {
|
|||||||
when(chatService.getOrCreateContext(1)).thenReturn(context);
|
when(chatService.getOrCreateContext(1)).thenReturn(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buildHttpSemanticServiceImpl(SemanticLayer httpSemanticLayer, List<DimSchemaResp> dimensionDescs,
|
public static void buildHttpSemanticServiceImpl(SemanticInterpreter httpSemanticInterpreter, List<DimSchemaResp> dimensionDescs,
|
||||||
List<MetricSchemaResp> metricDescs) {
|
List<MetricSchemaResp> metricDescs) {
|
||||||
DefaultMetric defaultMetricDesc = new DefaultMetric();
|
DefaultMetric defaultMetricDesc = new DefaultMetric();
|
||||||
defaultMetricDesc.setUnit(3);
|
defaultMetricDesc.setUnit(3);
|
||||||
defaultMetricDesc.setPeriod(Constants.DAY);
|
defaultMetricDesc.setPeriod(Constants.DAY);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.tencent.supersonic.knowledge.semantic;
|
|||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -14,7 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class BaseSemanticLayer implements SemanticLayer {
|
public abstract class BaseSemanticInterpreter implements SemanticInterpreter {
|
||||||
|
|
||||||
protected final Cache<String, List<ModelSchemaResp>> modelSchemaCache =
|
protected final Cache<String, List<ModelSchemaResp>> modelSchemaCache =
|
||||||
CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build();
|
CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build();
|
||||||
@@ -29,7 +29,7 @@ import lombok.SneakyThrows;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LocalSemanticLayer extends BaseSemanticLayer {
|
public class LocalSemanticInterpreter extends BaseSemanticInterpreter {
|
||||||
|
|
||||||
private SchemaService schemaService;
|
private SchemaService schemaService;
|
||||||
private DimensionService dimensionService;
|
private DimensionService dimensionService;
|
||||||
@@ -52,7 +52,7 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RemoteSemanticLayer extends BaseSemanticLayer {
|
public class RemoteSemanticInterpreter extends BaseSemanticInterpreter {
|
||||||
|
|
||||||
private S2ThreadContext s2ThreadContext;
|
private S2ThreadContext s2ThreadContext;
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.knowledge.service;
|
|||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import com.tencent.supersonic.knowledge.utils.ComponentFactory;
|
import com.tencent.supersonic.knowledge.utils.ComponentFactory;
|
||||||
@@ -19,7 +19,7 @@ public class SchemaService {
|
|||||||
|
|
||||||
public static final String ALL_CACHE = "all";
|
public static final String ALL_CACHE = "all";
|
||||||
private static final Integer META_CACHE_TIME = 2;
|
private static final Integer META_CACHE_TIME = 2;
|
||||||
private SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
private LoadingCache<String, SemanticSchema> cache = CacheBuilder.newBuilder()
|
private LoadingCache<String, SemanticSchema> cache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(META_CACHE_TIME, TimeUnit.MINUTES)
|
.expireAfterWrite(META_CACHE_TIME, TimeUnit.MINUTES)
|
||||||
@@ -28,13 +28,13 @@ public class SchemaService {
|
|||||||
@Override
|
@Override
|
||||||
public SemanticSchema load(String key) {
|
public SemanticSchema load(String key) {
|
||||||
log.info("load getDomainSchemaInfo cache [{}]", key);
|
log.info("load getDomainSchemaInfo cache [{}]", key);
|
||||||
return new SemanticSchema(semanticLayer.getModelSchema());
|
return new SemanticSchema(semanticInterpreter.getModelSchema());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
public ModelSchema getModelSchema(Long id) {
|
public ModelSchema getModelSchema(Long id) {
|
||||||
return semanticLayer.getModelSchema(id, true);
|
return semanticInterpreter.getModelSchema(id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SemanticSchema getSemanticSchema() {
|
public SemanticSchema getSemanticSchema() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.knowledge.service;
|
package com.tencent.supersonic.knowledge.service;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
||||||
@@ -22,8 +22,8 @@ public class WordService {
|
|||||||
private List<DictWord> preDictWords = new ArrayList<>();
|
private List<DictWord> preDictWords = new ArrayList<>();
|
||||||
|
|
||||||
public List<DictWord> getAllDictWords() {
|
public List<DictWord> getAllDictWords() {
|
||||||
SemanticLayer semanticLayer = ComponentFactory.getSemanticLayer();
|
SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
SemanticSchema semanticSchema = new SemanticSchema(semanticLayer.getModelSchema());
|
SemanticSchema semanticSchema = new SemanticSchema(semanticInterpreter.getModelSchema());
|
||||||
|
|
||||||
List<DictWord> words = new ArrayList<>();
|
List<DictWord> words = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.knowledge.utils;
|
package com.tencent.supersonic.knowledge.utils;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticLayer;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -8,17 +8,17 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class ComponentFactory {
|
public class ComponentFactory {
|
||||||
|
|
||||||
private static SemanticLayer semanticLayer;
|
private static SemanticInterpreter semanticInterpreter;
|
||||||
|
|
||||||
public static SemanticLayer getSemanticLayer() {
|
public static SemanticInterpreter getSemanticLayer() {
|
||||||
if (Objects.isNull(semanticLayer)) {
|
if (Objects.isNull(semanticInterpreter)) {
|
||||||
semanticLayer = init(SemanticLayer.class);
|
semanticInterpreter = init(SemanticInterpreter.class);
|
||||||
}
|
}
|
||||||
return semanticLayer;
|
return semanticInterpreter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSemanticLayer(SemanticLayer layer) {
|
public static void setSemanticLayer(SemanticInterpreter layer) {
|
||||||
semanticLayer = layer;
|
semanticInterpreter = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> List<T> init(Class<T> factoryType, List list) {
|
private static <T> List<T> init(Class<T> factoryType, List list) {
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 233 KiB After Width: | Height: | Size: 232 KiB |
@@ -14,8 +14,8 @@ com.tencent.supersonic.chat.api.component.SemanticParser=\
|
|||||||
com.tencent.supersonic.chat.parser.plugin.function.FunctionBasedParser
|
com.tencent.supersonic.chat.parser.plugin.function.FunctionBasedParser
|
||||||
|
|
||||||
|
|
||||||
com.tencent.supersonic.chat.api.component.SemanticLayer=\
|
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
|
||||||
com.tencent.supersonic.knowledge.semantic.RemoteSemanticLayer
|
com.tencent.supersonic.knowledge.semantic.RemoteSemanticInterpreter
|
||||||
|
|
||||||
com.tencent.supersonic.chat.query.QuerySelector=\
|
com.tencent.supersonic.chat.query.QuerySelector=\
|
||||||
com.tencent.supersonic.chat.query.HeuristicQuerySelector
|
com.tencent.supersonic.chat.query.HeuristicQuerySelector
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ com.tencent.supersonic.chat.api.component.SemanticParser=\
|
|||||||
com.tencent.supersonic.chat.parser.plugin.function.FunctionBasedParser
|
com.tencent.supersonic.chat.parser.plugin.function.FunctionBasedParser
|
||||||
|
|
||||||
|
|
||||||
com.tencent.supersonic.chat.api.component.SemanticLayer=\
|
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
|
||||||
com.tencent.supersonic.knowledge.semantic.LocalSemanticLayer
|
com.tencent.supersonic.knowledge.semantic.LocalSemanticInterpreter
|
||||||
|
|
||||||
com.tencent.supersonic.chat.query.QuerySelector=\
|
com.tencent.supersonic.chat.query.QuerySelector=\
|
||||||
com.tencent.supersonic.chat.query.HeuristicQuerySelector
|
com.tencent.supersonic.chat.query.HeuristicQuerySelector
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ com.tencent.supersonic.chat.api.component.SemanticParser=\
|
|||||||
com.tencent.supersonic.chat.api.component.QueryProcessor=\
|
com.tencent.supersonic.chat.api.component.QueryProcessor=\
|
||||||
com.tencent.supersonic.chat.application.processor.SemanticQueryProcessor
|
com.tencent.supersonic.chat.application.processor.SemanticQueryProcessor
|
||||||
|
|
||||||
com.tencent.supersonic.chat.api.component.SemanticLayer=\
|
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
|
||||||
com.tencent.supersonic.knowledge.semantic.LocalSemanticLayer
|
com.tencent.supersonic.knowledge.semantic.LocalSemanticInterpreter
|
||||||
|
|
||||||
com.tencent.supersonic.chat.query.QuerySelector=\
|
com.tencent.supersonic.chat.query.QuerySelector=\
|
||||||
com.tencent.supersonic.chat.query.HeuristicQuerySelector
|
com.tencent.supersonic.chat.query.HeuristicQuerySelector
|
||||||
|
|||||||
Reference in New Issue
Block a user