Skip to content

Commit

Permalink
(improvement)(chat) add chat plugin webservice demo (#1317)
Browse files Browse the repository at this point in the history
Co-authored-by: lxwcodemonkey
  • Loading branch information
lxwcodemonkey committed Jul 1, 2024
1 parent 0226ebf commit 2f0ac2b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.interceptor;
package com.tencent.supersonic.auth.api.authentication.annotation;


import java.lang.annotation.ElementType;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected WebBase fillWebBaseResult(WebBase webPage, PluginParseResult pluginPar
webBaseResult.setUrl(webPage.getUrl());
Map<String, Object> elementValueMap = getElementMap(pluginParseResult);
List<ParamOption> 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public QueryResult build() {
if (data.get("columns") != null) {
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);
} catch (Exception e) {
log.info("webServiceResponse result has an exception:{}", e.getMessage());
Expand All @@ -80,7 +80,8 @@ protected WebServiceResp buildResponse(PluginParseResult pluginParseResult) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
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;
Object objectResponse = null;
restTemplate = ContextUtils.getBean(RestTemplate.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -61,4 +64,11 @@ List<ChatPlugin> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DimensionDO> dimensionDOS = queryDimension(metaFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,6 +107,7 @@ public void doRun() {
addTerm(s2Domain);
addTerm_1(s2Domain);
addPlugin(s2DataSet);
addPlugin_1();

//load dict word
loadDictWord();
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down

0 comments on commit 2f0ac2b

Please sign in to comment.