mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvement)(Chat) Add encryption and decryption for llm api key (#1267)
* (improvement)(Chat) Add encryption and decryption for llm api key * (improvement)(Chat) Change Plugin to ChatPlugin --------- Co-authored-by: lxwcodemonkey
This commit is contained in:
@@ -10,7 +10,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Plugin extends RecordInfo {
|
public class ChatPlugin extends RecordInfo {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@@ -52,10 +52,10 @@ public class PluginManager {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmbeddingService embeddingService;
|
private EmbeddingService embeddingService;
|
||||||
|
|
||||||
public static List<Plugin> getPluginAgentCanSupport(ChatParseContext chatParseContext) {
|
public static List<ChatPlugin> getPluginAgentCanSupport(ChatParseContext chatParseContext) {
|
||||||
PluginService pluginService = ContextUtils.getBean(PluginService.class);
|
PluginService pluginService = ContextUtils.getBean(PluginService.class);
|
||||||
Agent agent = chatParseContext.getAgent();
|
Agent agent = chatParseContext.getAgent();
|
||||||
List<Plugin> plugins = pluginService.getPluginList();
|
List<ChatPlugin> plugins = pluginService.getPluginList();
|
||||||
if (Objects.isNull(agent)) {
|
if (Objects.isNull(agent)) {
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ public class PluginManager {
|
|||||||
plugins = plugins.stream().filter(plugin -> pluginIds.contains(plugin.getId()))
|
plugins = plugins.stream().filter(plugin -> pluginIds.contains(plugin.getId()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
log.info("plugins witch can be supported by cur agent :{} {}", agent.getName(),
|
log.info("plugins witch can be supported by cur agent :{} {}", agent.getName(),
|
||||||
plugins.stream().map(Plugin::getName).collect(Collectors.toList()));
|
plugins.stream().map(ChatPlugin::getName).collect(Collectors.toList()));
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public class PluginManager {
|
|||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
public void addPlugin(PluginAddEvent pluginAddEvent) {
|
public void addPlugin(PluginAddEvent pluginAddEvent) {
|
||||||
Plugin plugin = pluginAddEvent.getPlugin();
|
ChatPlugin plugin = pluginAddEvent.getPlugin();
|
||||||
if (CollectionUtils.isNotEmpty(plugin.getExampleQuestionList())) {
|
if (CollectionUtils.isNotEmpty(plugin.getExampleQuestionList())) {
|
||||||
requestEmbeddingPluginAdd(convert(Lists.newArrayList(plugin)));
|
requestEmbeddingPluginAdd(convert(Lists.newArrayList(plugin)));
|
||||||
}
|
}
|
||||||
@@ -93,8 +93,8 @@ public class PluginManager {
|
|||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
public void updatePlugin(PluginUpdateEvent pluginUpdateEvent) {
|
public void updatePlugin(PluginUpdateEvent pluginUpdateEvent) {
|
||||||
Plugin oldPlugin = pluginUpdateEvent.getOldPlugin();
|
ChatPlugin oldPlugin = pluginUpdateEvent.getOldPlugin();
|
||||||
Plugin newPlugin = pluginUpdateEvent.getNewPlugin();
|
ChatPlugin newPlugin = pluginUpdateEvent.getNewPlugin();
|
||||||
if (CollectionUtils.isNotEmpty(oldPlugin.getExampleQuestionList())) {
|
if (CollectionUtils.isNotEmpty(oldPlugin.getExampleQuestionList())) {
|
||||||
requestEmbeddingPluginDelete(getEmbeddingId(Lists.newArrayList(oldPlugin)));
|
requestEmbeddingPluginDelete(getEmbeddingId(Lists.newArrayList(oldPlugin)));
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ public class PluginManager {
|
|||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
public void delPlugin(PluginDelEvent pluginDelEvent) {
|
public void delPlugin(PluginDelEvent pluginDelEvent) {
|
||||||
Plugin plugin = pluginDelEvent.getPlugin();
|
ChatPlugin plugin = pluginDelEvent.getPlugin();
|
||||||
if (CollectionUtils.isNotEmpty(plugin.getExampleQuestionList())) {
|
if (CollectionUtils.isNotEmpty(plugin.getExampleQuestionList())) {
|
||||||
requestEmbeddingPluginDelete(getEmbeddingId(Lists.newArrayList(plugin)));
|
requestEmbeddingPluginDelete(getEmbeddingId(Lists.newArrayList(plugin)));
|
||||||
}
|
}
|
||||||
@@ -155,9 +155,9 @@ public class PluginManager {
|
|||||||
throw new RuntimeException("get embedding result failed");
|
throw new RuntimeException("get embedding result failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TextSegment> convert(List<Plugin> plugins) {
|
public List<TextSegment> convert(List<ChatPlugin> plugins) {
|
||||||
List<TextSegment> queries = Lists.newArrayList();
|
List<TextSegment> queries = Lists.newArrayList();
|
||||||
for (Plugin plugin : plugins) {
|
for (ChatPlugin plugin : plugins) {
|
||||||
List<String> exampleQuestions = plugin.getExampleQuestionList();
|
List<String> exampleQuestions = plugin.getExampleQuestionList();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (String pattern : exampleQuestions) {
|
for (String pattern : exampleQuestions) {
|
||||||
@@ -170,7 +170,7 @@ public class PluginManager {
|
|||||||
return queries;
|
return queries;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getEmbeddingId(List<Plugin> plugins) {
|
private Set<String> getEmbeddingId(List<ChatPlugin> plugins) {
|
||||||
Set<String> embeddingIdSet = new HashSet<>();
|
Set<String> embeddingIdSet = new HashSet<>();
|
||||||
for (TextSegment query : convert(plugins)) {
|
for (TextSegment query : convert(plugins)) {
|
||||||
TextSegmentConvert.addQueryId(query, TextSegmentConvert.getQueryId(query));
|
TextSegmentConvert.addQueryId(query, TextSegmentConvert.getQueryId(query));
|
||||||
@@ -191,7 +191,7 @@ public class PluginManager {
|
|||||||
return String.valueOf(Integer.parseInt(id) / 1000);
|
return String.valueOf(Integer.parseInt(id) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Pair<Boolean, Set<Long>> resolve(Plugin plugin, ChatParseContext chatParseContext) {
|
public static Pair<Boolean, Set<Long>> resolve(ChatPlugin plugin, ChatParseContext chatParseContext) {
|
||||||
SchemaMapInfo schemaMapInfo = chatParseContext.getMapInfo();
|
SchemaMapInfo schemaMapInfo = chatParseContext.getMapInfo();
|
||||||
Set<Long> pluginMatchedModel = getPluginMatchedModel(plugin, chatParseContext);
|
Set<Long> pluginMatchedModel = getPluginMatchedModel(plugin, chatParseContext);
|
||||||
if (CollectionUtils.isEmpty(pluginMatchedModel) && !plugin.isContainsAllModel()) {
|
if (CollectionUtils.isEmpty(pluginMatchedModel) && !plugin.isContainsAllModel()) {
|
||||||
@@ -245,7 +245,7 @@ public class PluginManager {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ParamOption> getSemanticOption(Plugin plugin) {
|
private static List<ParamOption> getSemanticOption(ChatPlugin plugin) {
|
||||||
WebBase webBase = JSONObject.parseObject(plugin.getConfig(), WebBase.class);
|
WebBase webBase = JSONObject.parseObject(plugin.getConfig(), WebBase.class);
|
||||||
if (Objects.isNull(webBase)) {
|
if (Objects.isNull(webBase)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -259,7 +259,7 @@ public class PluginManager {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<Long> getPluginMatchedModel(Plugin plugin, ChatParseContext chatParseContext) {
|
private static Set<Long> getPluginMatchedModel(ChatPlugin plugin, ChatParseContext chatParseContext) {
|
||||||
Set<Long> matchedDataSets = chatParseContext.getMapInfo().getMatchedDataSetInfos();
|
Set<Long> matchedDataSets = chatParseContext.getMapInfo().getMatchedDataSetInfos();
|
||||||
if (plugin.isContainsAllModel()) {
|
if (plugin.isContainsAllModel()) {
|
||||||
return Sets.newHashSet(plugin.getDefaultMode());
|
return Sets.newHashSet(plugin.getDefaultMode());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class PluginParseResult {
|
public class PluginParseResult {
|
||||||
|
|
||||||
private Plugin plugin;
|
private ChatPlugin plugin;
|
||||||
private QueryFilters queryFilters;
|
private QueryFilters queryFilters;
|
||||||
private double distance;
|
private double distance;
|
||||||
private String queryText;
|
private String queryText;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.Set;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class PluginRecallResult {
|
public class PluginRecallResult {
|
||||||
|
|
||||||
private Plugin plugin;
|
private ChatPlugin plugin;
|
||||||
|
|
||||||
private Set<Long> dataSetIds;
|
private Set<Long> dataSetIds;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.chat.server.plugin.build.webpage;
|
package com.tencent.supersonic.chat.server.plugin.build.webpage;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
||||||
import com.tencent.supersonic.chat.server.plugin.build.PluginSemanticQuery;
|
import com.tencent.supersonic.chat.server.plugin.build.PluginSemanticQuery;
|
||||||
@@ -25,7 +25,7 @@ public class WebPageQuery extends PluginSemanticQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected WebPageResp buildResponse(PluginParseResult pluginParseResult) {
|
protected WebPageResp buildResponse(PluginParseResult pluginParseResult) {
|
||||||
Plugin plugin = pluginParseResult.getPlugin();
|
ChatPlugin plugin = pluginParseResult.getPlugin();
|
||||||
WebPageResp webPageResponse = new WebPageResp();
|
WebPageResp webPageResponse = new WebPageResp();
|
||||||
webPageResponse.setName(plugin.getName());
|
webPageResponse.setName(plugin.getName());
|
||||||
webPageResponse.setPluginId(plugin.getId());
|
webPageResponse.setPluginId(plugin.getId());
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tencent.supersonic.chat.server.plugin.build.webservice;
|
package com.tencent.supersonic.chat.server.plugin.build.webservice;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
||||||
import com.tencent.supersonic.chat.server.plugin.build.ParamOption;
|
import com.tencent.supersonic.chat.server.plugin.build.ParamOption;
|
||||||
@@ -71,7 +71,7 @@ public class WebServiceQuery extends PluginSemanticQuery {
|
|||||||
|
|
||||||
protected WebServiceResp buildResponse(PluginParseResult pluginParseResult) {
|
protected WebServiceResp buildResponse(PluginParseResult pluginParseResult) {
|
||||||
WebServiceResp webServiceResponse = new WebServiceResp();
|
WebServiceResp webServiceResponse = new WebServiceResp();
|
||||||
Plugin plugin = pluginParseResult.getPlugin();
|
ChatPlugin plugin = pluginParseResult.getPlugin();
|
||||||
WebBase webBase = fillWebBaseResult(JsonUtil.toObject(plugin.getConfig(), WebBase.class), pluginParseResult);
|
WebBase webBase = fillWebBaseResult(JsonUtil.toObject(plugin.getConfig(), WebBase.class), pluginParseResult);
|
||||||
webServiceResponse.setWebBase(webBase);
|
webServiceResponse.setWebBase(webBase);
|
||||||
List<ParamOption> paramOptions = webBase.getParamOptions();
|
List<ParamOption> paramOptions = webBase.getParamOptions();
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package com.tencent.supersonic.chat.server.plugin.event;
|
package com.tencent.supersonic.chat.server.plugin.event;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
public class PluginAddEvent extends ApplicationEvent {
|
public class PluginAddEvent extends ApplicationEvent {
|
||||||
|
|
||||||
private Plugin plugin;
|
private ChatPlugin plugin;
|
||||||
|
|
||||||
public PluginAddEvent(Object source, Plugin plugin) {
|
public PluginAddEvent(Object source, ChatPlugin plugin) {
|
||||||
super(source);
|
super(source);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
public ChatPlugin getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
package com.tencent.supersonic.chat.server.plugin.event;
|
package com.tencent.supersonic.chat.server.plugin.event;
|
||||||
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
public class PluginDelEvent extends ApplicationEvent {
|
public class PluginDelEvent extends ApplicationEvent {
|
||||||
|
|
||||||
private Plugin plugin;
|
private ChatPlugin plugin;
|
||||||
|
|
||||||
public PluginDelEvent(Object source, Plugin plugin) {
|
public PluginDelEvent(Object source, ChatPlugin plugin) {
|
||||||
super(source);
|
super(source);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
public ChatPlugin getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
package com.tencent.supersonic.chat.server.plugin.event;
|
package com.tencent.supersonic.chat.server.plugin.event;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
public class PluginUpdateEvent extends ApplicationEvent {
|
public class PluginUpdateEvent extends ApplicationEvent {
|
||||||
|
|
||||||
private Plugin oldPlugin;
|
private ChatPlugin oldPlugin;
|
||||||
|
|
||||||
private Plugin newPlugin;
|
private ChatPlugin newPlugin;
|
||||||
|
|
||||||
public PluginUpdateEvent(Object source, Plugin oldPlugin, Plugin newPlugin) {
|
public PluginUpdateEvent(Object source, ChatPlugin oldPlugin, ChatPlugin newPlugin) {
|
||||||
super(source);
|
super(source);
|
||||||
this.oldPlugin = oldPlugin;
|
this.oldPlugin = oldPlugin;
|
||||||
this.newPlugin = newPlugin;
|
this.newPlugin = newPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getOldPlugin() {
|
public ChatPlugin getOldPlugin() {
|
||||||
return oldPlugin;
|
return oldPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getNewPlugin() {
|
public ChatPlugin getNewPlugin() {
|
||||||
return newPlugin;
|
return newPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.tencent.supersonic.chat.server.plugin.recognize;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginManager;
|
import com.tencent.supersonic.chat.server.plugin.PluginManager;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginRecallResult;
|
import com.tencent.supersonic.chat.server.plugin.PluginRecallResult;
|
||||||
@@ -45,7 +45,7 @@ public abstract class PluginRecognizer {
|
|||||||
|
|
||||||
public void buildQuery(ChatParseContext chatParseContext, ParseResp parseResp,
|
public void buildQuery(ChatParseContext chatParseContext, ParseResp parseResp,
|
||||||
PluginRecallResult pluginRecallResult) {
|
PluginRecallResult pluginRecallResult) {
|
||||||
Plugin plugin = pluginRecallResult.getPlugin();
|
ChatPlugin plugin = pluginRecallResult.getPlugin();
|
||||||
Set<Long> dataSetIds = pluginRecallResult.getDataSetIds();
|
Set<Long> dataSetIds = pluginRecallResult.getDataSetIds();
|
||||||
if (plugin.isContainsAllModel()) {
|
if (plugin.isContainsAllModel()) {
|
||||||
dataSetIds = Sets.newHashSet(-1L);
|
dataSetIds = Sets.newHashSet(-1L);
|
||||||
@@ -59,11 +59,11 @@ public abstract class PluginRecognizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Plugin> getPluginList(ChatParseContext chatParseContext) {
|
protected List<ChatPlugin> getPluginList(ChatParseContext chatParseContext) {
|
||||||
return PluginManager.getPluginAgentCanSupport(chatParseContext);
|
return PluginManager.getPluginAgentCanSupport(chatParseContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SemanticParseInfo buildSemanticParseInfo(Long dataSetId, Plugin plugin,
|
protected SemanticParseInfo buildSemanticParseInfo(Long dataSetId, ChatPlugin plugin,
|
||||||
ChatParseContext chatParseContext, double distance) {
|
ChatParseContext chatParseContext, double distance) {
|
||||||
List<SchemaElementMatch> schemaElementMatches = chatParseContext.getMapInfo().getMatchedElements(dataSetId);
|
List<SchemaElementMatch> schemaElementMatches = chatParseContext.getMapInfo().getMatchedElements(dataSetId);
|
||||||
QueryFilters queryFilters = chatParseContext.getQueryFilters();
|
QueryFilters queryFilters = chatParseContext.getQueryFilters();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.tencent.supersonic.chat.server.plugin.recognize.embedding;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.chat.server.plugin.ParseMode;
|
import com.tencent.supersonic.chat.server.plugin.ParseMode;
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginManager;
|
import com.tencent.supersonic.chat.server.plugin.PluginManager;
|
||||||
import com.tencent.supersonic.chat.server.plugin.PluginRecallResult;
|
import com.tencent.supersonic.chat.server.plugin.PluginRecallResult;
|
||||||
import com.tencent.supersonic.chat.server.plugin.recognize.PluginRecognizer;
|
import com.tencent.supersonic.chat.server.plugin.recognize.PluginRecognizer;
|
||||||
@@ -27,7 +27,7 @@ import java.util.stream.Collectors;
|
|||||||
public class EmbeddingRecallRecognizer extends PluginRecognizer {
|
public class EmbeddingRecallRecognizer extends PluginRecognizer {
|
||||||
|
|
||||||
public boolean checkPreCondition(ChatParseContext chatParseContext) {
|
public boolean checkPreCondition(ChatParseContext chatParseContext) {
|
||||||
List<Plugin> plugins = getPluginList(chatParseContext);
|
List<ChatPlugin> plugins = getPluginList(chatParseContext);
|
||||||
return !CollectionUtils.isEmpty(plugins);
|
return !CollectionUtils.isEmpty(plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,10 +37,10 @@ public class EmbeddingRecallRecognizer extends PluginRecognizer {
|
|||||||
if (CollectionUtils.isEmpty(embeddingRetrievals)) {
|
if (CollectionUtils.isEmpty(embeddingRetrievals)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<Plugin> plugins = getPluginList(chatParseContext);
|
List<ChatPlugin> plugins = getPluginList(chatParseContext);
|
||||||
Map<Long, Plugin> pluginMap = plugins.stream().collect(Collectors.toMap(Plugin::getId, p -> p));
|
Map<Long, ChatPlugin> pluginMap = plugins.stream().collect(Collectors.toMap(ChatPlugin::getId, p -> p));
|
||||||
for (Retrieval embeddingRetrieval : embeddingRetrievals) {
|
for (Retrieval embeddingRetrieval : embeddingRetrievals) {
|
||||||
Plugin plugin = pluginMap.get(Long.parseLong(embeddingRetrieval.getId()));
|
ChatPlugin plugin = pluginMap.get(Long.parseLong(embeddingRetrieval.getId()));
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.chat.server.rest;
|
|||||||
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.Plugin;
|
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.RestController;
|
||||||
@@ -25,7 +25,7 @@ public class PluginController {
|
|||||||
protected PluginService pluginService;
|
protected PluginService pluginService;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public boolean createPlugin(@RequestBody Plugin plugin,
|
public boolean createPlugin(@RequestBody ChatPlugin plugin,
|
||||||
HttpServletRequest httpServletRequest,
|
HttpServletRequest httpServletRequest,
|
||||||
HttpServletResponse httpServletResponse) {
|
HttpServletResponse httpServletResponse) {
|
||||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||||
@@ -34,7 +34,7 @@ public class PluginController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public boolean updatePlugin(@RequestBody Plugin plugin,
|
public boolean updatePlugin(@RequestBody ChatPlugin plugin,
|
||||||
HttpServletRequest httpServletRequest,
|
HttpServletRequest httpServletRequest,
|
||||||
HttpServletResponse httpServletResponse) {
|
HttpServletResponse httpServletResponse) {
|
||||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||||
@@ -49,14 +49,14 @@ public class PluginController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/getPluginList")
|
@RequestMapping("/getPluginList")
|
||||||
public List<Plugin> getPluginList() {
|
public List<ChatPlugin> getPluginList() {
|
||||||
return pluginService.getPluginList();
|
return pluginService.getPluginList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
List<Plugin> query(@RequestBody PluginQueryReq pluginQueryReq,
|
List<ChatPlugin> query(@RequestBody PluginQueryReq pluginQueryReq,
|
||||||
HttpServletRequest httpServletRequest,
|
HttpServletRequest httpServletRequest,
|
||||||
HttpServletResponse httpServletResponse) {
|
HttpServletResponse httpServletResponse) {
|
||||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||||
return pluginService.queryWithAuthCheck(pluginQueryReq, user);
|
return pluginService.queryWithAuthCheck(pluginQueryReq, user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.chat.server.service;
|
|||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
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.Plugin;
|
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -11,22 +11,22 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public interface PluginService {
|
public interface PluginService {
|
||||||
|
|
||||||
void createPlugin(Plugin plugin, User user);
|
void createPlugin(ChatPlugin plugin, User user);
|
||||||
|
|
||||||
void updatePlugin(Plugin plugin, User user);
|
void updatePlugin(ChatPlugin plugin, User user);
|
||||||
|
|
||||||
void deletePlugin(Long id);
|
void deletePlugin(Long id);
|
||||||
|
|
||||||
List<Plugin> getPluginList();
|
List<ChatPlugin> getPluginList();
|
||||||
|
|
||||||
List<Plugin> fetchPluginDOs(String queryText, String type);
|
List<ChatPlugin> fetchPluginDOs(String queryText, String type);
|
||||||
|
|
||||||
List<Plugin> query(PluginQueryReq pluginQueryReq);
|
List<ChatPlugin> query(PluginQueryReq pluginQueryReq);
|
||||||
|
|
||||||
Optional<Plugin> getPluginByName(String name);
|
Optional<ChatPlugin> getPluginByName(String name);
|
||||||
|
|
||||||
List<Plugin> queryWithAuthCheck(PluginQueryReq pluginQueryReq, User user);
|
List<ChatPlugin> queryWithAuthCheck(PluginQueryReq pluginQueryReq, User user);
|
||||||
|
|
||||||
Map<String, Plugin> getNameToPlugin();
|
Map<String, ChatPlugin> getNameToPlugin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
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.pojo.request.PluginQueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.PluginQueryReq;
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
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.event.PluginAddEvent;
|
import com.tencent.supersonic.chat.server.plugin.event.PluginAddEvent;
|
||||||
import com.tencent.supersonic.chat.server.plugin.event.PluginDelEvent;
|
import com.tencent.supersonic.chat.server.plugin.event.PluginDelEvent;
|
||||||
@@ -43,19 +43,19 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void createPlugin(Plugin plugin, User user) {
|
public synchronized void createPlugin(ChatPlugin plugin, User user) {
|
||||||
PluginDO pluginDO = convert(plugin, user);
|
PluginDO pluginDO = convert(plugin, user);
|
||||||
pluginRepository.createPlugin(pluginDO);
|
pluginRepository.createPlugin(pluginDO);
|
||||||
//compatible with H2 db
|
//compatible with H2 db
|
||||||
List<Plugin> plugins = getPluginList();
|
List<ChatPlugin> plugins = getPluginList();
|
||||||
publisher.publishEvent(new PluginAddEvent(this, plugins.get(plugins.size() - 1)));
|
publisher.publishEvent(new PluginAddEvent(this, plugins.get(plugins.size() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlugin(Plugin plugin, User user) {
|
public void updatePlugin(ChatPlugin plugin, User user) {
|
||||||
Long id = plugin.getId();
|
Long id = plugin.getId();
|
||||||
PluginDO pluginDO = pluginRepository.getPlugin(id);
|
PluginDO pluginDO = pluginRepository.getPlugin(id);
|
||||||
Plugin oldPlugin = convert(pluginDO);
|
ChatPlugin oldPlugin = convert(pluginDO);
|
||||||
convert(plugin, pluginDO, user);
|
convert(plugin, pluginDO, user);
|
||||||
pluginRepository.updatePlugin(pluginDO);
|
pluginRepository.updatePlugin(pluginDO);
|
||||||
publisher.publishEvent(new PluginUpdateEvent(this, oldPlugin, plugin));
|
publisher.publishEvent(new PluginUpdateEvent(this, oldPlugin, plugin));
|
||||||
@@ -71,8 +71,8 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Plugin> getPluginList() {
|
public List<ChatPlugin> getPluginList() {
|
||||||
List<Plugin> plugins = Lists.newArrayList();
|
List<ChatPlugin> plugins = Lists.newArrayList();
|
||||||
List<PluginDO> pluginDOS = pluginRepository.getPlugins();
|
List<PluginDO> pluginDOS = pluginRepository.getPlugins();
|
||||||
if (CollectionUtils.isEmpty(pluginDOS)) {
|
if (CollectionUtils.isEmpty(pluginDOS)) {
|
||||||
return plugins;
|
return plugins;
|
||||||
@@ -81,13 +81,13 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Plugin> fetchPluginDOs(String queryText, String type) {
|
public List<ChatPlugin> fetchPluginDOs(String queryText, String type) {
|
||||||
List<PluginDO> pluginDOS = pluginRepository.fetchPluginDOs(queryText, type);
|
List<PluginDO> pluginDOS = pluginRepository.fetchPluginDOs(queryText, type);
|
||||||
return convertList(pluginDOS);
|
return convertList(pluginDOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Plugin> query(PluginQueryReq pluginQueryReq) {
|
public List<ChatPlugin> query(PluginQueryReq pluginQueryReq) {
|
||||||
QueryWrapper<PluginDO> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<PluginDO> queryWrapper = new QueryWrapper<>();
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(pluginQueryReq.getType())) {
|
if (StringUtils.isNotBlank(pluginQueryReq.getType())) {
|
||||||
@@ -120,7 +120,7 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Plugin> getPluginByName(String name) {
|
public Optional<ChatPlugin> getPluginByName(String name) {
|
||||||
log.info("name:{}", name);
|
log.info("name:{}", name);
|
||||||
return getPluginList().stream()
|
return getPluginList().stream()
|
||||||
.filter(plugin -> {
|
.filter(plugin -> {
|
||||||
@@ -133,7 +133,7 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluginParseConfig getPluginParseConfig(Plugin plugin) {
|
private PluginParseConfig getPluginParseConfig(ChatPlugin plugin) {
|
||||||
if (StringUtils.isBlank(plugin.getParseModeConfig())) {
|
if (StringUtils.isBlank(plugin.getParseModeConfig())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -149,13 +149,13 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Plugin> queryWithAuthCheck(PluginQueryReq pluginQueryReq, User user) {
|
public List<ChatPlugin> queryWithAuthCheck(PluginQueryReq pluginQueryReq, User user) {
|
||||||
return authCheck(query(pluginQueryReq), user);
|
return authCheck(query(pluginQueryReq), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Plugin> getNameToPlugin() {
|
public Map<String, ChatPlugin> getNameToPlugin() {
|
||||||
List<Plugin> pluginList = getPluginList();
|
List<ChatPlugin> pluginList = getPluginList();
|
||||||
|
|
||||||
return pluginList.stream()
|
return pluginList.stream()
|
||||||
.filter(plugin -> {
|
.filter(plugin -> {
|
||||||
@@ -173,12 +173,12 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//todo
|
//todo
|
||||||
private List<Plugin> authCheck(List<Plugin> plugins, User user) {
|
private List<ChatPlugin> authCheck(List<ChatPlugin> plugins, User user) {
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin convert(PluginDO pluginDO) {
|
public ChatPlugin convert(PluginDO pluginDO) {
|
||||||
Plugin plugin = new Plugin();
|
ChatPlugin plugin = new ChatPlugin();
|
||||||
BeanUtils.copyProperties(pluginDO, plugin);
|
BeanUtils.copyProperties(pluginDO, plugin);
|
||||||
if (StringUtils.isNotBlank(pluginDO.getDataSet())) {
|
if (StringUtils.isNotBlank(pluginDO.getDataSet())) {
|
||||||
plugin.setDataSetList(Arrays.stream(pluginDO.getDataSet().split(","))
|
plugin.setDataSetList(Arrays.stream(pluginDO.getDataSet().split(","))
|
||||||
@@ -187,7 +187,7 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginDO convert(Plugin plugin, User user) {
|
public PluginDO convert(ChatPlugin plugin, User user) {
|
||||||
PluginDO pluginDO = new PluginDO();
|
PluginDO pluginDO = new PluginDO();
|
||||||
BeanUtils.copyProperties(plugin, pluginDO);
|
BeanUtils.copyProperties(plugin, pluginDO);
|
||||||
pluginDO.setCreatedAt(new Date());
|
pluginDO.setCreatedAt(new Date());
|
||||||
@@ -198,7 +198,7 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
return pluginDO;
|
return pluginDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginDO convert(Plugin plugin, PluginDO pluginDO, User user) {
|
public PluginDO convert(ChatPlugin plugin, PluginDO pluginDO, User user) {
|
||||||
BeanUtils.copyProperties(plugin, pluginDO);
|
BeanUtils.copyProperties(plugin, pluginDO);
|
||||||
pluginDO.setUpdatedAt(new Date());
|
pluginDO.setUpdatedAt(new Date());
|
||||||
pluginDO.setUpdatedBy(user.getName());
|
pluginDO.setUpdatedBy(user.getName());
|
||||||
@@ -206,7 +206,7 @@ public class PluginServiceImpl implements PluginService {
|
|||||||
return pluginDO;
|
return pluginDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Plugin> convertList(List<PluginDO> pluginDOS) {
|
public List<ChatPlugin> convertList(List<PluginDO> pluginDOS) {
|
||||||
if (!CollectionUtils.isEmpty(pluginDOS)) {
|
if (!CollectionUtils.isEmpty(pluginDOS)) {
|
||||||
return pluginDOS.stream().map(this::convert).collect(Collectors.toList());
|
return pluginDOS.stream().map(this::convert).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
package com.tencent.supersonic.chat.server.util;
|
package com.tencent.supersonic.chat.server.util;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.config.LLMConfig;
|
import com.tencent.supersonic.common.config.LLMConfig;
|
||||||
|
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||||
import com.tencent.supersonic.common.util.S2ChatModelProvider;
|
import com.tencent.supersonic.common.util.S2ChatModelProvider;
|
||||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class LLMConnHelper {
|
public class LLMConnHelper {
|
||||||
public static boolean testConnection(LLMConfig llmConfig) {
|
public static boolean testConnection(LLMConfig llmConfig) {
|
||||||
try {
|
try {
|
||||||
|
if (llmConfig == null || StringUtils.isBlank(llmConfig.getBaseUrl())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ChatLanguageModel chatLanguageModel = S2ChatModelProvider.provide(llmConfig);
|
ChatLanguageModel chatLanguageModel = S2ChatModelProvider.provide(llmConfig);
|
||||||
String response = chatLanguageModel.generate("Hi there");
|
String response = chatLanguageModel.generate("Hi there");
|
||||||
return StringUtils.isNotEmpty(response) ? true : false;
|
return StringUtils.isNotEmpty(response) ? true : false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
log.warn("connect llm failed:", e);
|
||||||
|
throw new InvalidArgumentException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.tencent.supersonic.common.config;
|
package com.tencent.supersonic.common.config;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.common.util.AESUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -36,4 +37,9 @@ public class LLMConfig {
|
|||||||
this.modelName = modelName;
|
this.modelName = modelName;
|
||||||
this.temperature = temperature;
|
this.temperature = temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String keyDecrypt() {
|
||||||
|
return AESUtil.aesDecrypt(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package com.tencent.supersonic.common.util;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import sun.misc.BASE64Decoder;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.KeyGenerator;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class AESUtil {
|
||||||
|
|
||||||
|
private static final String KEY = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
|
||||||
|
//算法
|
||||||
|
private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";
|
||||||
|
|
||||||
|
public static String aesDecrypt(String encrypt) {
|
||||||
|
try {
|
||||||
|
return aesDecrypt(encrypt, KEY);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("content decrypt failed:{}", encrypt);
|
||||||
|
return encrypt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
|
||||||
|
return StringUtils.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String base64Encode(byte[] bytes) {
|
||||||
|
return Base64.encodeBase64String(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] base64Decode(String base64Code) throws Exception {
|
||||||
|
return StringUtils.isEmpty(base64Code) ? null : new BASE64Decoder().decodeBuffer(base64Code);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
|
||||||
|
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||||
|
kgen.init(128);
|
||||||
|
Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(hexStringToByteArray(encryptKey), "AES"));
|
||||||
|
|
||||||
|
return cipher.doFinal(content.getBytes("utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String aesEncrypt(String content, String encryptKey) throws Exception {
|
||||||
|
return base64Encode(aesEncryptToBytes(content, encryptKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
|
||||||
|
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||||
|
kgen.init(128);
|
||||||
|
|
||||||
|
Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(hexStringToByteArray(decryptKey), "AES"));
|
||||||
|
byte[] decryptBytes = cipher.doFinal(encryptBytes);
|
||||||
|
return new String(decryptBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] hexStringToByteArray(String hexString) {
|
||||||
|
int len = hexString.length();
|
||||||
|
byte[] byteArray = new byte[len / 2];
|
||||||
|
for (int i = 0; i < len; i += 2) {
|
||||||
|
byteArray[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
|
||||||
|
+ Character.digit(hexString.charAt(i + 1), 16));
|
||||||
|
}
|
||||||
|
return byteArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
String content = "123";
|
||||||
|
System.out.println("before encrypt:" + content);
|
||||||
|
System.out.println("key:" + KEY);
|
||||||
|
String encrypt = aesEncrypt(content, KEY);
|
||||||
|
System.out.println("after encrypt:" + encrypt);
|
||||||
|
String decrypt = aesDecrypt(encrypt);
|
||||||
|
System.out.println("after decrypt:" + decrypt);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ public class S2ChatModelProvider {
|
|||||||
.builder()
|
.builder()
|
||||||
.baseUrl(llmConfig.getBaseUrl())
|
.baseUrl(llmConfig.getBaseUrl())
|
||||||
.modelName(llmConfig.getModelName())
|
.modelName(llmConfig.getModelName())
|
||||||
.apiKey(llmConfig.getApiKey())
|
.apiKey(llmConfig.keyDecrypt())
|
||||||
.temperature(llmConfig.getTemperature())
|
.temperature(llmConfig.getTemperature())
|
||||||
.timeout(Duration.ofSeconds(llmConfig.getTimeOut()))
|
.timeout(Duration.ofSeconds(llmConfig.getTimeOut()))
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
|||||||
import com.tencent.supersonic.chat.server.agent.LLMParserTool;
|
import com.tencent.supersonic.chat.server.agent.LLMParserTool;
|
||||||
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
||||||
import com.tencent.supersonic.chat.server.agent.RuleParserTool;
|
import com.tencent.supersonic.chat.server.agent.RuleParserTool;
|
||||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
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.common.pojo.JoinCondition;
|
import com.tencent.supersonic.common.pojo.JoinCondition;
|
||||||
@@ -514,7 +514,7 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addPlugin(DataSetResp s2DataSet) {
|
private void addPlugin(DataSetResp s2DataSet) {
|
||||||
Plugin plugin1 = new Plugin();
|
ChatPlugin plugin1 = new ChatPlugin();
|
||||||
plugin1.setType("WEB_PAGE");
|
plugin1.setType("WEB_PAGE");
|
||||||
plugin1.setDataSetList(Arrays.asList(s2DataSet.getId()));
|
plugin1.setDataSetList(Arrays.asList(s2DataSet.getId()));
|
||||||
plugin1.setPattern("用于分析超音数的流量概况,包含UV、PV等核心指标的追踪。P.S. 仅作为示例展示,无实际看板");
|
plugin1.setPattern("用于分析超音数的流量概况,包含UV、PV等核心指标的追踪。P.S. 仅作为示例展示,无实际看板");
|
||||||
|
|||||||
Reference in New Issue
Block a user