From 2f0ac2baf884c541baf898cce4991263f6f2ad90 Mon Sep 17 00:00:00 2001 From: LXW <1264174498@qq.com> Date: Mon, 1 Jul 2024 18:56:53 +0800 Subject: [PATCH] (improvement)(chat) add chat plugin webservice demo (#1317) Co-authored-by: lxwcodemonkey --- .../annotation}/AuthenticationIgnore.java | 2 +- .../DefaultAuthenticationInterceptor.java | 1 + .../plugin/build/PluginSemanticQuery.java | 2 +- .../build/webservice/WebServiceQuery.java | 5 ++-- .../chat/server/rest/PluginController.java | 18 ++++++++++--- .../service/impl/DimensionServiceImpl.java | 3 +++ .../tencent/supersonic/demo/S2VisitsDemo.java | 25 +++++++++++++++++-- 7 files changed, 46 insertions(+), 10 deletions(-) rename auth/{authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor => api/src/main/java/com/tencent/supersonic/auth/api/authentication/annotation}/AuthenticationIgnore.java (80%) diff --git a/auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/AuthenticationIgnore.java b/auth/api/src/main/java/com/tencent/supersonic/auth/api/authentication/annotation/AuthenticationIgnore.java similarity index 80% rename from auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/AuthenticationIgnore.java rename to auth/api/src/main/java/com/tencent/supersonic/auth/api/authentication/annotation/AuthenticationIgnore.java index 4223c54f6..afdb74b12 100644 --- a/auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/AuthenticationIgnore.java +++ b/auth/api/src/main/java/com/tencent/supersonic/auth/api/authentication/annotation/AuthenticationIgnore.java @@ -1,4 +1,4 @@ -package com.tencent.supersonic.auth.authentication.interceptor; +package com.tencent.supersonic.auth.api.authentication.annotation; import java.lang.annotation.ElementType; diff --git a/auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/DefaultAuthenticationInterceptor.java b/auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/DefaultAuthenticationInterceptor.java index e3d1cd74d..069b2dd04 100644 --- a/auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/DefaultAuthenticationInterceptor.java +++ b/auth/authentication/src/main/java/com/tencent/supersonic/auth/authentication/interceptor/DefaultAuthenticationInterceptor.java @@ -1,6 +1,7 @@ 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.pojo.User; import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword; diff --git a/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/PluginSemanticQuery.java b/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/PluginSemanticQuery.java index 6ff6321a0..6934adc62 100644 --- a/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/PluginSemanticQuery.java +++ b/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/PluginSemanticQuery.java @@ -75,7 +75,7 @@ protected WebBase fillWebBaseResult(WebBase webPage, PluginParseResult pluginPar webBaseResult.setUrl(webPage.getUrl()); Map elementValueMap = getElementMap(pluginParseResult); List paramOptions = Lists.newArrayList(); - if (!CollectionUtils.isEmpty(webPage.getParamOptions()) && !CollectionUtils.isEmpty(elementValueMap)) { + if (!CollectionUtils.isEmpty(webPage.getParamOptions())) { for (ParamOption paramOption : webPage.getParamOptions()) { if (paramOption.getDataSetId() != null && !parseInfo.getDataSetId().equals(paramOption.getDataSetId())) { diff --git a/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/webservice/WebServiceQuery.java b/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/webservice/WebServiceQuery.java index 16b761ba3..127416eba 100644 --- a/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/webservice/WebServiceQuery.java +++ b/chat/server/src/main/java/com/tencent/supersonic/chat/server/plugin/build/webservice/WebServiceQuery.java @@ -61,7 +61,7 @@ public QueryResult build() { if (data.get("columns") != null) { queryResult.setQueryColumns((List) data.get("columns")); } - queryResult.setTextResult(String.valueOf(data.get("textInfo"))); + queryResult.setTextResult(String.valueOf(data.get("data"))); queryResult.setQueryState(QueryState.SUCCESS); } catch (Exception e) { log.info("webServiceResponse result has an exception:{}", e.getMessage()); @@ -80,7 +80,8 @@ protected WebServiceResp buildResponse(PluginParseResult pluginParseResult) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity 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; Object objectResponse = null; restTemplate = ContextUtils.getBean(RestTemplate.class); diff --git a/chat/server/src/main/java/com/tencent/supersonic/chat/server/rest/PluginController.java b/chat/server/src/main/java/com/tencent/supersonic/chat/server/rest/PluginController.java index 51ff49426..96717c2e5 100644 --- a/chat/server/src/main/java/com/tencent/supersonic/chat/server/rest/PluginController.java +++ b/chat/server/src/main/java/com/tencent/supersonic/chat/server/rest/PluginController.java @@ -1,18 +1,21 @@ 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.utils.UserHolder; import com.tencent.supersonic.chat.api.pojo.request.PluginQueryReq; import com.tencent.supersonic.chat.server.plugin.ChatPlugin; import com.tencent.supersonic.chat.server.service.PluginService; 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.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.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -61,4 +64,11 @@ List query(@RequestBody PluginQueryReq pluginQueryReq, return pluginService.queryWithAuthCheck(pluginQueryReq, user); } + @AuthenticationIgnore + @PostMapping("/pluginDemo") + public String pluginDemo(@RequestParam("queryText") String queryText, + @RequestBody Object object) { + return String.format("已收到您的问题:%s, 但这只是一个demo~", queryText); + } + } diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/web/service/impl/DimensionServiceImpl.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/web/service/impl/DimensionServiceImpl.java index 6ef965eaf..14b1d30f0 100644 --- a/headless/server/src/main/java/com/tencent/supersonic/headless/server/web/service/impl/DimensionServiceImpl.java +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/web/service/impl/DimensionServiceImpl.java @@ -182,6 +182,9 @@ public void batchUpdateStatus(MetaBatchReq metaBatchReq, User user) { @Override public void batchUpdateSensitiveLevel(MetaBatchReq metaBatchReq, User user) { + if (CollectionUtils.isEmpty(metaBatchReq.getIds())) { + return; + } DimensionFilter metaFilter = new DimensionFilter(); metaFilter.setIds(metaBatchReq.getIds()); List dimensionDOS = queryDimension(metaFilter); diff --git a/launchers/standalone/src/main/java/com/tencent/supersonic/demo/S2VisitsDemo.java b/launchers/standalone/src/main/java/com/tencent/supersonic/demo/S2VisitsDemo.java index 111aca95b..5600218e4 100644 --- a/launchers/standalone/src/main/java/com/tencent/supersonic/demo/S2VisitsDemo.java +++ b/launchers/standalone/src/main/java/com/tencent/supersonic/demo/S2VisitsDemo.java @@ -14,6 +14,8 @@ import com.tencent.supersonic.chat.server.plugin.ChatPlugin; 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.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.ModelRela; import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum; @@ -105,6 +107,7 @@ public void doRun() { addTerm(s2Domain); addTerm_1(s2Domain); addPlugin(s2DataSet); + addPlugin_1(); //load dict word loadDictWord(); @@ -504,8 +507,8 @@ public void addAuthGroup_2(ModelResp stayTimeModel) { private void addPlugin(DataSetResp s2DataSet) { ChatPlugin plugin1 = new ChatPlugin(); - plugin1.setType("WEB_PAGE"); - plugin1.setDataSetList(Arrays.asList(s2DataSet.getId())); + plugin1.setType(WebPageQuery.QUERY_MODE); + plugin1.setDataSetList(Collections.singletonList(s2DataSet.getId())); plugin1.setPattern("用于分析超音数的流量概况,包含UV、PV等核心指标的追踪。P.S. 仅作为示例展示,无实际看板"); plugin1.setName("超音数流量分析看板"); PluginParseConfig pluginParseConfig = new PluginParseConfig(); @@ -520,6 +523,24 @@ private void addPlugin(DataSetResp s2DataSet) { 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 { TagObjectReq tagObjectReq = new TagObjectReq(); tagObjectReq.setDomainId(s2Domain.getId());