mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(improvement)(chat) add chat plugin webservice demo (#1317)
Co-authored-by: lxwcodemonkey
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package com.tencent.supersonic.auth.authentication.interceptor;
|
package com.tencent.supersonic.auth.api.authentication.annotation;
|
||||||
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.tencent.supersonic.auth.authentication.interceptor;
|
package com.tencent.supersonic.auth.authentication.interceptor;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tencent.supersonic.auth.api.authentication.annotation.AuthenticationIgnore;
|
||||||
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
|
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
|
||||||
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.pojo.UserWithPassword;
|
import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public abstract class PluginSemanticQuery {
|
|||||||
webBaseResult.setUrl(webPage.getUrl());
|
webBaseResult.setUrl(webPage.getUrl());
|
||||||
Map<String, Object> elementValueMap = getElementMap(pluginParseResult);
|
Map<String, Object> elementValueMap = getElementMap(pluginParseResult);
|
||||||
List<ParamOption> paramOptions = Lists.newArrayList();
|
List<ParamOption> paramOptions = Lists.newArrayList();
|
||||||
if (!CollectionUtils.isEmpty(webPage.getParamOptions()) && !CollectionUtils.isEmpty(elementValueMap)) {
|
if (!CollectionUtils.isEmpty(webPage.getParamOptions())) {
|
||||||
for (ParamOption paramOption : webPage.getParamOptions()) {
|
for (ParamOption paramOption : webPage.getParamOptions()) {
|
||||||
if (paramOption.getDataSetId() != null
|
if (paramOption.getDataSetId() != null
|
||||||
&& !parseInfo.getDataSetId().equals(paramOption.getDataSetId())) {
|
&& !parseInfo.getDataSetId().equals(paramOption.getDataSetId())) {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class WebServiceQuery extends PluginSemanticQuery {
|
|||||||
if (data.get("columns") != null) {
|
if (data.get("columns") != null) {
|
||||||
queryResult.setQueryColumns((List<QueryColumn>) data.get("columns"));
|
queryResult.setQueryColumns((List<QueryColumn>) data.get("columns"));
|
||||||
}
|
}
|
||||||
queryResult.setTextResult(String.valueOf(data.get("textInfo")));
|
queryResult.setTextResult(String.valueOf(data.get("data")));
|
||||||
queryResult.setQueryState(QueryState.SUCCESS);
|
queryResult.setQueryState(QueryState.SUCCESS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("webServiceResponse result has an exception:{}", e.getMessage());
|
log.info("webServiceResponse result has an exception:{}", e.getMessage());
|
||||||
@@ -80,7 +80,8 @@ public class WebServiceQuery extends PluginSemanticQuery {
|
|||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(params), headers);
|
HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(params), headers);
|
||||||
URI requestUrl = UriComponentsBuilder.fromHttpUrl(webBase.getUrl()).build().encode().toUri();
|
String url = webBase.getUrl() + "?queryText=" + pluginParseResult.getQueryText();
|
||||||
|
URI requestUrl = UriComponentsBuilder.fromHttpUrl(url).build().encode().toUri();
|
||||||
ResponseEntity responseEntity = null;
|
ResponseEntity responseEntity = null;
|
||||||
Object objectResponse = null;
|
Object objectResponse = null;
|
||||||
restTemplate = ContextUtils.getBean(RestTemplate.class);
|
restTemplate = ContextUtils.getBean(RestTemplate.class);
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
package com.tencent.supersonic.chat.server.rest;
|
package com.tencent.supersonic.chat.server.rest;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.auth.api.authentication.annotation.AuthenticationIgnore;
|
||||||
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.pojo.request.PluginQueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.PluginQueryReq;
|
||||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import com.tencent.supersonic.chat.server.service.PluginService;
|
import com.tencent.supersonic.chat.server.service.PluginService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -61,4 +64,11 @@ public class PluginController {
|
|||||||
return pluginService.queryWithAuthCheck(pluginQueryReq, user);
|
return pluginService.queryWithAuthCheck(pluginQueryReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AuthenticationIgnore
|
||||||
|
@PostMapping("/pluginDemo")
|
||||||
|
public String pluginDemo(@RequestParam("queryText") String queryText,
|
||||||
|
@RequestBody Object object) {
|
||||||
|
return String.format("已收到您的问题:%s, 但这只是一个demo~", queryText);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,9 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void batchUpdateSensitiveLevel(MetaBatchReq metaBatchReq, User user) {
|
public void batchUpdateSensitiveLevel(MetaBatchReq metaBatchReq, User user) {
|
||||||
|
if (CollectionUtils.isEmpty(metaBatchReq.getIds())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
DimensionFilter metaFilter = new DimensionFilter();
|
DimensionFilter metaFilter = new DimensionFilter();
|
||||||
metaFilter.setIds(metaBatchReq.getIds());
|
metaFilter.setIds(metaBatchReq.getIds());
|
||||||
List<DimensionDO> dimensionDOS = queryDimension(metaFilter);
|
List<DimensionDO> dimensionDOS = queryDimension(metaFilter);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import com.tencent.supersonic.chat.server.agent.RuleParserTool;
|
|||||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginParseConfig;
|
import com.tencent.supersonic.chat.server.plugin.PluginParseConfig;
|
||||||
import com.tencent.supersonic.chat.server.plugin.build.WebBase;
|
import com.tencent.supersonic.chat.server.plugin.build.WebBase;
|
||||||
|
import com.tencent.supersonic.chat.server.plugin.build.webpage.WebPageQuery;
|
||||||
|
import com.tencent.supersonic.chat.server.plugin.build.webservice.WebServiceQuery;
|
||||||
import com.tencent.supersonic.common.pojo.JoinCondition;
|
import com.tencent.supersonic.common.pojo.JoinCondition;
|
||||||
import com.tencent.supersonic.common.pojo.ModelRela;
|
import com.tencent.supersonic.common.pojo.ModelRela;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||||
@@ -105,6 +107,7 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
addTerm(s2Domain);
|
addTerm(s2Domain);
|
||||||
addTerm_1(s2Domain);
|
addTerm_1(s2Domain);
|
||||||
addPlugin(s2DataSet);
|
addPlugin(s2DataSet);
|
||||||
|
addPlugin_1();
|
||||||
|
|
||||||
//load dict word
|
//load dict word
|
||||||
loadDictWord();
|
loadDictWord();
|
||||||
@@ -504,8 +507,8 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
|
|
||||||
private void addPlugin(DataSetResp s2DataSet) {
|
private void addPlugin(DataSetResp s2DataSet) {
|
||||||
ChatPlugin plugin1 = new ChatPlugin();
|
ChatPlugin plugin1 = new ChatPlugin();
|
||||||
plugin1.setType("WEB_PAGE");
|
plugin1.setType(WebPageQuery.QUERY_MODE);
|
||||||
plugin1.setDataSetList(Arrays.asList(s2DataSet.getId()));
|
plugin1.setDataSetList(Collections.singletonList(s2DataSet.getId()));
|
||||||
plugin1.setPattern("用于分析超音数的流量概况,包含UV、PV等核心指标的追踪。P.S. 仅作为示例展示,无实际看板");
|
plugin1.setPattern("用于分析超音数的流量概况,包含UV、PV等核心指标的追踪。P.S. 仅作为示例展示,无实际看板");
|
||||||
plugin1.setName("超音数流量分析看板");
|
plugin1.setName("超音数流量分析看板");
|
||||||
PluginParseConfig pluginParseConfig = new PluginParseConfig();
|
PluginParseConfig pluginParseConfig = new PluginParseConfig();
|
||||||
@@ -520,6 +523,24 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
pluginService.createPlugin(plugin1, user);
|
pluginService.createPlugin(plugin1, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addPlugin_1() {
|
||||||
|
ChatPlugin plugin1 = new ChatPlugin();
|
||||||
|
plugin1.setType(WebServiceQuery.QUERY_MODE);
|
||||||
|
plugin1.setDataSetList(Collections.singletonList(-1L));
|
||||||
|
plugin1.setPattern("用于分析超音数的流量概况,包含UV、PV等核心指标的追踪。P.S. 仅作为示例展示,无实际内容");
|
||||||
|
plugin1.setName("超音数流量分析小助手");
|
||||||
|
PluginParseConfig pluginParseConfig = new PluginParseConfig();
|
||||||
|
pluginParseConfig.setDescription(plugin1.getPattern());
|
||||||
|
pluginParseConfig.setName(plugin1.getName());
|
||||||
|
pluginParseConfig.setExamples(Lists.newArrayList("tom最近访问超音数情况怎么样"));
|
||||||
|
plugin1.setParseModeConfig(JSONObject.toJSONString(pluginParseConfig));
|
||||||
|
WebBase webBase = new WebBase();
|
||||||
|
webBase.setUrl("http://localhost:9080/api/chat/plugin/pluginDemo");
|
||||||
|
webBase.setParamOptions(Lists.newArrayList());
|
||||||
|
plugin1.setConfig(JsonUtil.toString(webBase));
|
||||||
|
pluginService.createPlugin(plugin1, user);
|
||||||
|
}
|
||||||
|
|
||||||
private TagObjectResp addTagObjectUser(DomainResp s2Domain) throws Exception {
|
private TagObjectResp addTagObjectUser(DomainResp s2Domain) throws Exception {
|
||||||
TagObjectReq tagObjectReq = new TagObjectReq();
|
TagObjectReq tagObjectReq = new TagObjectReq();
|
||||||
tagObjectReq.setDomainId(s2Domain.getId());
|
tagObjectReq.setDomainId(s2Domain.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user