mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
chore: remove legacy utils and constant class
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
package work.slhaf.partner.common;
|
|
||||||
|
|
||||||
public final class Constant {
|
|
||||||
|
|
||||||
public static final class Path {
|
|
||||||
public static final String DATA = "data";
|
|
||||||
public static final String MEMORY_DATA = DATA + "/memory";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package work.slhaf.partner.common.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ExtractUtil {
|
|
||||||
public static String extractJson(String jsonStr) {
|
|
||||||
jsonStr = jsonStr.replace("“", "\"").replace("”", "\"");
|
|
||||||
int start = jsonStr.indexOf("{");
|
|
||||||
int end = jsonStr.lastIndexOf("}");
|
|
||||||
if (start != -1 && end != -1 && start < end) {
|
|
||||||
return jsonStr.substring(start, end + 1);
|
|
||||||
}
|
|
||||||
return jsonStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String extractUserId(String messageContent) {
|
|
||||||
Pattern pattern = Pattern.compile("\\[.*\\(([^)]+)\\)\\]");
|
|
||||||
Matcher matcher = pattern.matcher(messageContent);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return matcher.group(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String fixTopicPath(String topicPath) {
|
|
||||||
String[] parts = topicPath.split("->");
|
|
||||||
List<String> cleanedParts = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String part : parts) {
|
|
||||||
// 修正正则表达式,正确移除 [xxx] 部分
|
|
||||||
String cleaned = part.replaceAll("\\[[^\\]]*\\]", "").trim();
|
|
||||||
if (!cleaned.isEmpty()) { // 忽略空字符串
|
|
||||||
cleanedParts.add(cleaned);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.join("->", cleanedParts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package work.slhaf.partner.common.util;
|
|
||||||
|
|
||||||
public class PathUtil {
|
|
||||||
public static String buildPathStr(String... path) {
|
|
||||||
StringBuilder str = new StringBuilder();
|
|
||||||
for (int i = 0; i < path.length; i++) {
|
|
||||||
str.append(path[i]);
|
|
||||||
if (i < path.length - 1) {
|
|
||||||
str.append("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,8 +22,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static work.slhaf.partner.common.util.PathUtil.buildPathStr;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LocalRunnerClient extends RunnerClient implements AutoCloseable {
|
public class LocalRunnerClient extends RunnerClient implements AutoCloseable {
|
||||||
|
|
||||||
@@ -195,4 +193,15 @@ public class LocalRunnerClient extends RunnerClient implements AutoCloseable {
|
|||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String buildPathStr(String... path) {
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
for (int i = 0; i < path.length; i++) {
|
||||||
|
str.append(path[i]);
|
||||||
|
if (i < path.length - 1) {
|
||||||
|
str.append("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package work.slhaf.partner.module.communication;
|
package work.slhaf.partner.module.communication;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -25,8 +24,6 @@ import java.io.StringWriter;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static work.slhaf.partner.common.util.ExtractUtil.extractJson;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class CommunicationProducer extends AbstractAgentModule.Running<PartnerRunningFlowContext> implements ActivateModel {
|
public class CommunicationProducer extends AbstractAgentModule.Running<PartnerRunningFlowContext> implements ActivateModel {
|
||||||
@@ -160,15 +157,7 @@ public class CommunicationProducer extends AbstractAgentModule.Running<PartnerRu
|
|||||||
}
|
}
|
||||||
String content = message.getContent();
|
String content = message.getContent();
|
||||||
String trimmed = content.trim();
|
String trimmed = content.trim();
|
||||||
if (trimmed.startsWith("<input>") || trimmed.startsWith("<context>") || trimmed.startsWith("<?xml")) {
|
return trimmed.startsWith("<input>") || trimmed.startsWith("<context>") || trimmed.startsWith("<?xml");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject.parseObject(extractJson(content));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean belongsToContextSection(BlockContent blockContent) {
|
private boolean belongsToContextSection(BlockContent blockContent) {
|
||||||
|
|||||||
@@ -322,6 +322,21 @@ public class MemoryRuntime extends AbstractAgentModule.Standalone implements Sta
|
|||||||
return refs;
|
return refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String fixTopicPath(String topicPath) {
|
||||||
|
String[] parts = topicPath.split("->");
|
||||||
|
List<String> cleanedParts = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String part : parts) {
|
||||||
|
// 修正正则表达式,正确移除 [xxx] 部分
|
||||||
|
String cleaned = part.replaceAll("\\[[^\\]]*\\]", "").trim();
|
||||||
|
if (!cleaned.isEmpty()) { // 忽略空字符串
|
||||||
|
cleanedParts.add(cleaned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.join("->", cleanedParts);
|
||||||
|
}
|
||||||
|
|
||||||
private static final class TopicTreeNode {
|
private static final class TopicTreeNode {
|
||||||
private final Map<String, TopicTreeNode> children = new LinkedHashMap<>();
|
private final Map<String, TopicTreeNode> children = new LinkedHashMap<>();
|
||||||
private int count;
|
private int count;
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import work.slhaf.partner.module.memory.selector.extractor.entity.ExtractorResul
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class MemorySelectExtractor extends AbstractAgentModule.Sub<ExtractorInput, ExtractorResult> implements ActivateModel {
|
public class MemorySelectExtractor extends AbstractAgentModule.Sub<ExtractorInput, ExtractorResult> implements ActivateModel {
|
||||||
@@ -81,7 +79,7 @@ public class MemorySelectExtractor extends AbstractAgentModule.Sub<ExtractorInpu
|
|||||||
if (m.getType().equals(ExtractorMatchData.Constant.DATE)) {
|
if (m.getType().equals(ExtractorMatchData.Constant.DATE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m.setText(fixTopicPath(m.getText()));
|
m.setText(memoryRuntime.fixTopicPath(m.getText()));
|
||||||
});
|
});
|
||||||
if (extractorResult.getMatches().isEmpty()) {
|
if (extractorResult.getMatches().isEmpty()) {
|
||||||
return extractorResult;
|
return extractorResult;
|
||||||
|
|||||||
@@ -5,19 +5,23 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import work.slhaf.partner.framework.agent.factory.component.abstracts.AbstractAgentModule;
|
import work.slhaf.partner.framework.agent.factory.component.abstracts.AbstractAgentModule;
|
||||||
|
import work.slhaf.partner.framework.agent.factory.component.annotation.InjectModule;
|
||||||
import work.slhaf.partner.framework.agent.model.ActivateModel;
|
import work.slhaf.partner.framework.agent.model.ActivateModel;
|
||||||
import work.slhaf.partner.framework.agent.model.pojo.Message;
|
import work.slhaf.partner.framework.agent.model.pojo.Message;
|
||||||
|
import work.slhaf.partner.module.memory.runtime.MemoryRuntime;
|
||||||
import work.slhaf.partner.module.memory.updater.summarizer.entity.SummarizeInput;
|
import work.slhaf.partner.module.memory.updater.summarizer.entity.SummarizeInput;
|
||||||
import work.slhaf.partner.module.memory.updater.summarizer.entity.SummarizeResult;
|
import work.slhaf.partner.module.memory.updater.summarizer.entity.SummarizeResult;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class MultiSummarizer extends AbstractAgentModule.Sub<SummarizeInput, SummarizeResult> implements ActivateModel {
|
public class MultiSummarizer extends AbstractAgentModule.Sub<SummarizeInput, SummarizeResult> implements ActivateModel {
|
||||||
|
|
||||||
|
@InjectModule
|
||||||
|
private MemoryRuntime memoryRuntime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SummarizeResult execute(SummarizeInput input) {
|
public SummarizeResult execute(SummarizeInput input) {
|
||||||
log.debug("[MemorySummarizer] 整体摘要开始...");
|
log.debug("[MemorySummarizer] 整体摘要开始...");
|
||||||
@@ -33,10 +37,10 @@ public class MultiSummarizer extends AbstractAgentModule.Sub<SummarizeInput, Sum
|
|||||||
if (result == null || result.getTopicPath() == null || result.getTopicPath().isEmpty()) {
|
if (result == null || result.getTopicPath() == null || result.getTopicPath().isEmpty()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
String topicPath = fixTopicPath(result.getTopicPath());
|
String topicPath = memoryRuntime.fixTopicPath(result.getTopicPath());
|
||||||
List<String> relatedTopicPath = new ArrayList<>();
|
List<String> relatedTopicPath = new ArrayList<>();
|
||||||
for (String s : result.getRelatedTopicPath()) {
|
for (String s : result.getRelatedTopicPath()) {
|
||||||
relatedTopicPath.add(fixTopicPath(s));
|
relatedTopicPath.add(memoryRuntime.fixTopicPath(s));
|
||||||
}
|
}
|
||||||
result.setTopicPath(topicPath);
|
result.setTopicPath(topicPath);
|
||||||
result.setRelatedTopicPath(relatedTopicPath);
|
result.setRelatedTopicPath(relatedTopicPath);
|
||||||
|
|||||||
Reference in New Issue
Block a user