mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(Core): normalize preprocess user resolution from source/additional info, add Kotlin-safe AgentConfigLoader getters, and update async summary writes by index
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package work.slhaf.partner.core.action.entity;
|
||||
|
||||
import work.slhaf.partner.core.action.entity.ExecutableAction.Status;
|
||||
import work.slhaf.partner.core.action.entity.Action.Status;
|
||||
|
||||
import java.util.concurrent.Phaser;
|
||||
|
||||
|
||||
@@ -32,14 +32,17 @@ public class SingleSummarizer extends AbstractAgentModule.Sub<List<Message>, Voi
|
||||
log.debug("[MemorySummarizer] 长文本摘要开始...");
|
||||
List<Callable<Void>> tasks = new ArrayList<>();
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
for (Message chatMessage : chatMessages) {
|
||||
for (int i = 0; i < chatMessages.size(); i++) {
|
||||
Message chatMessage = chatMessages.get(i);
|
||||
if (chatMessage.getRole().equals(ChatConstant.Character.ASSISTANT)) {
|
||||
String content = chatMessage.getContent();
|
||||
if (chatMessage.getContent().length() > 500) {
|
||||
int index = i;
|
||||
tasks.add(() -> {
|
||||
int thisCount = counter.incrementAndGet();
|
||||
log.debug("[MemorySummarizer] 长文本摘要[{}]启动", thisCount);
|
||||
chatMessage.setContent(singleExecute(JSONObject.of("content", content).toString()));
|
||||
String summarized = singleExecute(JSONObject.of("content", content).toString());
|
||||
chatMessages.set(index, new Message(chatMessage.getRole(), summarized));
|
||||
log.debug("[MemorySummarizer] 长文本摘要[{}]完成", thisCount);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -18,6 +18,9 @@ import java.util.Map;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PreprocessExecutor extends PreRunningAbstractAgentModuleAbstract {
|
||||
private static final String INFO_PLATFORM = "platform";
|
||||
private static final String INFO_NICKNAME = "nickname";
|
||||
|
||||
@InjectCapability
|
||||
private CognationCapability cognationCapability;
|
||||
@InjectCapability
|
||||
@@ -38,19 +41,28 @@ public class PreprocessExecutor extends PreRunningAbstractAgentModuleAbstract {
|
||||
|
||||
private void getInteractionContext(PartnerRunningFlowContext context) {
|
||||
log.debug("[PreprocessExecutor] 预处理原始输入: {}", context);
|
||||
User user = perceiveCapability.getUser(context.getUserInfo(), context.getPlatform());
|
||||
String platform = context.getAdditionalUserInfo().getOrDefault(INFO_PLATFORM, "");
|
||||
String nickName = context.getAdditionalUserInfo().getOrDefault(INFO_NICKNAME, "");
|
||||
String sourceUserId = parseSourceUserId(context.getSource());
|
||||
User user = perceiveCapability.getUser(sourceUserId, platform);
|
||||
if (user == null) {
|
||||
user = perceiveCapability.addUser(context.getUserInfo(), context.getPlatform(), context.getUserNickname());
|
||||
user = perceiveCapability.addUser(sourceUserId, platform, nickName);
|
||||
}
|
||||
String userId = user.getUuid();
|
||||
context.setUserId(userId);
|
||||
String userStr = "[" + context.getUserNickname() + "(" + userId + ")]";
|
||||
String userStr = "[" + nickName + "(" + userId + ")]";
|
||||
String input = userStr + " " + context.getInput();
|
||||
context.setInput(input);
|
||||
setCoreContext(context);
|
||||
setCoreContext(context, input, nickName, userId);
|
||||
log.debug("[PreprocessExecutor] 预处理结果: {}", context);
|
||||
}
|
||||
|
||||
private String parseSourceUserId(String source) {
|
||||
int split = source.indexOf(':');
|
||||
if (split < 0 || split + 1 >= source.length()) {
|
||||
return source;
|
||||
}
|
||||
return source.substring(split + 1).trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getPromptDataMap(PartnerRunningFlowContext context) {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
@@ -68,12 +80,12 @@ public class PreprocessExecutor extends PreRunningAbstractAgentModuleAbstract {
|
||||
return "[基础模块]";
|
||||
}
|
||||
|
||||
private void setCoreContext(PartnerRunningFlowContext context) {
|
||||
private void setCoreContext(PartnerRunningFlowContext context, String input, String nickName, String userId) {
|
||||
CoreContext coreContext = context.getCoreContext();
|
||||
coreContext.setText(context.getInput());
|
||||
coreContext.setText(input);
|
||||
coreContext.setDateTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
coreContext.setUserNick(context.getUserNickname());
|
||||
coreContext.setUserId(context.getUserId());
|
||||
coreContext.setUserNick(nickName);
|
||||
coreContext.setUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,15 @@ public abstract class AgentConfigLoader {
|
||||
|
||||
public abstract void dumpModelConfig(String key);
|
||||
|
||||
// Keep explicit getters for Kotlin compilation phase (without Lombok-generated methods).
|
||||
public HashMap<String, ModelConfig> getModelConfigMap() {
|
||||
return modelConfigMap;
|
||||
}
|
||||
|
||||
public HashMap<String, List<Message>> getModelPromptMap() {
|
||||
return modelPromptMap;
|
||||
}
|
||||
|
||||
public List<Message> loadModelPrompt(String modelKey) {
|
||||
if (!modelPromptMap.containsKey(modelKey)) {
|
||||
throw new PromptNotExistException("不存在的modelPrompt: " + modelKey);
|
||||
|
||||
Reference in New Issue
Block a user