mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
完成了本体与框架的适配工作,并修复了某些问题。需要进一步进行测试
- 修复了 CognationCapability 相关的注解使用错误 - 将前置模块中的 setAppendedPrompt 与 setActiveModule 方法抽取到 execute 模板方法中 - 完善了已有模块的适配工作, 并去除了不必要的单例配置
This commit is contained in:
12
.idea/misc.xml
generated
12
.idea/misc.xml
generated
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
<component name="EntryPointsManager">
|
||||||
<list size="11">
|
<list size="13">
|
||||||
<item index="0" class="java.lang.String" itemvalue="lombok.Data" />
|
<item index="0" class="java.lang.String" itemvalue="lombok.Data" />
|
||||||
<item index="1" class="java.lang.String" itemvalue="net.bytebuddy.implementation.bind.annotation.RuntimeType" />
|
<item index="1" class="java.lang.String" itemvalue="net.bytebuddy.implementation.bind.annotation.RuntimeType" />
|
||||||
<item index="2" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.Capability" />
|
<item index="2" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.Capability" />
|
||||||
@@ -9,10 +9,12 @@
|
|||||||
<item index="4" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod" />
|
<item index="4" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod" />
|
||||||
<item index="5" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.CoordinateManager" />
|
<item index="5" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.CoordinateManager" />
|
||||||
<item index="6" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.Coordinated" />
|
<item index="6" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.capability.annotation.Coordinated" />
|
||||||
<item index="7" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.module.annotation.Init" />
|
<item index="7" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.module.annotation.AfterExecute" />
|
||||||
<item index="8" class="java.lang.String" itemvalue="work.slhaf.partner.api.capability.annotation.CapabilityMethod" />
|
<item index="8" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.module.annotation.AgentModule" />
|
||||||
<item index="9" class="java.lang.String" itemvalue="work.slhaf.partner.api.capability.annotation.CoordinateManager" />
|
<item index="9" class="java.lang.String" itemvalue="work.slhaf.partner.api.agent.factory.module.annotation.Init" />
|
||||||
<item index="10" class="java.lang.String" itemvalue="work.slhaf.partner.api.register.capability.annotation.Capability" />
|
<item index="10" class="java.lang.String" itemvalue="work.slhaf.partner.api.capability.annotation.CapabilityMethod" />
|
||||||
|
<item index="11" class="java.lang.String" itemvalue="work.slhaf.partner.api.capability.annotation.CoordinateManager" />
|
||||||
|
<item index="12" class="java.lang.String" itemvalue="work.slhaf.partner.api.register.capability.annotation.Capability" />
|
||||||
</list>
|
</list>
|
||||||
</component>
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import work.slhaf.partner.api.agent.factory.module.ModuleInitHookExecuteFactory;
|
|||||||
import work.slhaf.partner.api.agent.factory.module.ModuleProxyFactory;
|
import work.slhaf.partner.api.agent.factory.module.ModuleProxyFactory;
|
||||||
import work.slhaf.partner.api.agent.factory.module.ModuleRegisterFactory;
|
import work.slhaf.partner.api.agent.factory.module.ModuleRegisterFactory;
|
||||||
import work.slhaf.partner.api.agent.factory.module.pojo.MetaModule;
|
import work.slhaf.partner.api.agent.factory.module.pojo.MetaModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.data.AgentContext;
|
|
||||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
||||||
|
import work.slhaf.partner.api.agent.runtime.data.AgentContext;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.AgentRunningFlow;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.AgentRunningFlow;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import work.slhaf.partner.api.agent.factory.capability.exception.UnMatchedCapabi
|
|||||||
import work.slhaf.partner.api.agent.factory.capability.exception.UnMatchedCoordinatedMethodException;
|
import work.slhaf.partner.api.agent.factory.capability.exception.UnMatchedCoordinatedMethodException;
|
||||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||||
import work.slhaf.partner.api.agent.factory.context.CapabilityFactoryContext;
|
import work.slhaf.partner.api.agent.factory.context.CapabilityFactoryContext;
|
||||||
import work.slhaf.partner.api.agent.factory.module.ModuleCheckFactory;
|
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
import work.slhaf.partner.api.agent.util.AgentUtil;
|
import work.slhaf.partner.api.agent.util.AgentUtil;
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package work.slhaf.partner.api.agent.factory.context;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import work.slhaf.partner.api.agent.factory.module.pojo.MetaModule;
|
import work.slhaf.partner.api.agent.factory.module.pojo.MetaModule;
|
||||||
import work.slhaf.partner.api.agent.factory.module.pojo.MetaSubModule;
|
import work.slhaf.partner.api.agent.factory.module.pojo.MetaSubModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import cn.hutool.core.util.ClassUtil;
|
|||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import work.slhaf.partner.api.agent.factory.AgentBaseFactory;
|
import work.slhaf.partner.api.agent.factory.AgentBaseFactory;
|
||||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.*;
|
import work.slhaf.partner.api.agent.factory.module.annotation.AfterExecute;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.BeforeExecute;
|
||||||
import work.slhaf.partner.api.agent.factory.module.exception.ModuleCheckException;
|
import work.slhaf.partner.api.agent.factory.module.exception.ModuleCheckException;
|
||||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunn
|
|||||||
import work.slhaf.partner.api.agent.util.AgentUtil;
|
import work.slhaf.partner.api.agent.util.AgentUtil;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static work.slhaf.partner.api.agent.util.AgentUtil.collectExtendedClasses;
|
import static work.slhaf.partner.api.agent.util.AgentUtil.collectExtendedClasses;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import work.slhaf.partner.api.agent.factory.module.pojo.MetaSubModule;
|
|||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.Module;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.Module;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -146,8 +145,8 @@ public class ModuleProxyFactory extends AgentBaseFactory {
|
|||||||
List<MetaMethod> pre = new ArrayList<>();
|
List<MetaMethod> pre = new ArrayList<>();
|
||||||
//获取该类本身的hook逻辑
|
//获取该类本身的hook逻辑
|
||||||
collectHookMethods(post, pre, clazz);
|
collectHookMethods(post, pre, clazz);
|
||||||
//获取它所继承、实现的抽象类或接口, 以AgentInteractionModule、ActiveModel为终点
|
//获取它所继承、实现的抽象类或接口, 以Module为终点,收集继承链上所有父类和接口
|
||||||
Set<Class<?>> classes = collectExtendedClasses(clazz, AgentRunningModule.class);
|
Set<Class<?>> classes = collectExtendedClasses(clazz, Module.class);
|
||||||
//获取这些类中的hook逻辑
|
//获取这些类中的hook逻辑
|
||||||
collectHookMethods(post, pre, classes);
|
collectHookMethods(post, pre, classes);
|
||||||
return new MethodsListRecord(post, pre);
|
return new MethodsListRecord(post, pre);
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package work.slhaf.partner.api.agent.factory.module.annotation;
|
|||||||
|
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于注解执行模块
|
* 用于注解执行模块
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package work.slhaf.partner.api.agent.factory.module.annotation;
|
|||||||
|
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package work.slhaf.partner.api.agent.factory.module.pojo;
|
package work.slhaf.partner.api.agent.factory.module.pojo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.Module;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.Module;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import work.slhaf.partner.api.agent.factory.config.pojo.ModelConfig;
|
import work.slhaf.partner.api.agent.factory.config.pojo.ModelConfig;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.Model;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.Model;
|
||||||
@@ -87,7 +88,9 @@ public interface ActivateModel {
|
|||||||
((Module) this).setModel(model);
|
((Module) this).setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
String modelKey();
|
default String modelKey(){
|
||||||
|
return this.getClass().getAnnotation(AgentModule.class).name();
|
||||||
|
}
|
||||||
|
|
||||||
boolean withBasicPrompt();
|
boolean withBasicPrompt();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package work.slhaf.partner.api.agent.util;
|
package work.slhaf.partner.api.agent.util;
|
||||||
|
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -40,8 +40,8 @@ public final class AgentUtil {
|
|||||||
collectInterfaces(clazz, classes);
|
collectInterfaces(clazz, classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Class<?>> getMethodAnnotationTypeSet(Class<?> clazz, Reflections reflections){
|
public static Set<Class<?>> getMethodAnnotationTypeSet(Class<? extends Annotation> clazz, Reflections reflections){
|
||||||
Set<Method> methods = reflections.getMethodsAnnotatedWith(Init.class);
|
Set<Method> methods = reflections.getMethodsAnnotatedWith(clazz);
|
||||||
return methods.stream()
|
return methods.stream()
|
||||||
.map(Method::getDeclaringClass)
|
.map(Method::getDeclaringClass)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ import work.slhaf.partner.api.agent.factory.capability.annotation.CoordinateMana
|
|||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Coordinated;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.Coordinated;
|
||||||
import work.slhaf.partner.api.chat.constant.ChatConstant;
|
import work.slhaf.partner.api.chat.constant.ChatConstant;
|
||||||
import work.slhaf.partner.common.exception.callback.GlobalExceptionHandler;
|
import work.slhaf.partner.common.exception.callback.GlobalExceptionHandler;
|
||||||
import work.slhaf.partner.runtime.exception.pojo.GlobalException;
|
|
||||||
import work.slhaf.partner.core.cognation.CognationCore;
|
import work.slhaf.partner.core.cognation.CognationCore;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
|
||||||
import work.slhaf.partner.core.common.pojo.MemorySliceResult;
|
|
||||||
import work.slhaf.partner.core.submodule.cache.CacheCore;
|
import work.slhaf.partner.core.submodule.cache.CacheCore;
|
||||||
import work.slhaf.partner.core.submodule.dispatch.DispatchCore;
|
import work.slhaf.partner.core.submodule.dispatch.DispatchCore;
|
||||||
import work.slhaf.partner.core.submodule.memory.MemoryCore;
|
import work.slhaf.partner.core.submodule.memory.MemoryCore;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySliceResult;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCore;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCore;
|
||||||
|
import work.slhaf.partner.runtime.exception.pojo.GlobalException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package work.slhaf.partner.core.cognation;
|
package work.slhaf.partner.core.cognation;
|
||||||
|
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.ToCoordinated;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.ToCoordinated;
|
||||||
import work.slhaf.partner.api.chat.pojo.Message;
|
import work.slhaf.partner.api.chat.pojo.Message;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
||||||
@@ -13,37 +12,16 @@ import java.util.concurrent.locks.Lock;
|
|||||||
@Capability("cognation")
|
@Capability("cognation")
|
||||||
public interface CognationCapability {
|
public interface CognationCapability {
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
List<Message> getChatMessages();
|
List<Message> getChatMessages();
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
void setChatMessages(List<Message> chatMessages);
|
void setChatMessages(List<Message> chatMessages);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
void cleanMessage(List<Message> messages);
|
void cleanMessage(List<Message> messages);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
void updateActivatedSlices(String userId, List<EvaluatedSlice> memorySlices);
|
void updateActivatedSlices(String userId, List<EvaluatedSlice> memorySlices);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
String getActivatedSlicesStr(String userId);
|
String getActivatedSlicesStr(String userId);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
HashMap<String, List<EvaluatedSlice>> getActivatedSlices();
|
HashMap<String, List<EvaluatedSlice>> getActivatedSlices();
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
void clearActivatedSlices(String userId);
|
void clearActivatedSlices(String userId);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
boolean hasActivatedSlices(String userId);
|
boolean hasActivatedSlices(String userId);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
int getActivatedSlicesSize(String userId);
|
int getActivatedSlicesSize(String userId);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
List<EvaluatedSlice> getActivatedSlices(String userId);
|
List<EvaluatedSlice> getActivatedSlices(String userId);
|
||||||
|
|
||||||
@CapabilityMethod
|
|
||||||
Lock getMessageLock();
|
Lock getMessageLock();
|
||||||
|
|
||||||
@ToCoordinated
|
@ToCoordinated
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
|
||||||
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
||||||
import work.slhaf.partner.api.chat.pojo.Message;
|
import work.slhaf.partner.api.chat.pojo.Message;
|
||||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||||
import work.slhaf.partner.core.cognation.pojo.ActiveData;
|
import work.slhaf.partner.core.cognation.pojo.ActiveData;
|
||||||
@@ -66,6 +67,16 @@ public class CognationCore extends PersistableObject {
|
|||||||
temp.setPerceiveCore(PerceiveCore.getInstance());
|
temp.setPerceiveCore(PerceiveCore.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
|
public List<Message> getChatMessages() {
|
||||||
|
return chatMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
|
public void setChatMessages(List<Message> chatMessages) {
|
||||||
|
this.chatMessages = chatMessages;
|
||||||
|
}
|
||||||
|
|
||||||
private void setupHook(CognationCore temp) {
|
private void setupHook(CognationCore temp) {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -131,6 +142,7 @@ public class CognationCore extends PersistableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public void cleanMessage(List<Message> messages) {
|
public void cleanMessage(List<Message> messages) {
|
||||||
messageLock.lock();
|
messageLock.lock();
|
||||||
this.getChatMessages().removeAll(messages);
|
this.getChatMessages().removeAll(messages);
|
||||||
@@ -138,31 +150,38 @@ public class CognationCore extends PersistableObject {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public void updateActivatedSlices(String userId, List<EvaluatedSlice> memorySlices) {
|
public void updateActivatedSlices(String userId, List<EvaluatedSlice> memorySlices) {
|
||||||
activeData.updateActivatedSlices(userId, memorySlices);
|
activeData.updateActivatedSlices(userId, memorySlices);
|
||||||
log.debug("[CoordinatedManager] 已更新激活切片, userId: {}", userId);
|
log.debug("[CoordinatedManager] 已更新激活切片, userId: {}", userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public String getActivatedSlicesStr(String userId) {
|
public String getActivatedSlicesStr(String userId) {
|
||||||
return activeData.getActivatedSlicesStr(userId);
|
return activeData.getActivatedSlicesStr(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public HashMap<String, List<EvaluatedSlice>> getActivatedSlices() {
|
public HashMap<String, List<EvaluatedSlice>> getActivatedSlices() {
|
||||||
return activeData.getActivatedSlices();
|
return activeData.getActivatedSlices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public void clearActivatedSlices(String userId) {
|
public void clearActivatedSlices(String userId) {
|
||||||
activeData.clearActivatedSlices(userId);
|
activeData.clearActivatedSlices(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public boolean hasActivatedSlices(String userId) {
|
public boolean hasActivatedSlices(String userId) {
|
||||||
return activeData.hasActivatedSlices(userId);
|
return activeData.hasActivatedSlices(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public int getActivatedSlicesSize(String userId) {
|
public int getActivatedSlicesSize(String userId) {
|
||||||
return activeData.getActivatedSlices().get(userId).size();
|
return activeData.getActivatedSlices().get(userId).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CapabilityMethod
|
||||||
public List<EvaluatedSlice> getActivatedSlices(String userId) {
|
public List<EvaluatedSlice> getActivatedSlices(String userId) {
|
||||||
return activeData.getActivatedSlices().get(userId);
|
return activeData.getActivatedSlices().get(userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
||||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.core.submodule.memory;
|
|||||||
|
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.ToCoordinated;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.ToCoordinated;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import lombok.EqualsAndHashCode;
|
|||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
||||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
|
||||||
import work.slhaf.partner.core.common.pojo.MemorySliceResult;
|
|
||||||
import work.slhaf.partner.core.submodule.memory.exception.UnExistedDateIndexException;
|
import work.slhaf.partner.core.submodule.memory.exception.UnExistedDateIndexException;
|
||||||
import work.slhaf.partner.core.submodule.memory.exception.UnExistedTopicException;
|
import work.slhaf.partner.core.submodule.memory.exception.UnExistedTopicException;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySliceResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.node.MemoryNode;
|
import work.slhaf.partner.core.submodule.memory.pojo.node.MemoryNode;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.node.TopicNode;
|
import work.slhaf.partner.core.submodule.memory.pojo.node.TopicNode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package work.slhaf.partner.core.common.pojo;
|
package work.slhaf.partner.core.submodule.memory.pojo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package work.slhaf.partner.core.common.pojo;
|
package work.slhaf.partner.core.submodule.memory.pojo;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
@@ -1,28 +1,45 @@
|
|||||||
package work.slhaf.partner.module.common.module;
|
package work.slhaf.partner.module.common.module;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前置模块抽象类
|
* 前置模块抽象类
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public abstract class PreRunningModule extends AgentRunningModule<PartnerRunningFlowContext> {
|
public abstract class PreRunningModule extends AgentRunningModule<PartnerRunningFlowContext> {
|
||||||
protected void setAppendedPrompt(PartnerRunningFlowContext context) {
|
private void setAppendedPrompt(PartnerRunningFlowContext context) {
|
||||||
AppendPromptData data = new AppendPromptData();
|
AppendPromptData data = new AppendPromptData();
|
||||||
data.setModuleName(moduleName());
|
data.setModuleName(moduleName());
|
||||||
HashMap<String, String> map = getPromptDataMap(context.getUserId());
|
HashMap<String, String> map = getPromptDataMap(context.getUserId());
|
||||||
data.setAppendedPrompt(map);
|
data.setAppendedPrompt(map);
|
||||||
context.getModuleContext().getAppendedPrompt().add(data);
|
context.setAppendedPrompt(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setActiveModule(PartnerRunningFlowContext context) {
|
private void setActiveModule(PartnerRunningFlowContext context) {
|
||||||
context.getCoreContext().addActiveModule(moduleName());
|
context.getCoreContext().addActiveModule(moduleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract HashMap<String, String> getPromptDataMap(String userId);
|
protected abstract HashMap<String, String> getPromptDataMap(String userId);
|
||||||
|
|
||||||
protected abstract String moduleName();
|
protected abstract String moduleName();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void execute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException {
|
||||||
|
log.debug("[{}] 模块执行开始...", this.getClass().getAnnotation(AgentModule.class).name());
|
||||||
|
doExecute(context); // 子类实现差异化逻辑
|
||||||
|
setAppendedPrompt(context); // 通用逻辑
|
||||||
|
setActiveModule(context); // 通用逻辑
|
||||||
|
log.debug("[{}] 模块执行结束...", this.getClass().getAnnotation(AgentModule.class).name());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void doExecute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,12 @@ import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
|||||||
import work.slhaf.partner.api.chat.pojo.Message;
|
import work.slhaf.partner.api.chat.pojo.Message;
|
||||||
import work.slhaf.partner.api.chat.pojo.MetaMessage;
|
import work.slhaf.partner.api.chat.pojo.MetaMessage;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.runtime.session.SessionManager;
|
|
||||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
||||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||||
import work.slhaf.partner.module.common.module.CoreRunningModule;
|
import work.slhaf.partner.module.common.module.CoreRunningModule;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
import work.slhaf.partner.runtime.session.SessionManager;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -44,6 +43,8 @@ public class CoreModel extends CoreRunningModule implements ActivateModel {
|
|||||||
this.getModel().setChatMessages(chatMessages);
|
this.getModel().setChatMessages(chatMessages);
|
||||||
this.appendedMessages = new ArrayList<>();
|
this.appendedMessages = new ArrayList<>();
|
||||||
this.sessionManager = SessionManager.getInstance();
|
this.sessionManager = SessionManager.getInstance();
|
||||||
|
|
||||||
|
updateChatClientSettings();
|
||||||
log.info("[CoreModel] CoreModel注册完毕...");
|
log.info("[CoreModel] CoreModel注册完毕...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,11 +54,6 @@ public class CoreModel extends CoreRunningModule implements ActivateModel {
|
|||||||
chatClient().setTop_p(0.7);
|
chatClient().setTop_p(0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String modelKey() {
|
|
||||||
return "core_model";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean withBasicPrompt() {
|
public boolean withBasicPrompt() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -5,24 +5,24 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AfterExecute;
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
import work.slhaf.partner.api.agent.factory.module.annotation.InjectModule;
|
import work.slhaf.partner.api.agent.factory.module.annotation.InjectModule;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
|
||||||
import work.slhaf.partner.core.submodule.cache.CacheCapability;
|
import work.slhaf.partner.core.submodule.cache.CacheCapability;
|
||||||
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
||||||
import work.slhaf.partner.core.submodule.memory.exception.UnExistedDateIndexException;
|
import work.slhaf.partner.core.submodule.memory.exception.UnExistedDateIndexException;
|
||||||
import work.slhaf.partner.core.submodule.memory.exception.UnExistedTopicException;
|
import work.slhaf.partner.core.submodule.memory.exception.UnExistedTopicException;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.runtime.session.SessionManager;
|
|
||||||
import work.slhaf.partner.module.common.module.PreRunningModule;
|
import work.slhaf.partner.module.common.module.PreRunningModule;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.evaluator.SliceSelectEvaluator;
|
import work.slhaf.partner.module.modules.memory.selector.evaluator.SliceSelectEvaluator;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorInput;
|
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorInput;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.MemorySelectExtractor;
|
import work.slhaf.partner.module.modules.memory.selector.extractor.MemorySelectExtractor;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorMatchData;
|
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorMatchData;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorResult;
|
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorResult;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -50,8 +50,7 @@ public class MemorySelector extends PreRunningModule {
|
|||||||
private MemorySelectExtractor memorySelectExtractor;
|
private MemorySelectExtractor memorySelectExtractor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(PartnerRunningFlowContext runningFlowContext) throws IOException, ClassNotFoundException {
|
public void doExecute(PartnerRunningFlowContext runningFlowContext) throws IOException, ClassNotFoundException {
|
||||||
log.debug("[MemorySelector] 记忆回溯流程开始...");
|
|
||||||
String userId = runningFlowContext.getUserId();
|
String userId = runningFlowContext.getUserId();
|
||||||
//获取主题路径
|
//获取主题路径
|
||||||
ExtractorResult extractorResult = memorySelectExtractor.execute(runningFlowContext);
|
ExtractorResult extractorResult = memorySelectExtractor.execute(runningFlowContext);
|
||||||
@@ -60,11 +59,6 @@ public class MemorySelector extends PreRunningModule {
|
|||||||
List<EvaluatedSlice> evaluatedSlices = selectAndEvaluateMemory(runningFlowContext, extractorResult);
|
List<EvaluatedSlice> evaluatedSlices = selectAndEvaluateMemory(runningFlowContext, extractorResult);
|
||||||
cognationCapability.updateActivatedSlices(userId, evaluatedSlices);
|
cognationCapability.updateActivatedSlices(userId, evaluatedSlices);
|
||||||
}
|
}
|
||||||
//设置追加提示词
|
|
||||||
setAppendedPrompt(runningFlowContext);
|
|
||||||
setModuleContextRecall(runningFlowContext);
|
|
||||||
setActiveModule(runningFlowContext);
|
|
||||||
log.debug("[MemorySelector] 记忆回溯完成...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<EvaluatedSlice> selectAndEvaluateMemory(PartnerRunningFlowContext runningFlowContext, ExtractorResult extractorResult) throws IOException, ClassNotFoundException {
|
private List<EvaluatedSlice> selectAndEvaluateMemory(PartnerRunningFlowContext runningFlowContext, ExtractorResult extractorResult) throws IOException, ClassNotFoundException {
|
||||||
@@ -85,6 +79,7 @@ public class MemorySelector extends PreRunningModule {
|
|||||||
return memorySlices;
|
return memorySlices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterExecute(order = 1)
|
||||||
private void setModuleContextRecall(PartnerRunningFlowContext runningFlowContext) {
|
private void setModuleContextRecall(PartnerRunningFlowContext runningFlowContext) {
|
||||||
String userId = runningFlowContext.getUserId();
|
String userId = runningFlowContext.getUserId();
|
||||||
boolean recall = cognationCapability.hasActivatedSlices(userId);
|
boolean recall = cognationCapability.hasActivatedSlices(userId);
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
|||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
|
||||||
import work.slhaf.partner.core.common.pojo.MemorySliceResult;
|
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySliceResult;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorBatchInput;
|
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorBatchInput;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorInput;
|
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorInput;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorResult;
|
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.EvaluatorResult;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.SliceSummary;
|
import work.slhaf.partner.module.modules.memory.selector.evaluator.data.SliceSummary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.module.modules.memory.selector.evaluator.data;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import work.slhaf.partner.api.chat.pojo.Message;
|
import work.slhaf.partner.api.chat.pojo.Message;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunn
|
|||||||
import work.slhaf.partner.api.chat.pojo.Message;
|
import work.slhaf.partner.api.chat.pojo.Message;
|
||||||
import work.slhaf.partner.api.chat.pojo.MetaMessage;
|
import work.slhaf.partner.api.chat.pojo.MetaMessage;
|
||||||
import work.slhaf.partner.common.exception.callback.GlobalExceptionHandler;
|
import work.slhaf.partner.common.exception.callback.GlobalExceptionHandler;
|
||||||
import work.slhaf.partner.runtime.exception.pojo.GlobalException;
|
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.EvaluatedSlice;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.runtime.session.SessionManager;
|
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorInput;
|
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorInput;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorMatchData;
|
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorMatchData;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorResult;
|
import work.slhaf.partner.module.modules.memory.selector.extractor.data.ExtractorResult;
|
||||||
|
import work.slhaf.partner.runtime.exception.pojo.GlobalException;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
import work.slhaf.partner.runtime.session.SessionManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -16,15 +16,15 @@ import work.slhaf.partner.core.submodule.cache.CacheCapability;
|
|||||||
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
||||||
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
import work.slhaf.partner.core.submodule.memory.pojo.MemorySlice;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.runtime.session.SessionManager;
|
|
||||||
import work.slhaf.partner.module.common.module.PostRunningModule;
|
import work.slhaf.partner.module.common.module.PostRunningModule;
|
||||||
import work.slhaf.partner.module.modules.memory.selector.extractor.MemorySelectExtractor;
|
import work.slhaf.partner.module.modules.memory.updater.summarizer.MultiSummarizer;
|
||||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.MemorySummarizer;
|
import work.slhaf.partner.module.modules.memory.updater.summarizer.SingleSummarizer;
|
||||||
|
import work.slhaf.partner.module.modules.memory.updater.summarizer.TotalSummarizer;
|
||||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeInput;
|
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeInput;
|
||||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeResult;
|
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeResult;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
import work.slhaf.partner.runtime.session.SessionManager;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -35,11 +35,9 @@ import static work.slhaf.partner.common.util.ExtractUtil.extractUserId;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AgentModule(name="memory_updater",order=6)
|
@AgentModule(name = "memory_updater", order = 7)
|
||||||
public class MemoryUpdater extends PostRunningModule {
|
public class MemoryUpdater extends PostRunningModule {
|
||||||
|
|
||||||
private static volatile MemoryUpdater memoryUpdater;
|
|
||||||
|
|
||||||
private static final long SCHEDULED_UPDATE_INTERVAL = 10 * 1000;
|
private static final long SCHEDULED_UPDATE_INTERVAL = 10 * 1000;
|
||||||
private static final long UPDATE_TRIGGER_INTERVAL = 60 * 60 * 1000;
|
private static final long UPDATE_TRIGGER_INTERVAL = 60 * 60 * 1000;
|
||||||
|
|
||||||
@@ -53,9 +51,11 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
|
|
||||||
@InjectModule
|
@InjectModule
|
||||||
private MemorySelectExtractor memorySelectExtractor;
|
private MultiSummarizer multiSummarizer;
|
||||||
@InjectModule
|
@InjectModule
|
||||||
private MemorySummarizer memorySummarizer;
|
private SingleSummarizer singleSummarizer;
|
||||||
|
@InjectModule
|
||||||
|
private TotalSummarizer totalSummarizer;
|
||||||
|
|
||||||
private SessionManager sessionManager;
|
private SessionManager sessionManager;
|
||||||
private InteractionThreadPoolExecutor executor;
|
private InteractionThreadPoolExecutor executor;
|
||||||
@@ -64,20 +64,6 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
*/
|
*/
|
||||||
private List<Message> tempMessage;
|
private List<Message> tempMessage;
|
||||||
|
|
||||||
public static MemoryUpdater getInstance() throws IOException, ClassNotFoundException {
|
|
||||||
if (memoryUpdater == null) {
|
|
||||||
synchronized (MemoryUpdater.class) {
|
|
||||||
if (memoryUpdater == null) {
|
|
||||||
memoryUpdater = new MemoryUpdater();
|
|
||||||
memoryUpdater.setSessionManager(SessionManager.getInstance());
|
|
||||||
memoryUpdater.setExecutor(InteractionThreadPoolExecutor.getInstance());
|
|
||||||
memoryUpdater.setScheduledUpdater();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return memoryUpdater;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Init
|
@Init
|
||||||
public void init() {
|
public void init() {
|
||||||
executor = InteractionThreadPoolExecutor.getInstance();
|
executor = InteractionThreadPoolExecutor.getInstance();
|
||||||
@@ -170,7 +156,7 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
}
|
}
|
||||||
SummarizeInput summarizeInput = new SummarizeInput(chatMessages, memoryCapability.getTopicTree());
|
SummarizeInput summarizeInput = new SummarizeInput(chatMessages, memoryCapability.getTopicTree());
|
||||||
log.debug("[MemoryUpdater] 多人聊天记忆更新-总结流程-输入: {}", summarizeInput);
|
log.debug("[MemoryUpdater] 多人聊天记忆更新-总结流程-输入: {}", summarizeInput);
|
||||||
SummarizeResult summarizeResult = memorySummarizer.execute(summarizeInput);
|
SummarizeResult summarizeResult = summarize(summarizeInput);
|
||||||
log.debug("[MemoryUpdater] 多人聊天记忆更新-总结流程-输出: {}", summarizeResult);
|
log.debug("[MemoryUpdater] 多人聊天记忆更新-总结流程-输出: {}", summarizeResult);
|
||||||
MemorySlice memorySlice = getMemorySlice(userId, summarizeResult, chatMessages);
|
MemorySlice memorySlice = getMemorySlice(userId, summarizeResult, chatMessages);
|
||||||
// 设置involvedUserId
|
// 设置involvedUserId
|
||||||
@@ -181,7 +167,7 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.debug("[MemoryUpdater] 不存在多人聊天记录, 将以单聊总结为对话缓存的主要输入: {}", singleMemorySummary);
|
log.debug("[MemoryUpdater] 不存在多人聊天记录, 将以单聊总结为对话缓存的主要输入: {}", singleMemorySummary);
|
||||||
cacheCapability.updateDialogMap(LocalDateTime.now(), memorySummarizer.executeTotalSummary(singleMemorySummary));
|
cacheCapability.updateDialogMap(LocalDateTime.now(), totalSummarizer.execute(singleMemorySummary));
|
||||||
}
|
}
|
||||||
log.debug("[MemoryUpdater] 对话缓存更新完毕");
|
log.debug("[MemoryUpdater] 对话缓存更新完毕");
|
||||||
log.debug("[MemoryUpdater] 多人聊天记忆更新流程结束...");
|
log.debug("[MemoryUpdater] 多人聊天记忆更新流程结束...");
|
||||||
@@ -205,7 +191,8 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
private void clearChatMessages() {
|
private void clearChatMessages() {
|
||||||
// 不全部清空,保留一部分输入防止上下文割裂
|
// 不全部清空,保留一部分输入防止上下文割裂
|
||||||
cognationCapability.getMessageLock().lock();
|
cognationCapability.getMessageLock().lock();
|
||||||
List<Message> temp = new ArrayList<>(tempMessage.subList(tempMessage.size() - tempMessage.size() / 6, tempMessage.size()));
|
List<Message> temp = new ArrayList<>(
|
||||||
|
tempMessage.subList(tempMessage.size() - tempMessage.size() / 6, tempMessage.size()));
|
||||||
cognationCapability.getChatMessages().removeAll(tempMessage);
|
cognationCapability.getChatMessages().removeAll(tempMessage);
|
||||||
cognationCapability.getChatMessages().addAll(0, temp);
|
cognationCapability.getChatMessages().addAll(0, temp);
|
||||||
cognationCapability.getMessageLock().unlock();
|
cognationCapability.getMessageLock().unlock();
|
||||||
@@ -229,7 +216,6 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateSingleChatSlices(HashMap<String, String> singleMemorySummary) {
|
private void updateSingleChatSlices(HashMap<String, String> singleMemorySummary) {
|
||||||
log.debug("[MemoryUpdater] 单聊记忆更新流程开始...");
|
log.debug("[MemoryUpdater] 单聊记忆更新流程开始...");
|
||||||
// 更新单聊记忆,同时从chatMessages中去掉单聊记忆
|
// 更新单聊记忆,同时从chatMessages中去掉单聊记忆
|
||||||
@@ -246,7 +232,7 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
// 单聊记忆更新
|
// 单聊记忆更新
|
||||||
SummarizeInput summarizeInput = new SummarizeInput(messages, memoryCapability.getTopicTree());
|
SummarizeInput summarizeInput = new SummarizeInput(messages, memoryCapability.getTopicTree());
|
||||||
log.debug("[MemoryUpdater] 单聊记忆[{}]更新-总结流程-输入: {}", thisCount, JSONObject.toJSONString(summarizeInput));
|
log.debug("[MemoryUpdater] 单聊记忆[{}]更新-总结流程-输入: {}", thisCount, JSONObject.toJSONString(summarizeInput));
|
||||||
SummarizeResult summarizeResult = memorySummarizer.execute(summarizeInput);
|
SummarizeResult summarizeResult = summarize(summarizeInput);
|
||||||
log.debug("[MemoryUpdater] 单聊记忆[{}]更新-总结流程-输出: {}", thisCount, JSONObject.toJSONString(summarizeResult));
|
log.debug("[MemoryUpdater] 单聊记忆[{}]更新-总结流程-输出: {}", thisCount, JSONObject.toJSONString(summarizeResult));
|
||||||
MemorySlice memorySlice = getMemorySlice(id, summarizeResult, messages);
|
MemorySlice memorySlice = getMemorySlice(id, summarizeResult, messages);
|
||||||
// 插入时userDialogMap已经进行更新
|
// 插入时userDialogMap已经进行更新
|
||||||
@@ -268,6 +254,11 @@ public class MemoryUpdater extends PostRunningModule {
|
|||||||
log.debug("[MemoryUpdater] 单聊记忆更新结束...");
|
log.debug("[MemoryUpdater] 单聊记忆更新结束...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SummarizeResult summarize(SummarizeInput summarizeInput) {
|
||||||
|
singleSummarizer.execute(summarizeInput.getChatMessages());
|
||||||
|
return multiSummarizer.execute(summarizeInput);
|
||||||
|
}
|
||||||
|
|
||||||
private MemorySlice getMemorySlice(String userId, SummarizeResult summarizeResult, List<Message> chatMessages) {
|
private MemorySlice getMemorySlice(String userId, SummarizeResult summarizeResult, List<Message> chatMessages) {
|
||||||
MemorySlice memorySlice = new MemorySlice();
|
MemorySlice memorySlice = new MemorySlice();
|
||||||
// 设置 memoryId,timestamp
|
// 设置 memoryId,timestamp
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package work.slhaf.partner.module.modules.memory.updater.summarizer;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
|
||||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
|
||||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeInput;
|
|
||||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeResult;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
@Slf4j
|
|
||||||
public class MemorySummarizer extends AgentRunningSubModule<SummarizeInput,SummarizeResult> {
|
|
||||||
|
|
||||||
private static volatile MemorySummarizer memorySummarizer;
|
|
||||||
public static final String MODEL_KEY = "memory_summarizer";
|
|
||||||
|
|
||||||
private InteractionThreadPoolExecutor executor;
|
|
||||||
private SingleSummarizer singleSummarizer;
|
|
||||||
private MultiSummarizer multiSummarizer;
|
|
||||||
private TotalSummarizer totalSummarizer;
|
|
||||||
|
|
||||||
public static MemorySummarizer getInstance() {
|
|
||||||
if (memorySummarizer == null) {
|
|
||||||
synchronized (MemorySummarizer.class) {
|
|
||||||
if (memorySummarizer == null) {
|
|
||||||
memorySummarizer = new MemorySummarizer();
|
|
||||||
memorySummarizer.setExecutor(InteractionThreadPoolExecutor.getInstance());
|
|
||||||
memorySummarizer.setSingleSummarizer(SingleSummarizer.getInstance());
|
|
||||||
memorySummarizer.setMultiSummarizer(MultiSummarizer.getInstance());
|
|
||||||
memorySummarizer.setTotalSummarizer(TotalSummarizer.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return memorySummarizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SummarizeResult execute(SummarizeInput input) {
|
|
||||||
//进行长文本批量摘要
|
|
||||||
singleSummarizer.execute(input.getChatMessages());
|
|
||||||
//进行整体摘要并返回结果
|
|
||||||
return multiSummarizer.execute(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String executeTotalSummary(HashMap<String, String> singleMemorySummary) {
|
|
||||||
return totalSummarizer.execute(singleMemorySummary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||||
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
||||||
@@ -20,24 +22,16 @@ import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@AgentSubModule
|
||||||
public class MultiSummarizer extends AgentRunningSubModule<SummarizeInput, SummarizeResult> implements ActivateModel {
|
public class MultiSummarizer extends AgentRunningSubModule<SummarizeInput, SummarizeResult> implements ActivateModel {
|
||||||
|
|
||||||
private static volatile MultiSummarizer multiSummarizer;
|
|
||||||
|
|
||||||
private MultiSummarizer() {
|
private MultiSummarizer() {
|
||||||
modelSettings();
|
modelSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiSummarizer getInstance() {
|
@Init
|
||||||
if (multiSummarizer == null) {
|
public void init() {
|
||||||
synchronized (MultiSummarizer.class) {
|
updateChatClientSettings();
|
||||||
if (multiSummarizer == null) {
|
|
||||||
multiSummarizer = new MultiSummarizer();
|
|
||||||
multiSummarizer.updateChatClientSettings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return multiSummarizer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||||
import work.slhaf.partner.api.chat.constant.ChatConstant;
|
import work.slhaf.partner.api.chat.constant.ChatConstant;
|
||||||
@@ -20,26 +22,14 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
|
@AgentSubModule
|
||||||
public class SingleSummarizer extends AgentRunningSubModule<List<Message>,Void> implements ActivateModel {
|
public class SingleSummarizer extends AgentRunningSubModule<List<Message>,Void> implements ActivateModel {
|
||||||
|
|
||||||
private static volatile SingleSummarizer singleSummarizer;
|
|
||||||
|
|
||||||
private InteractionThreadPoolExecutor executor;
|
private InteractionThreadPoolExecutor executor;
|
||||||
|
|
||||||
|
@Init
|
||||||
private SingleSummarizer() {
|
public void init() {
|
||||||
modelSettings();
|
this.executor = InteractionThreadPoolExecutor.getInstance();
|
||||||
}
|
|
||||||
public static SingleSummarizer getInstance() {
|
|
||||||
if (singleSummarizer == null) {
|
|
||||||
synchronized (SingleSummarizer.class) {
|
|
||||||
if (singleSummarizer == null) {
|
|
||||||
singleSummarizer = new SingleSummarizer();
|
|
||||||
singleSummarizer.setExecutor(InteractionThreadPoolExecutor.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return singleSummarizer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||||
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
||||||
@@ -16,25 +18,12 @@ import static work.slhaf.partner.common.util.ExtractUtil.extractJson;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@AgentSubModule
|
||||||
public class TotalSummarizer extends AgentRunningSubModule<HashMap<String, String>, String> implements ActivateModel {
|
public class TotalSummarizer extends AgentRunningSubModule<HashMap<String, String>, String> implements ActivateModel {
|
||||||
|
|
||||||
private static volatile TotalSummarizer totalSummarizer;
|
@Init
|
||||||
|
public void init() {
|
||||||
|
updateChatClientSettings();
|
||||||
private TotalSummarizer() {
|
|
||||||
modelSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TotalSummarizer getInstance() {
|
|
||||||
if (totalSummarizer == null) {
|
|
||||||
synchronized (TotalSummarizer.class) {
|
|
||||||
if (totalSummarizer == null) {
|
|
||||||
totalSummarizer = new TotalSummarizer();
|
|
||||||
totalSummarizer.updateChatClientSettings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return totalSummarizer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String execute(HashMap<String, String> singleMemorySummary){
|
public String execute(HashMap<String, String> singleMemorySummary){
|
||||||
|
|||||||
@@ -3,41 +3,24 @@ package work.slhaf.partner.module.modules.perceive.selector;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.module.common.module.PreRunningModule;
|
import work.slhaf.partner.module.common.module.PreRunningModule;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Setter
|
@Setter
|
||||||
|
@AgentModule(name = "perceive_selector",order = 2)
|
||||||
public class PerceiveSelector extends PreRunningModule {
|
public class PerceiveSelector extends PreRunningModule {
|
||||||
|
|
||||||
private static volatile PerceiveSelector perceiveSelector;
|
|
||||||
|
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
|
|
||||||
public static PerceiveSelector getInstance() throws IOException, ClassNotFoundException {
|
|
||||||
if (perceiveSelector == null) {
|
|
||||||
synchronized (PerceiveSelector.class) {
|
|
||||||
if (perceiveSelector == null) {
|
|
||||||
perceiveSelector = new PerceiveSelector();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return perceiveSelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException {
|
public void doExecute(PartnerRunningFlowContext context) {
|
||||||
log.debug("[PerceiveSelector] 感知模块处理流程开始...");
|
|
||||||
//处理思路: 根据用户id,查询用户相关身份感知数据,直接添加到appendPrompt中,这直接执行appendPrompt方法应该可以
|
|
||||||
setAppendedPrompt(context);
|
|
||||||
setActiveModule(context);
|
|
||||||
log.debug("[PerceiveSelector] 感知模块处理流程结束...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
package work.slhaf.partner.module.modules.perceive.updater;
|
package work.slhaf.partner.module.modules.perceive.updater;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.InjectModule;
|
||||||
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
||||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.RelationExtractor;
|
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.RelationExtractor;
|
||||||
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractResult;
|
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractResult;
|
||||||
import work.slhaf.partner.module.modules.perceive.updater.static_extractor.StaticMemoryExtractor;
|
import work.slhaf.partner.module.modules.perceive.updater.static_extractor.StaticMemoryExtractor;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -22,9 +27,11 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
/**
|
/**
|
||||||
* 感知更新,异步
|
* 感知更新,异步
|
||||||
*/
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
public class PerceiveUpdater {
|
@AgentModule(name = "perceive_updater", order = 8)
|
||||||
|
public class PerceiveUpdater extends AgentRunningModule<PartnerRunningFlowContext> {
|
||||||
|
|
||||||
private static volatile PerceiveUpdater perceiveUpdater;
|
private static volatile PerceiveUpdater perceiveUpdater;
|
||||||
|
|
||||||
@@ -32,23 +39,18 @@ public class PerceiveUpdater {
|
|||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private CognationCapability cognationCapability;
|
private CognationCapability cognationCapability;
|
||||||
private InteractionThreadPoolExecutor executor;
|
|
||||||
|
@InjectModule
|
||||||
private RelationExtractor relationExtractor;
|
private RelationExtractor relationExtractor;
|
||||||
|
@InjectModule
|
||||||
private StaticMemoryExtractor staticMemoryExtractor;
|
private StaticMemoryExtractor staticMemoryExtractor;
|
||||||
|
|
||||||
|
private InteractionThreadPoolExecutor executor;
|
||||||
|
|
||||||
public static PerceiveUpdater getInstance() throws IOException, ClassNotFoundException {
|
|
||||||
if (perceiveUpdater == null) {
|
@Init
|
||||||
synchronized (PerceiveUpdater.class) {
|
public void init() {
|
||||||
if (perceiveUpdater == null) {
|
this.executor = InteractionThreadPoolExecutor.getInstance();
|
||||||
perceiveUpdater = new PerceiveUpdater();
|
|
||||||
perceiveUpdater.setExecutor(InteractionThreadPoolExecutor.getInstance());
|
|
||||||
perceiveUpdater.setRelationExtractor(RelationExtractor.getInstance());
|
|
||||||
perceiveUpdater.setStaticMemoryExtractor(StaticMemoryExtractor.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return perceiveUpdater;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException {
|
public void execute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package work.slhaf.partner.module.modules.perceive.updater.relation_extractor;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||||
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
||||||
@@ -10,39 +12,26 @@ import work.slhaf.partner.api.chat.pojo.Message;
|
|||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractInput;
|
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractInput;
|
||||||
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractResult;
|
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractResult;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
|
@AgentSubModule
|
||||||
public class RelationExtractor extends AgentRunningSubModule<PartnerRunningFlowContext, RelationExtractResult> implements ActivateModel {
|
public class RelationExtractor extends AgentRunningSubModule<PartnerRunningFlowContext, RelationExtractResult> implements ActivateModel {
|
||||||
|
|
||||||
private static volatile RelationExtractor relationExtractor;
|
@InjectCapability
|
||||||
|
|
||||||
private CognationCapability cognationCapability;
|
private CognationCapability cognationCapability;
|
||||||
|
@InjectCapability
|
||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
|
|
||||||
private List<Message> tempMessages;
|
private List<Message> tempMessages;
|
||||||
|
|
||||||
private RelationExtractor(){
|
|
||||||
modelSettings();
|
|
||||||
}
|
|
||||||
public static RelationExtractor getInstance() throws IOException, ClassNotFoundException {
|
|
||||||
if (relationExtractor == null) {
|
|
||||||
synchronized (RelationExtractor.class) {
|
|
||||||
if (relationExtractor == null) {
|
|
||||||
relationExtractor = new RelationExtractor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return relationExtractor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RelationExtractResult execute(PartnerRunningFlowContext context){
|
public RelationExtractResult execute(PartnerRunningFlowContext context){
|
||||||
|
|||||||
@@ -5,19 +5,20 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||||
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.module.modules.perceive.updater.static_extractor.data.StaticMemoryExtractInput;
|
import work.slhaf.partner.module.modules.perceive.updater.static_extractor.data.StaticMemoryExtractInput;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
|
@AgentSubModule
|
||||||
public class StaticMemoryExtractor extends AgentRunningSubModule<PartnerRunningFlowContext, HashMap<String, String>> implements ActivateModel {
|
public class StaticMemoryExtractor extends AgentRunningSubModule<PartnerRunningFlowContext, HashMap<String, String>> implements ActivateModel {
|
||||||
|
|
||||||
private static volatile StaticMemoryExtractor staticMemoryExtractor;
|
private static volatile StaticMemoryExtractor staticMemoryExtractor;
|
||||||
@@ -27,21 +28,6 @@ public class StaticMemoryExtractor extends AgentRunningSubModule<PartnerRunningF
|
|||||||
@InjectCapability
|
@InjectCapability
|
||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
|
|
||||||
private StaticMemoryExtractor() {
|
|
||||||
modelSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StaticMemoryExtractor getInstance() throws IOException, ClassNotFoundException {
|
|
||||||
if (staticMemoryExtractor == null) {
|
|
||||||
synchronized (StaticMemoryExtractor.class) {
|
|
||||||
if (staticMemoryExtractor == null) {
|
|
||||||
staticMemoryExtractor = new StaticMemoryExtractor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return staticMemoryExtractor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, String> execute(PartnerRunningFlowContext context) {
|
public HashMap<String, String> execute(PartnerRunningFlowContext context) {
|
||||||
StaticMemoryExtractInput input = StaticMemoryExtractInput.builder()
|
StaticMemoryExtractInput input = StaticMemoryExtractInput.builder()
|
||||||
|
|||||||
@@ -4,34 +4,24 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.module.common.module.PostRunningModule;
|
import work.slhaf.partner.module.common.module.PostRunningModule;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
|
@AgentModule(name = "postprocess_executor", order = 6)
|
||||||
public class PostprocessExecutor extends PostRunningModule {
|
public class PostprocessExecutor extends PostRunningModule {
|
||||||
|
|
||||||
private static volatile PostprocessExecutor postprocessExecutor;
|
|
||||||
private static final int POST_PROCESS_TRIGGER_ROLL_LIMIT = 36;
|
private static final int POST_PROCESS_TRIGGER_ROLL_LIMIT = 36;
|
||||||
|
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private CognationCapability cognationCapability;
|
private CognationCapability cognationCapability;
|
||||||
|
|
||||||
public static PostprocessExecutor getInstance() throws IOException, ClassNotFoundException {
|
|
||||||
if (postprocessExecutor == null) {
|
|
||||||
synchronized (PostprocessExecutor.class) {
|
|
||||||
if (postprocessExecutor == null) {
|
|
||||||
postprocessExecutor = new PostprocessExecutor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return postprocessExecutor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException {
|
public void execute(PartnerRunningFlowContext context) throws IOException, ClassNotFoundException {
|
||||||
boolean trigger = cognationCapability.getChatMessages().size() >= POST_PROCESS_TRIGGER_ROLL_LIMIT;
|
boolean trigger = cognationCapability.getChatMessages().size() >= POST_PROCESS_TRIGGER_ROLL_LIMIT;
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import lombok.Data;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder;
|
||||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||||
|
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
import work.slhaf.partner.core.submodule.perceive.PerceiveCapability;
|
||||||
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
import work.slhaf.partner.core.submodule.perceive.pojo.User;
|
||||||
import work.slhaf.partner.runtime.interaction.data.PartnerInputData;
|
import work.slhaf.partner.module.common.module.PreRunningModule;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
import work.slhaf.partner.runtime.interaction.data.context.subcontext.CoreContext;
|
||||||
import work.slhaf.partner.runtime.session.SessionManager;
|
import work.slhaf.partner.runtime.session.SessionManager;
|
||||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -20,7 +20,7 @@ import java.util.HashMap;
|
|||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@CapabilityHolder
|
@CapabilityHolder
|
||||||
public class PreprocessExecutor {
|
public class PreprocessExecutor extends PreRunningModule {
|
||||||
|
|
||||||
private static volatile PreprocessExecutor preprocessExecutor;
|
private static volatile PreprocessExecutor preprocessExecutor;
|
||||||
|
|
||||||
@@ -30,24 +30,15 @@ public class PreprocessExecutor {
|
|||||||
private PerceiveCapability perceiveCapability;
|
private PerceiveCapability perceiveCapability;
|
||||||
private SessionManager sessionManager;
|
private SessionManager sessionManager;
|
||||||
|
|
||||||
private PreprocessExecutor() {
|
@Init
|
||||||
|
public void init() {
|
||||||
|
this.sessionManager = SessionManager.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PreprocessExecutor getInstance() throws IOException, ClassNotFoundException {
|
@Override
|
||||||
if (preprocessExecutor == null) {
|
public void doExecute(PartnerRunningFlowContext context) {
|
||||||
synchronized (PreprocessExecutor.class) {
|
|
||||||
if (preprocessExecutor == null) {
|
|
||||||
preprocessExecutor = new PreprocessExecutor();
|
|
||||||
preprocessExecutor.setSessionManager(SessionManager.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return preprocessExecutor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PartnerRunningFlowContext execute(PartnerInputData inputData) {
|
|
||||||
checkAndSetMemoryId();
|
checkAndSetMemoryId();
|
||||||
return getInteractionContext(inputData);
|
getInteractionContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAndSetMemoryId() {
|
private void checkAndSetMemoryId() {
|
||||||
@@ -57,29 +48,25 @@ public class PreprocessExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PartnerRunningFlowContext getInteractionContext(PartnerInputData inputData) {
|
private void getInteractionContext(PartnerRunningFlowContext context) {
|
||||||
log.debug("[PreprocessExecutor] 预处理原始输入: {}", inputData);
|
log.debug("[PreprocessExecutor] 预处理原始输入: {}", context);
|
||||||
PartnerRunningFlowContext context = new PartnerRunningFlowContext();
|
User user = perceiveCapability.getUser(context.getUserInfo(), context.getPlatform());
|
||||||
|
|
||||||
User user = perceiveCapability.getUser(inputData.getUserInfo(), inputData.getPlatform());
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = perceiveCapability.addUser(inputData.getUserInfo(), inputData.getPlatform(), inputData.getUserNickName());
|
user = perceiveCapability.addUser(context.getUserInfo(), context.getPlatform(), context.getUserNickname());
|
||||||
}
|
}
|
||||||
String userId = user.getUuid();
|
String userId = user.getUuid();
|
||||||
context.setUserId(userId);
|
context.setUserId(userId);
|
||||||
|
|
||||||
String userStr = "[" + inputData.getUserNickName() + "(" + userId + ")]";
|
String userStr = "[" + context.getUserNickname() + "(" + userId + ")]";
|
||||||
String input = userStr + " " + inputData.getContent();
|
String input = userStr + " " + context.getInput();
|
||||||
context.setInput(input);
|
context.setInput(input);
|
||||||
|
setCoreContext(context);
|
||||||
setAppendedPrompt(context);
|
|
||||||
setCoreContext(inputData, context, input, userId);
|
|
||||||
|
|
||||||
log.debug("[PreprocessExecutor] 预处理结果: {}", context);
|
log.debug("[PreprocessExecutor] 预处理结果: {}", context);
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAppendedPrompt(PartnerRunningFlowContext context) {
|
|
||||||
|
@Override
|
||||||
|
protected HashMap<String, String> getPromptDataMap(String userId) {
|
||||||
HashMap<String, String> map = new HashMap<>();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
map.put("text", "这部分才是真正的用户输入内容, 就像你之前收到过的输入一样。但...不会是'同一个人'。");
|
map.put("text", "这部分才是真正的用户输入内容, 就像你之前收到过的输入一样。但...不会是'同一个人'。");
|
||||||
map.put("datetime", "本次用户输入对应的当前时间");
|
map.put("datetime", "本次用户输入对应的当前时间");
|
||||||
@@ -87,16 +74,19 @@ public class PreprocessExecutor {
|
|||||||
map.put("user_id", "用户id, 与user_nick区分, 这是用户的唯一标识");
|
map.put("user_id", "用户id, 与user_nick区分, 这是用户的唯一标识");
|
||||||
map.put("active_modules", "已激活的模块, 为false时为激活但未活跃; 为true时为激活且活跃");
|
map.put("active_modules", "已激活的模块, 为false时为激活但未活跃; 为true时为激活且活跃");
|
||||||
map.put("其他", "历史对话中将在用户消息的最后一行标注时间");
|
map.put("其他", "历史对话中将在用户消息的最后一行标注时间");
|
||||||
AppendPromptData data = new AppendPromptData();
|
return map;
|
||||||
data.setModuleName("[基础模块]");
|
|
||||||
data.setAppendedPrompt(map);
|
|
||||||
context.setAppendedPrompt(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCoreContext(PartnerInputData inputData, PartnerRunningFlowContext context, String input, String userId) {
|
@Override
|
||||||
context.getCoreContext().setText(input);
|
protected String moduleName() {
|
||||||
context.getCoreContext().setDateTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
return "[基础模块]";
|
||||||
context.getCoreContext().setUserNick(inputData.getUserNickName());
|
}
|
||||||
context.getCoreContext().setUserId(userId);
|
|
||||||
|
private void setCoreContext(PartnerRunningFlowContext context) {
|
||||||
|
CoreContext coreContext = context.getCoreContext();
|
||||||
|
coreContext.setText(context.getInput());
|
||||||
|
coreContext.setDateTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
coreContext.setUserNick(context.getUserNickname());
|
||||||
|
coreContext.setUserId(context.getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ package work.slhaf.partner.module.modules.task;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningModule;
|
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TaskScheduler extends AgentRunningModule {
|
public class TaskScheduler {
|
||||||
private static TaskScheduler taskScheduler;
|
private static TaskScheduler taskScheduler;
|
||||||
|
|
||||||
private TaskScheduler() {
|
private TaskScheduler() {
|
||||||
@@ -22,7 +21,6 @@ public class TaskScheduler extends AgentRunningModule {
|
|||||||
return taskScheduler;
|
return taskScheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(PartnerRunningFlowContext runningFlowContext) {
|
public void execute(PartnerRunningFlowContext runningFlowContext) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ package work.slhaf.partner.runtime.exception.pojo;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.core.cognation.CognationCore;
|
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
|
|
||||||
import work.slhaf.partner.runtime.session.SessionManager;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class PartnerInteractionAdapter extends AgentInteractionAdapter<PartnerIn
|
|||||||
context.setUserInfo(inputData.getUserInfo());
|
context.setUserInfo(inputData.getUserInfo());
|
||||||
context.setDateTime(inputData.getDateTime());
|
context.setDateTime(inputData.getDateTime());
|
||||||
context.setSingle(inputData.isSingle());
|
context.setSingle(inputData.isSingle());
|
||||||
|
context.setPlatform(inputData.getPlatform());
|
||||||
|
context.setInput(inputData.getContent());
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.RunningFlowContext;
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.RunningFlowContext;
|
||||||
|
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.subcontext.CoreContext;
|
import work.slhaf.partner.runtime.interaction.data.context.subcontext.CoreContext;
|
||||||
import work.slhaf.partner.runtime.interaction.data.context.subcontext.ModuleContext;
|
import work.slhaf.partner.runtime.interaction.data.context.subcontext.ModuleContext;
|
||||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -25,6 +25,7 @@ public class PartnerRunningFlowContext extends RunningFlowContext {
|
|||||||
protected String userId;
|
protected String userId;
|
||||||
protected String userNickname;
|
protected String userNickname;
|
||||||
protected String userInfo;
|
protected String userInfo;
|
||||||
|
protected String platform;
|
||||||
protected LocalDateTime dateTime;
|
protected LocalDateTime dateTime;
|
||||||
protected boolean single;
|
protected boolean single;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import work.slhaf.partner.core.common.pojo.MemoryResult;
|
|
||||||
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
import work.slhaf.partner.core.submodule.memory.MemoryCapability;
|
||||||
|
import work.slhaf.partner.core.submodule.memory.pojo.MemoryResult;
|
||||||
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|||||||
Reference in New Issue
Block a user