mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +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.atomic.AtomicBoolean;
|
||||
|
||||
import static work.slhaf.partner.common.util.PathUtil.buildPathStr;
|
||||
|
||||
@Slf4j
|
||||
public class LocalRunnerClient extends RunnerClient implements AutoCloseable {
|
||||
|
||||
@@ -195,4 +193,15 @@ public class LocalRunnerClient extends RunnerClient implements AutoCloseable {
|
||||
} 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;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -25,8 +24,6 @@ import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static work.slhaf.partner.common.util.ExtractUtil.extractJson;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
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 trimmed = content.trim();
|
||||
if (trimmed.startsWith("<input>") || trimmed.startsWith("<context>") || trimmed.startsWith("<?xml")) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
JSONObject.parseObject(extractJson(content));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return trimmed.startsWith("<input>") || trimmed.startsWith("<context>") || trimmed.startsWith("<?xml");
|
||||
}
|
||||
|
||||
private boolean belongsToContextSection(BlockContent blockContent) {
|
||||
|
||||
@@ -322,6 +322,21 @@ public class MemoryRuntime extends AbstractAgentModule.Standalone implements Sta
|
||||
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 final Map<String, TopicTreeNode> children = new LinkedHashMap<>();
|
||||
private int count;
|
||||
|
||||
@@ -22,8 +22,6 @@ import work.slhaf.partner.module.memory.selector.extractor.entity.ExtractorResul
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
m.setText(fixTopicPath(m.getText()));
|
||||
m.setText(memoryRuntime.fixTopicPath(m.getText()));
|
||||
});
|
||||
if (extractorResult.getMatches().isEmpty()) {
|
||||
return extractorResult;
|
||||
|
||||
@@ -5,19 +5,23 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
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.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.SummarizeResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class MultiSummarizer extends AbstractAgentModule.Sub<SummarizeInput, SummarizeResult> implements ActivateModel {
|
||||
|
||||
@InjectModule
|
||||
private MemoryRuntime memoryRuntime;
|
||||
|
||||
@Override
|
||||
public SummarizeResult execute(SummarizeInput input) {
|
||||
log.debug("[MemorySummarizer] 整体摘要开始...");
|
||||
@@ -33,10 +37,10 @@ public class MultiSummarizer extends AbstractAgentModule.Sub<SummarizeInput, Sum
|
||||
if (result == null || result.getTopicPath() == null || result.getTopicPath().isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
String topicPath = fixTopicPath(result.getTopicPath());
|
||||
String topicPath = memoryRuntime.fixTopicPath(result.getTopicPath());
|
||||
List<String> relatedTopicPath = new ArrayList<>();
|
||||
for (String s : result.getRelatedTopicPath()) {
|
||||
relatedTopicPath.add(fixTopicPath(s));
|
||||
relatedTopicPath.add(memoryRuntime.fixTopicPath(s));
|
||||
}
|
||||
result.setTopicPath(topicPath);
|
||||
result.setRelatedTopicPath(relatedTopicPath);
|
||||
|
||||
Reference in New Issue
Block a user