mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-14 09:43:03 +08:00
推进核心服务与模块注册机制
- 完善Agent流程执行框架 - Api包下新增flow流程包,该部分对应模块的执行流程 - 明确ModuleFactory与CapabilityFactory以及ModuleHook的共同运作流程 - 调整了Hook注解名称
This commit is contained in:
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="2">
|
||||
<list size="3">
|
||||
<item index="0" class="java.lang.String" itemvalue="work.slhaf.partner.api.capability.annotation.CapabilityMethod" />
|
||||
<item index="1" class="java.lang.String" itemvalue="work.slhaf.partner.api.capability.annotation.CoordinateManager" />
|
||||
<item index="2" class="java.lang.String" itemvalue="work.slhaf.partner.api.register.capability.annotation.Capability" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
package work.slhaf.partner.api;
|
||||
|
||||
public class Agent {
|
||||
public static void run(Class<?> clazz) {
|
||||
import work.slhaf.partner.api.entity.AgentContext;
|
||||
import work.slhaf.partner.api.factory.AgentRegisterFactory;
|
||||
import work.slhaf.partner.api.flow.AgentInteraction;
|
||||
|
||||
/**
|
||||
* Agent启动类
|
||||
*/
|
||||
public class Agent {
|
||||
|
||||
public static void run(Class<?> clazz) {
|
||||
AgentContext context = AgentRegisterFactory.launch(clazz.getPackage().getName());
|
||||
AgentInteraction.launch(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package work.slhaf.partner.api;
|
||||
|
||||
import work.slhaf.partner.api.common.entity.AgentRegisterContext;
|
||||
|
||||
public class AgentRegisterFactory {
|
||||
|
||||
private AgentRegisterContext context = new AgentRegisterContext();
|
||||
|
||||
private AgentRegisterFactory(){}
|
||||
|
||||
public static void launch(){
|
||||
//TODO 通过调用module与capability的注册逻辑,完成完整的注册过程,需要考虑hook机制
|
||||
AgentRegisterFactory factory = new AgentRegisterFactory();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package work.slhaf.partner.common.chat;
|
||||
package work.slhaf.partner.api.common.chat;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import work.slhaf.partner.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatBody;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.chat.pojo.PrimaryChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatBody;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.PrimaryChatResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.common.chat.constant;
|
||||
package work.slhaf.partner.api.common.chat.constant;
|
||||
|
||||
public class ChatConstant {
|
||||
|
||||
@@ -8,13 +8,6 @@ public class ChatConstant {
|
||||
public static final String ASSISTANT = "assistant";
|
||||
}
|
||||
|
||||
public static class Model {
|
||||
public static final String DEEP_SEEK_CHAT = "deepseek-chat";
|
||||
public static final String GLM_4_FLASH = "glm-4_flash";
|
||||
public static final String GLM_4_PLUS = "glm-4_plus";
|
||||
public static final String GLM_4_0520 = "glm-4_0520";
|
||||
}
|
||||
|
||||
public static class Response {
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String ERROR = "error";
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.common.chat.pojo;
|
||||
package work.slhaf.partner.api.common.chat.pojo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.common.chat.pojo;
|
||||
package work.slhaf.partner.api.common.chat.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -1,7 +1,7 @@
|
||||
package work.slhaf.partner.common.chat.pojo;
|
||||
package work.slhaf.partner.api.common.chat.pojo;
|
||||
|
||||
import lombok.*;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package work.slhaf.partner.common.chat.pojo;
|
||||
package work.slhaf.partner.api.common.chat.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.common.chat.pojo;
|
||||
package work.slhaf.partner.api.common.chat.pojo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -1,10 +0,0 @@
|
||||
package work.slhaf.partner.api.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
@Data
|
||||
public class AgentRegisterContext {
|
||||
//TODO 抽取出必要的注册工厂共用的上下文
|
||||
private Reflections reflections;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.common.serialize;
|
||||
package work.slhaf.partner.api.common.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package work.slhaf.partner.api.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Data
|
||||
public class AgentContext {
|
||||
private HashMap<String, Function<Object[], Object>> methodsRouterTable;
|
||||
private HashMap<String, Function<Object[], Object>> coordinatedMethodsRouterTable;
|
||||
private HashMap<Class<?>, Object> capabilityCoreInstances;
|
||||
private HashMap<Class<?>, Object> capabilityHolderInstances;
|
||||
private Set<Class<?>> cores;
|
||||
private Set<Class<?>> capabilities;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package work.slhaf.partner.api.factory;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import work.slhaf.partner.api.entity.AgentContext;
|
||||
import work.slhaf.partner.api.factory.entity.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.factory.capability.CapabilityCheckFactory;
|
||||
import work.slhaf.partner.api.factory.capability.CapabilityRegisterFactory;
|
||||
import work.slhaf.partner.api.factory.module.ModuleCheckFactory;
|
||||
import work.slhaf.partner.api.factory.module.ModuleRegisterFactory;
|
||||
|
||||
public class AgentRegisterFactory {
|
||||
|
||||
private AgentRegisterFactory() {
|
||||
}
|
||||
|
||||
public static AgentContext launch(String path) {
|
||||
AgentRegisterContext registerContext = new AgentRegisterContext(path);
|
||||
//流程
|
||||
//1. 执行register和check逻辑
|
||||
new CapabilityRegisterFactory().execute(registerContext);
|
||||
new CapabilityCheckFactory().execute(registerContext);
|
||||
new ModuleRegisterFactory().execute(registerContext);
|
||||
new ModuleCheckFactory().execute(registerContext);
|
||||
|
||||
//2. 为module通过动态代理添加后hook逻辑并进行实例化
|
||||
|
||||
//3. 先一步注入Capability,避免因前hook逻辑存在针对能力的引用而报错
|
||||
|
||||
//4. 执行前hook逻辑
|
||||
|
||||
|
||||
AgentContext agentContext = new AgentContext();
|
||||
BeanUtil.copyProperties(registerContext,agentContext);
|
||||
return agentContext;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,178 +1,41 @@
|
||||
package work.slhaf.partner.api.capability;
|
||||
package work.slhaf.partner.api.factory.capability;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import work.slhaf.partner.api.capability.annotation.*;
|
||||
import work.slhaf.partner.api.capability.exception.*;
|
||||
import work.slhaf.partner.api.factory.entity.AgentBaseFactory;
|
||||
import work.slhaf.partner.api.factory.entity.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.common.util.AgentUtil;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.*;
|
||||
import work.slhaf.partner.api.factory.capability.exception.DuplicateCapabilityException;
|
||||
import work.slhaf.partner.api.factory.capability.exception.UnMatchedCapabilityException;
|
||||
import work.slhaf.partner.api.factory.capability.exception.UnMatchedCapabilityMethodException;
|
||||
import work.slhaf.partner.api.factory.capability.exception.UnMatchedCoordinatedMethodException;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.net.URL;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static work.slhaf.partner.api.common.util.AgentUtil.methodSignature;
|
||||
|
||||
|
||||
public final class CapabilityRegisterFactory {
|
||||
public class CapabilityCheckFactory extends AgentBaseFactory {
|
||||
|
||||
private Reflections reflections;
|
||||
private final HashMap<String, Function<Object[], Object>> methodsRouterTable = new HashMap<>();
|
||||
private final HashMap<String, Function<Object[], Object>> coordinatedMethodsRouterTable = new HashMap<>();
|
||||
private final HashMap<Class<?>, Object> capabilityCoreInstances = new HashMap<>();
|
||||
private final HashMap<Class<?>, Object> capabilityHolderInstances = new HashMap<>();
|
||||
private Set<Class<?>> cores;
|
||||
private Set<Class<?>> capabilities;
|
||||
|
||||
private CapabilityRegisterFactory() {
|
||||
|
||||
@Override
|
||||
protected void setVariables(AgentRegisterContext context) {
|
||||
reflections = context.getReflections();
|
||||
cores = context.getCores();
|
||||
capabilities = context.getCapabilities();
|
||||
}
|
||||
|
||||
//TODO 需决定是否分离检查与路由表生成、注入逻辑,如果分离,可进一步添加hook点,但目前似乎并非必要
|
||||
public void registerCapabilities(String scannerPath) {
|
||||
setBasicVariable(scannerPath);
|
||||
//检查可注册能力是否正常
|
||||
statusCheck();
|
||||
//扫描现有Capability, value为键,返回函数路由表, 函数路由表内部通过反射调用对应core的方法
|
||||
generateRouterTable();
|
||||
//通过动态代理注入能力
|
||||
injectCapability();
|
||||
}
|
||||
|
||||
private void generateRouterTable() {
|
||||
generateMethodsRouterTable();
|
||||
generateCoordinatedMethodsRouterTable();
|
||||
}
|
||||
|
||||
private void generateCoordinatedMethodsRouterTable() {
|
||||
Set<Method> methodsAnnotatedWith = reflections.getMethodsAnnotatedWith(Coordinated.class);
|
||||
if (methodsAnnotatedWith.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
//获取所有CM实例
|
||||
HashMap<String, Object> cognationManagerInstances = getCognationManagerInstances();
|
||||
methodsAnnotatedWith.forEach(method -> {
|
||||
String key = method.getAnnotation(Coordinated.class).capability() + "." + methodSignature(method);
|
||||
Function<Object[], Object> function = args -> {
|
||||
try {
|
||||
return method.invoke(cognationManagerInstances.get(key), args);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
coordinatedMethodsRouterTable.put(key, function);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new FactoryExecuteFailedException("创建协调方法路由表出错", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private HashMap<String, Object> getCognationManagerInstances() throws InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
for (Class<?> c : reflections.getTypesAnnotatedWith(CoordinateManager.class)) {
|
||||
Constructor<?> constructor = c.getDeclaredConstructor();
|
||||
Object instance = constructor.newInstance();
|
||||
|
||||
Arrays.stream(c.getMethods())
|
||||
.filter(method -> method.isAnnotationPresent(Coordinated.class))
|
||||
.forEach(method -> {
|
||||
String key = method.getAnnotation(Coordinated.class).capability() + "." + methodSignature(method);
|
||||
map.put(key, instance);
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void setBasicVariable(String scannerPath) {
|
||||
setReflections(scannerPath);
|
||||
setAnnotatedClasses();
|
||||
}
|
||||
|
||||
private void setAnnotatedClasses() {
|
||||
cores = reflections.getTypesAnnotatedWith(CapabilityCore.class);
|
||||
capabilities = reflections.getTypesAnnotatedWith(Capability.class);
|
||||
}
|
||||
|
||||
private void setReflections(String scannerPath) {
|
||||
//后续可替换为根据传入的启动类获取路径
|
||||
Collection<URL> urls = ClasspathHelper.forPackage(scannerPath);
|
||||
reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.setUrls(urls)
|
||||
.setScanners(
|
||||
Scanners.TypesAnnotated,
|
||||
Scanners.MethodsAnnotated,
|
||||
Scanners.SubTypes,
|
||||
Scanners.FieldsAnnotated
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private void generateMethodsRouterTable() {
|
||||
//扫描`@Capability`与`@CapabilityMethod`注解的类与方法
|
||||
//将`capabilityValue.methodSignature`作为key,函数对象为通过反射拿到的core实例对应的方法
|
||||
cores.forEach(core -> Arrays.stream(core.getMethods())
|
||||
.filter(method -> method.isAnnotationPresent(CapabilityMethod.class))
|
||||
.forEach(method -> {
|
||||
Function<Object[], Object> function = args -> {
|
||||
try {
|
||||
return method.invoke(capabilityCoreInstances.get(core), args);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
String key = core.getAnnotation(CapabilityCore.class).value() + "." + methodSignature(method);
|
||||
if (methodsRouterTable.containsKey(key)) {
|
||||
throw new DuplicateMethodException("重复注册能力方法: " + core.getPackage().getName() + "." + core.getSimpleName() + "#" + method.getName());
|
||||
}
|
||||
methodsRouterTable.put(key, function);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private void injectCapability() {
|
||||
//获取现有的`@InjectCapability`注解所在字段,并获取对应的类,通过动态代理注入对象
|
||||
Set<Field> fields = reflections.getFieldsAnnotatedWith(InjectCapability.class);
|
||||
//在动态代理内部,通过函数路由表调用对应的方法
|
||||
createProxy(fields);
|
||||
}
|
||||
|
||||
private void createProxy(Set<Field> fields) {
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
Class<?> fieldType = field.getType();
|
||||
Object instance = Proxy.newProxyInstance(
|
||||
fieldType.getClassLoader(),
|
||||
new Class[]{fieldType},
|
||||
(proxy, method, objects) -> {
|
||||
if (method.isAnnotationPresent(ToCoordinated.class)) {
|
||||
String key = method.getDeclaringClass().getAnnotation(Capability.class).value() + "." + methodSignature(method);
|
||||
return coordinatedMethodsRouterTable.get(key).apply(objects);
|
||||
}
|
||||
String key = fieldType.getAnnotation(Capability.class).value() + "." + methodSignature(method);
|
||||
return methodsRouterTable.get(key).apply(objects);
|
||||
}
|
||||
);
|
||||
field.set(capabilityHolderInstances.get(field.getDeclaringClass()), instance);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ProxySetFailedException("代理设置失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void statusCheck() {
|
||||
capabilityHolderCheck();
|
||||
@Override
|
||||
protected void run() {
|
||||
checkCountAndCapabilities();
|
||||
checkCapabilityMethods();
|
||||
checkCoordinatedMethods();
|
||||
checkInjectCapability();
|
||||
//检查完毕,设置core的实例类
|
||||
setCapabilityCoreInstances();
|
||||
}
|
||||
|
||||
private void checkInjectCapability() {
|
||||
@@ -183,25 +46,6 @@ public final class CapabilityRegisterFactory {
|
||||
});
|
||||
}
|
||||
|
||||
private void capabilityHolderCheck() {
|
||||
if (capabilityHolderInstances.isEmpty()) {
|
||||
throw new EmptyCapabilityHolderException("Capability 持有者实例为空");
|
||||
}
|
||||
}
|
||||
|
||||
private void setCapabilityCoreInstances() {
|
||||
try {
|
||||
for (Class<?> core : cores) {
|
||||
Constructor<?> constructor = core.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
capabilityCoreInstances.put(core, constructor.newInstance());
|
||||
}
|
||||
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException |
|
||||
IllegalAccessException e) {
|
||||
throw new CoreInstancesCreateFailedException("core实例创建失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCoordinatedMethods() {
|
||||
//检查各个capability中是否含有ToCoordinated注解
|
||||
//如果含有,则需要查找AbstractCognationManager的子类,看这里是否有对应的Coordinated注解所在方法
|
||||
@@ -249,7 +93,6 @@ public final class CapabilityRegisterFactory {
|
||||
return methodsCoordinated;
|
||||
}
|
||||
|
||||
|
||||
private void checkCapabilityMethods() {
|
||||
HashMap<String, List<Method>> capabilitiesMethods = getCapabilityMethods(capabilities);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -317,7 +160,6 @@ public final class CapabilityRegisterFactory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean checkValuesMatched(Set<Class<?>> cores, Set<Class<?>> capabilities) {
|
||||
Set<String> coresValues = new HashSet<>();
|
||||
Set<String> capabilitiesValues = new HashSet<>();
|
||||
@@ -342,10 +184,6 @@ public final class CapabilityRegisterFactory {
|
||||
return coresValues.equals(capabilitiesValues);
|
||||
}
|
||||
|
||||
public void registerModule(CapabilityHolder capabilityHolder) {
|
||||
capabilityHolderInstances.put(capabilityHolder.getClass(), capabilityHolder);
|
||||
}
|
||||
|
||||
record LackRecord(List<String> coreLack, List<String> capLack) {
|
||||
public boolean hasNotEmptyRecord() {
|
||||
return !coreLack.isEmpty() || !capLack.isEmpty();
|
||||
@@ -0,0 +1,67 @@
|
||||
package work.slhaf.partner.api.factory.capability;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import work.slhaf.partner.api.factory.entity.AgentBaseFactory;
|
||||
import work.slhaf.partner.api.factory.entity.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.ToCoordinated;
|
||||
import work.slhaf.partner.api.factory.capability.exception.ProxySetFailedException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static work.slhaf.partner.api.common.util.AgentUtil.methodSignature;
|
||||
|
||||
public class CapabilityInjectFactory extends AgentBaseFactory {
|
||||
|
||||
private Reflections reflections;
|
||||
private HashMap<String, Function<Object[], Object>> coordinatedMethodsRouterTable;
|
||||
private HashMap<String, Function<Object[], Object>> methodsRouterTable;
|
||||
private HashMap<Class<?>, Object> capabilityHolderInstances;
|
||||
|
||||
@Override
|
||||
protected void setVariables(AgentRegisterContext context) {
|
||||
reflections = context.getReflections();
|
||||
coordinatedMethodsRouterTable = context.getCoordinatedMethodsRouterTable();
|
||||
methodsRouterTable = context.getMethodsRouterTable();
|
||||
capabilityHolderInstances = context.getCapabilityHolderInstances();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
//获取现有的`@InjectCapability`注解所在字段,并获取对应的类,通过动态代理注入对象
|
||||
Set<Field> fields = reflections.getFieldsAnnotatedWith(InjectCapability.class);
|
||||
//在动态代理内部,通过函数路由表调用对应的方法
|
||||
createProxy(fields);
|
||||
|
||||
}
|
||||
|
||||
private void createProxy(Set<Field> fields) {
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
Class<?> fieldType = field.getType();
|
||||
Object instance = Proxy.newProxyInstance(
|
||||
fieldType.getClassLoader(),
|
||||
new Class[]{fieldType},
|
||||
(proxy, method, objects) -> {
|
||||
if (method.isAnnotationPresent(ToCoordinated.class)) {
|
||||
String key = method.getDeclaringClass().getAnnotation(Capability.class).value() + "." + methodSignature(method);
|
||||
return coordinatedMethodsRouterTable.get(key).apply(objects);
|
||||
}
|
||||
String key = fieldType.getAnnotation(Capability.class).value() + "." + methodSignature(method);
|
||||
return methodsRouterTable.get(key).apply(objects);
|
||||
}
|
||||
);
|
||||
field.set(capabilityHolderInstances.get(field.getDeclaringClass()), instance);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ProxySetFailedException("代理设置失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package work.slhaf.partner.api.factory.capability;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import work.slhaf.partner.api.factory.entity.AgentBaseFactory;
|
||||
import work.slhaf.partner.api.factory.entity.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.*;
|
||||
import work.slhaf.partner.api.factory.capability.exception.CoreInstancesCreateFailedException;
|
||||
import work.slhaf.partner.api.factory.capability.exception.DuplicateMethodException;
|
||||
import work.slhaf.partner.api.factory.capability.exception.FactoryExecuteFailedException;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static work.slhaf.partner.api.common.util.AgentUtil.methodSignature;
|
||||
|
||||
|
||||
public final class CapabilityRegisterFactory extends AgentBaseFactory {
|
||||
|
||||
private Reflections reflections;
|
||||
private HashMap<String, Function<Object[], Object>> methodsRouterTable;
|
||||
private HashMap<String, Function<Object[], Object>> coordinatedMethodsRouterTable;
|
||||
private HashMap<Class<?>, Object> capabilityCoreInstances;
|
||||
private HashMap<Class<?>, Object> capabilityHolderInstances;
|
||||
private Set<Class<?>> cores;
|
||||
private Set<Class<?>> capabilities;
|
||||
|
||||
@Override
|
||||
protected void setVariables(AgentRegisterContext context) {
|
||||
reflections = context.getReflections();
|
||||
methodsRouterTable = context.getMethodsRouterTable();
|
||||
coordinatedMethodsRouterTable = context.getCoordinatedMethodsRouterTable();
|
||||
capabilityCoreInstances = context.getCapabilityCoreInstances();
|
||||
capabilityHolderInstances = context.getCapabilityHolderInstances();
|
||||
cores = context.getCores();
|
||||
capabilities = context.getCapabilities();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
setCapabilityCoreInstances();
|
||||
setAnnotatedClasses();
|
||||
generateRouterTable();
|
||||
}
|
||||
|
||||
private void setAnnotatedClasses() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
cores.addAll(reflections.getTypesAnnotatedWith(CapabilityCore.class));
|
||||
capabilities.addAll(reflections.getTypesAnnotatedWith(Capability.class));
|
||||
setCapabilityHolderInstances();
|
||||
}
|
||||
|
||||
private void setCapabilityHolderInstances() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
for (Class<?> clazz : reflections.getTypesAnnotatedWith(CapabilityHolder.class)) {
|
||||
Object o = clazz.getDeclaredConstructor().newInstance();
|
||||
capabilityHolderInstances.put(clazz, o);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateRouterTable() {
|
||||
generateMethodsRouterTable();
|
||||
generateCoordinatedMethodsRouterTable();
|
||||
}
|
||||
|
||||
private void generateCoordinatedMethodsRouterTable() {
|
||||
Set<Method> methodsAnnotatedWith = reflections.getMethodsAnnotatedWith(Coordinated.class);
|
||||
if (methodsAnnotatedWith.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
//获取所有CM实例
|
||||
HashMap<String, Object> coordinateManagerInstances = getCoordinateManagerInstances();
|
||||
methodsAnnotatedWith.forEach(method -> {
|
||||
String key = method.getAnnotation(Coordinated.class).capability() + "." + methodSignature(method);
|
||||
Function<Object[], Object> function = args -> {
|
||||
try {
|
||||
return method.invoke(coordinateManagerInstances.get(key), args);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
coordinatedMethodsRouterTable.put(key, function);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new FactoryExecuteFailedException("创建协调方法路由表出错", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private HashMap<String, Object> getCoordinateManagerInstances() throws InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
for (Class<?> c : reflections.getTypesAnnotatedWith(CoordinateManager.class)) {
|
||||
Constructor<?> constructor = c.getDeclaredConstructor();
|
||||
Object instance = constructor.newInstance();
|
||||
|
||||
Arrays.stream(c.getMethods())
|
||||
.filter(method -> method.isAnnotationPresent(Coordinated.class))
|
||||
.forEach(method -> {
|
||||
String key = method.getAnnotation(Coordinated.class).capability() + "." + methodSignature(method);
|
||||
map.put(key, instance);
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void generateMethodsRouterTable() {
|
||||
//扫描`@Capability`与`@CapabilityMethod`注解的类与方法
|
||||
//将`capabilityValue.methodSignature`作为key,函数对象为通过反射拿到的core实例对应的方法
|
||||
cores.forEach(core -> Arrays.stream(core.getMethods())
|
||||
.filter(method -> method.isAnnotationPresent(CapabilityMethod.class))
|
||||
.forEach(method -> {
|
||||
Function<Object[], Object> function = args -> {
|
||||
try {
|
||||
return method.invoke(capabilityCoreInstances.get(core), args);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
String key = core.getAnnotation(CapabilityCore.class).value() + "." + methodSignature(method);
|
||||
if (methodsRouterTable.containsKey(key)) {
|
||||
throw new DuplicateMethodException("重复注册能力方法: " + core.getPackage().getName() + "." + core.getSimpleName() + "#" + method.getName());
|
||||
}
|
||||
methodsRouterTable.put(key, function);
|
||||
}));
|
||||
}
|
||||
|
||||
private void setCapabilityCoreInstances() {
|
||||
try {
|
||||
for (Class<?> core : cores) {
|
||||
Constructor<?> constructor = core.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
capabilityCoreInstances.put(core, constructor.newInstance());
|
||||
}
|
||||
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException |
|
||||
IllegalAccessException e) {
|
||||
throw new CoreInstancesCreateFailedException("core实例创建失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.annotation;
|
||||
package work.slhaf.partner.api.factory.capability.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class CapabilityCheckFailedException extends RuntimeException {
|
||||
public CapabilityCheckFailedException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class CoreInstancesCreateFailedException extends FactoryExecuteFailedException {
|
||||
public CoreInstancesCreateFailedException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class DuplicateCapabilityException extends CapabilityCheckFailedException {
|
||||
public DuplicateCapabilityException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class DuplicateMethodException extends CapabilityCheckFailedException{
|
||||
public DuplicateMethodException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class EmptyCapabilityHolderException extends CapabilityCheckFailedException{
|
||||
public EmptyCapabilityHolderException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class FactoryExecuteFailedException extends RuntimeException {
|
||||
public FactoryExecuteFailedException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class ProxySetFailedException extends FactoryExecuteFailedException{
|
||||
public ProxySetFailedException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class UnMatchedCapabilityException extends CapabilityCheckFailedException{
|
||||
public UnMatchedCapabilityException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class UnMatchedCapabilityMethodException extends CapabilityCheckFailedException {
|
||||
public UnMatchedCapabilityMethodException(String message) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package work.slhaf.partner.api.capability.exception;
|
||||
package work.slhaf.partner.api.factory.capability.exception;
|
||||
|
||||
public class UnMatchedCoordinatedMethodException extends CapabilityCheckFailedException {
|
||||
public UnMatchedCoordinatedMethodException(String message) {
|
||||
@@ -0,0 +1,20 @@
|
||||
package work.slhaf.partner.api.factory.entity;
|
||||
|
||||
import work.slhaf.partner.api.factory.capability.exception.FactoryExecuteFailedException;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public abstract class AgentBaseFactory {
|
||||
public void execute(AgentRegisterContext context) {
|
||||
try {
|
||||
setVariables(context);
|
||||
run();
|
||||
} catch (Exception e) {
|
||||
throw new FactoryExecuteFailedException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void setVariables(AgentRegisterContext context);
|
||||
|
||||
protected abstract void run() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package work.slhaf.partner.api.factory.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Data
|
||||
public class AgentRegisterContext {
|
||||
private Reflections reflections;
|
||||
private final HashMap<String, Function<Object[], Object>> methodsRouterTable = new HashMap<>();
|
||||
private final HashMap<String, Function<Object[], Object>> coordinatedMethodsRouterTable = new HashMap<>();
|
||||
private final HashMap<Class<?>, Object> capabilityCoreInstances = new HashMap<>();
|
||||
private final HashMap<Class<?>, Object> capabilityHolderInstances = new HashMap<>();
|
||||
private Set<Class<?>> cores;
|
||||
private Set<Class<?>> capabilities;
|
||||
|
||||
public AgentRegisterContext(String path) {
|
||||
reflections = new Reflections(path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package work.slhaf.partner.api.factory.module;
|
||||
|
||||
import work.slhaf.partner.api.factory.entity.AgentBaseFactory;
|
||||
import work.slhaf.partner.api.factory.entity.AgentRegisterContext;
|
||||
|
||||
public class ModuleCheckFactory extends AgentBaseFactory {
|
||||
@Override
|
||||
protected void setVariables(AgentRegisterContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
//检查注解AgentModule所在类是否继承了AgentInteractionModule
|
||||
//检查hook注解所在方法是否位于AgentInteractionModule子类/AgentInteractionSubModule子类/ActivateModel子类
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package work.slhaf.partner.api.factory.module;
|
||||
|
||||
public class ModuleHookExecutor {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package work.slhaf.partner.api.factory.module;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import work.slhaf.partner.api.factory.entity.AgentBaseFactory;
|
||||
import work.slhaf.partner.api.factory.entity.AgentRegisterContext;
|
||||
|
||||
public class ModuleRegisterFactory extends AgentBaseFactory {
|
||||
|
||||
private Reflections reflections;
|
||||
|
||||
@Override
|
||||
protected void setVariables(AgentRegisterContext context) {
|
||||
reflections = context.getReflections();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
//反射扫描获取InteractionModule所在类与hook注解所在方法
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package work.slhaf.partner.api.factory.module.annotation;
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface After {
|
||||
int order() default 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package work.slhaf.partner.api.factory.module.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 用于注解执行模块
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AgentModule {
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* 模块执行顺序,数字越小执行越靠前
|
||||
*/
|
||||
int order();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package work.slhaf.partner.api.factory.module.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Before {
|
||||
int order() default 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package work.slhaf.partner.api.flow;
|
||||
|
||||
import work.slhaf.partner.api.entity.AgentContext;
|
||||
|
||||
/**
|
||||
* Agent执行流程
|
||||
*/
|
||||
public class AgentInteraction {
|
||||
|
||||
private AgentInteraction(){}
|
||||
|
||||
public static void launch(AgentContext context){
|
||||
//流程执行启动,需考虑模块热插拔,可结合http调整模块启用情况,并序列化至本地或数据库中
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package work.slhaf.partner.api.flow.abstracts;
|
||||
|
||||
import work.slhaf.partner.api.common.chat.ChatClient;
|
||||
import work.slhaf.partner.api.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.factory.module.annotation.Before;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface ActivateModel {
|
||||
|
||||
|
||||
@Before
|
||||
default void modelSettings() {
|
||||
// Model model = new Model();
|
||||
// ModelConfig modelConfig = ModelConfig.load(modelKey());
|
||||
// model.setBaseMessages(withAwareness() ? ResourcesUtil.Prompt.loadPromptWithSelfAwareness(modelKey(), promptModule()) : ResourcesUtil.Prompt.loadPrompt(modelKey(), promptModule()));
|
||||
// model.setChatClient(new ChatClient(modelConfig.getBaseUrl(), modelConfig.getApikey(), modelConfig.getModel()));
|
||||
}
|
||||
|
||||
default ChatResponse chat() {
|
||||
Model model = getModel();
|
||||
List<Message> temp = new ArrayList<>();
|
||||
temp.addAll(model.getBaseMessages());
|
||||
temp.addAll(model.getChatMessages());
|
||||
return model.getChatClient().runChat(temp);
|
||||
}
|
||||
|
||||
default ChatResponse singleChat(String input) {
|
||||
Model model = getModel();
|
||||
List<Message> temp = new ArrayList<>(model.getBaseMessages());
|
||||
temp.add(new Message(ChatConstant.Character.USER, input));
|
||||
return model.getChatClient().runChat(temp);
|
||||
}
|
||||
|
||||
default void updateChatClientSettings() {
|
||||
Model model = getModel();
|
||||
model.getChatClient().setTemperature(0.4);
|
||||
model.getChatClient().setTop_p(0.8);
|
||||
}
|
||||
|
||||
default List<Message> chatMessages() {
|
||||
return getModel().getChatMessages();
|
||||
}
|
||||
|
||||
default List<Message> baseMessages() {
|
||||
return getModel().getBaseMessages();
|
||||
}
|
||||
|
||||
default ChatClient chatClient() {
|
||||
return getModel().getChatClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅适用Module子类,否则需要重写
|
||||
*
|
||||
* @return 持有的model实例
|
||||
*/
|
||||
default Model getModel() {
|
||||
return ((Module) this).getModel();
|
||||
}
|
||||
|
||||
default void setModel(Model model) {
|
||||
((Module) this).setModel(model);
|
||||
}
|
||||
|
||||
String modelKey();
|
||||
|
||||
boolean withAwareness();
|
||||
|
||||
String promptModule();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package work.slhaf.partner.api.flow.abstracts;
|
||||
|
||||
import work.slhaf.partner.api.flow.entity.InteractionFlowContext;
|
||||
|
||||
/**
|
||||
* 流程执行模块基类
|
||||
*/
|
||||
public abstract class AgentInteractionModule extends Module {
|
||||
public abstract void execute(InteractionFlowContext context);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package work.slhaf.partner.api.flow.abstracts;
|
||||
|
||||
|
||||
/**
|
||||
* 流程子模块基类
|
||||
* @param <I> 输入类型
|
||||
* @param <O> 输出类型
|
||||
*/
|
||||
public abstract class AgentInteractionSubModule<I, O> extends Module {
|
||||
|
||||
public abstract O execute(I data);
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package work.slhaf.partner.module.common.model;
|
||||
package work.slhaf.partner.api.flow.abstracts;
|
||||
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.ChatClient;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.ChatClient;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package work.slhaf.partner.api.flow.abstracts;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityHolder;
|
||||
|
||||
@CapabilityHolder
|
||||
public abstract class Module {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
protected Model model = new Model();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package work.slhaf.partner.api.flow.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 流程上下文
|
||||
*/
|
||||
@Data
|
||||
public class InteractionFlowContext {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package work.slhaf.partner.api.module;
|
||||
|
||||
public class ModuleRegisterFactory {
|
||||
}
|
||||
@@ -12,21 +12,6 @@
|
||||
<artifactId>Partner-Main</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.56</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.18.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.36</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
|
||||
@@ -101,7 +101,6 @@ public class Config {
|
||||
new ModuleConfig(CoreModel.class.getName(), ModuleConfig.Constant.INTERNAL, null),
|
||||
new ModuleConfig(PostprocessExecutor.class.getName(),ModuleConfig.Constant.INTERNAL,null),
|
||||
new ModuleConfig(MemoryUpdater.class.getName(), ModuleConfig.Constant.INTERNAL, null)
|
||||
// new ModuleConfig(TaskScheduler.class.getName(), ModuleConfig.Constant.INTERNAL, null)
|
||||
);
|
||||
config.setModuleConfigList(moduleConfigList);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.common.exception_handler.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCore;
|
||||
import work.slhaf.partner.core.interaction.data.context.InteractionContext;
|
||||
import work.slhaf.partner.core.session.SessionManager;
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.common.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import work.slhaf.partner.Agent;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -2,9 +2,9 @@ package work.slhaf.partner.core.cognation;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.CoordinateManager;
|
||||
import work.slhaf.partner.api.capability.annotation.Coordinated;
|
||||
import work.slhaf.partner.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CoordinateManager;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.Coordinated;
|
||||
import work.slhaf.partner.common.exception_handler.GlobalExceptionHandler;
|
||||
import work.slhaf.partner.common.exception_handler.pojo.GlobalException;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCore;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package work.slhaf.partner.core.cognation.cognation;
|
||||
|
||||
import work.slhaf.partner.api.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.api.capability.annotation.ToCoordinated;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.ToCoordinated;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.EvaluatedSlice;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -4,9 +4,9 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.core.cognation.cognation.pojo.ActiveData;
|
||||
import work.slhaf.partner.core.cognation.submodule.cache.CacheCore;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.MemoryCore;
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.core.cognation.common.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.MemorySlice;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.core.cognation.common.pojo;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.MemorySlice;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package work.slhaf.partner.core.cognation.submodule.cache;
|
||||
|
||||
import work.slhaf.partner.api.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.Capability;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -3,9 +3,9 @@ package work.slhaf.partner.core.cognation.submodule.cache;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemoryResult;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.MemorySlice;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package work.slhaf.partner.core.cognation.submodule.dispatch;
|
||||
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.core.cognation.submodule.dispatch.pojo.DispatchData;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package work.slhaf.partner.core.cognation.submodule.memory;
|
||||
|
||||
import work.slhaf.partner.api.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.capability.annotation.ToCoordinated;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.ToCoordinated;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemoryResult;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.MemorySlice;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package work.slhaf.partner.core.cognation.submodule.memory;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemoryResult;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemorySliceResult;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.exception.UnExistedDateIndexException;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.core.cognation.submodule.memory.pojo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -3,8 +3,8 @@ package work.slhaf.partner.core.cognation.submodule.memory.pojo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.core.cognation.submodule.memory.pojo.node;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.exception.NullSliceListException;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.MemorySlice;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.core.cognation.submodule.memory.pojo.node;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package work.slhaf.partner.core.cognation.submodule.perceive;
|
||||
|
||||
import work.slhaf.partner.api.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.pojo.User;
|
||||
|
||||
@Capability(value = "perceive")
|
||||
|
||||
@@ -2,9 +2,9 @@ package work.slhaf.partner.core.cognation.submodule.perceive;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityCore;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.core.cognation.cognation.exception.UserNotExistsException;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.pojo.User;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.core.cognation.submodule.perceive.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.core.interaction.data.context;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.core.interaction.data.context.subcontext.CoreContext;
|
||||
import work.slhaf.partner.core.interaction.data.context.subcontext.ModuleContext;
|
||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.core.interaction.data.context.subcontext;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.core.interaction.data.context.subcontext;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.chat.pojo.MetaMessage;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.MetaMessage;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
import work.slhaf.partner.common.config.Config;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.serialize.PersistableObject;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package work.slhaf.partner.module.common.model;
|
||||
|
||||
import work.slhaf.partner.common.chat.ChatClient;
|
||||
import work.slhaf.partner.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.config.ModelConfig;
|
||||
import work.slhaf.partner.common.util.ResourcesUtil;
|
||||
import work.slhaf.partner.module.common.module.Module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface ActivateModel {
|
||||
|
||||
default void modelSettings() {
|
||||
Model model = new Model();
|
||||
ModelConfig modelConfig = ModelConfig.load(modelKey());
|
||||
model.setBaseMessages(withAwareness() ? ResourcesUtil.Prompt.loadPromptWithSelfAwareness(modelKey(), promptModule()) : ResourcesUtil.Prompt.loadPrompt(modelKey(), promptModule()));
|
||||
model.setChatClient(new ChatClient(modelConfig.getBaseUrl(), modelConfig.getApikey(), modelConfig.getModel()));
|
||||
}
|
||||
|
||||
default ChatResponse chat() {
|
||||
Model model = getModel();
|
||||
List<Message> temp = new ArrayList<>();
|
||||
temp.addAll(model.baseMessages);
|
||||
temp.addAll(model.chatMessages);
|
||||
return model.chatClient.runChat(temp);
|
||||
}
|
||||
|
||||
default ChatResponse singleChat(String input) {
|
||||
Model model = getModel();
|
||||
List<Message> temp = new ArrayList<>(model.baseMessages);
|
||||
temp.add(new Message(ChatConstant.Character.USER, input));
|
||||
return model.chatClient.runChat(temp);
|
||||
}
|
||||
|
||||
default void updateChatClientSettings() {
|
||||
Model model = getModel();
|
||||
model.chatClient.setTemperature(0.4);
|
||||
model.chatClient.setTop_p(0.8);
|
||||
}
|
||||
|
||||
default List<Message> chatMessages() {
|
||||
return getModel().getChatMessages();
|
||||
}
|
||||
|
||||
default List<Message> baseMessages() {
|
||||
return getModel().getBaseMessages();
|
||||
}
|
||||
|
||||
default ChatClient chatClient() {
|
||||
return getModel().getChatClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅适用Module子类,否则需要重写
|
||||
*
|
||||
* @return 持有的model实例
|
||||
*/
|
||||
default Model getModel() {
|
||||
return ((Module) this).getModel();
|
||||
}
|
||||
|
||||
default void setModel(Model model) {
|
||||
((Module) this).setModel(model);
|
||||
}
|
||||
|
||||
String modelKey();
|
||||
|
||||
boolean withAwareness();
|
||||
|
||||
String promptModule();
|
||||
|
||||
}
|
||||
@@ -2,6 +2,6 @@ package work.slhaf.partner.module.common.module;
|
||||
|
||||
import work.slhaf.partner.core.interaction.module.InteractionFlow;
|
||||
|
||||
public abstract class InteractionModule extends Module implements InteractionFlow {
|
||||
public abstract class InteractionModule/* extends Module*/ implements InteractionFlow {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package work.slhaf.partner.module.common.module;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import work.slhaf.partner.api.capability.annotation.CapabilityHolder;
|
||||
import work.slhaf.partner.module.common.model.Model;
|
||||
|
||||
@CapabilityHolder
|
||||
public abstract class Module {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
protected Model model;
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package work.slhaf.partner.module.common.module;
|
||||
|
||||
|
||||
/**
|
||||
* 子模块基类
|
||||
* @param <I> 输入类型
|
||||
* @param <O> 输出类型
|
||||
*/
|
||||
public abstract class SubModule<I, O> extends Module {
|
||||
|
||||
public abstract O execute(I data);
|
||||
|
||||
}
|
||||
@@ -4,16 +4,16 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.chat.pojo.MetaMessage;
|
||||
import work.slhaf.partner.api.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.MetaMessage;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
import work.slhaf.partner.core.interaction.data.context.InteractionContext;
|
||||
import work.slhaf.partner.core.session.SessionManager;
|
||||
import work.slhaf.partner.module.common.entity.AppendPromptData;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.CoreModule;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CoreModel extends CoreModule implements ActivateModel {
|
||||
synchronized (CoreModel.class) {
|
||||
if (coreModel == null) {
|
||||
coreModel = new CoreModel();
|
||||
coreModel.model.setChatMessages(coreModel.cognationCapability.getChatMessages());
|
||||
coreModel.getModel().setChatMessages(coreModel.cognationCapability.getChatMessages());
|
||||
coreModel.appendedMessages = new ArrayList<>();
|
||||
coreModel.sessionManager = SessionManager.getInstance();
|
||||
coreModel.updateChatClientSettings();
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemoryResult;
|
||||
import work.slhaf.partner.core.cognation.submodule.cache.CacheCapability;
|
||||
|
||||
@@ -6,14 +6,14 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemoryResult;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemorySliceResult;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.EvaluatedSlice;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.MemorySlice;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
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.EvaluatorResult;
|
||||
@@ -31,7 +31,7 @@ import static work.slhaf.partner.common.util.ExtractUtil.extractJson;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Slf4j
|
||||
public class SliceSelectEvaluator extends SubModule<EvaluatorInput, List<EvaluatedSlice>> implements ActivateModel {
|
||||
public class SliceSelectEvaluator extends AgentInteractionSubModule<EvaluatorInput, List<EvaluatedSlice>> implements ActivateModel {
|
||||
private static volatile SliceSelectEvaluator sliceSelectEvaluator;
|
||||
private InteractionThreadPoolExecutor executor;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.modules.memory.selector.evaluator.data;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.modules.memory.selector.evaluator.data;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.core.cognation.common.pojo.MemoryResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.chat.pojo.MetaMessage;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.MetaMessage;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.common.exception_handler.GlobalExceptionHandler;
|
||||
import work.slhaf.partner.common.exception_handler.pojo.GlobalException;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
@@ -15,9 +17,7 @@ import work.slhaf.partner.core.cognation.submodule.memory.MemoryCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.EvaluatedSlice;
|
||||
import work.slhaf.partner.core.interaction.data.context.InteractionContext;
|
||||
import work.slhaf.partner.core.session.SessionManager;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
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.ExtractorResult;
|
||||
@@ -32,7 +32,7 @@ import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Slf4j
|
||||
public class MemorySelectExtractor extends SubModule<InteractionContext, ExtractorResult> implements ActivateModel {
|
||||
public class MemorySelectExtractor extends AgentInteractionSubModule<InteractionContext, ExtractorResult> implements ActivateModel {
|
||||
|
||||
private static volatile MemorySelectExtractor memorySelectExtractor;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.modules.memory.selector.extractor.data;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.core.cognation.submodule.memory.pojo.EvaluatedSlice;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.cache.CacheCapability;
|
||||
|
||||
@@ -3,8 +3,8 @@ 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.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeInput;
|
||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeResult;
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.HashMap;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Slf4j
|
||||
public class MemorySummarizer extends SubModule<SummarizeInput,SummarizeResult> {
|
||||
public class MemorySummarizer extends AgentInteractionSubModule<SummarizeInput,SummarizeResult> {
|
||||
|
||||
private static volatile MemorySummarizer memorySummarizer;
|
||||
public static final String MODEL_KEY = "memory_summarizer";
|
||||
|
||||
@@ -5,10 +5,10 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeInput;
|
||||
import work.slhaf.partner.module.modules.memory.updater.summarizer.data.SummarizeResult;
|
||||
|
||||
@@ -21,7 +21,7 @@ import static work.slhaf.partner.common.util.ExtractUtil.fixTopicPath;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Slf4j
|
||||
public class MultiSummarizer extends SubModule<SummarizeInput, SummarizeResult> implements ActivateModel {
|
||||
public class MultiSummarizer extends AgentInteractionSubModule<SummarizeInput, SummarizeResult> implements ActivateModel {
|
||||
|
||||
private static volatile MultiSummarizer multiSummarizer;
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Slf4j
|
||||
@Data
|
||||
public class SingleSummarizer extends SubModule<List<Message>,Void> implements ActivateModel {
|
||||
public class SingleSummarizer extends AgentInteractionSubModule<List<Message>,Void> implements ActivateModel {
|
||||
|
||||
private static volatile SingleSummarizer singleSummarizer;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -17,7 +17,7 @@ import static work.slhaf.partner.common.util.ExtractUtil.extractJson;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Slf4j
|
||||
public class TotalSummarizer extends SubModule<HashMap<String, String>, String> implements ActivateModel {
|
||||
public class TotalSummarizer extends AgentInteractionSubModule<HashMap<String, String>, String> implements ActivateModel {
|
||||
|
||||
private static volatile TotalSummarizer totalSummarizer;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.modules.memory.updater.summarizer.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.modules.perceive.selector;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.PerceiveCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.pojo.User;
|
||||
import work.slhaf.partner.core.interaction.data.context.InteractionContext;
|
||||
|
||||
@@ -3,7 +3,7 @@ package work.slhaf.partner.module.modules.perceive.updater;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.PerceiveCapability;
|
||||
|
||||
@@ -3,15 +3,15 @@ package work.slhaf.partner.module.modules.perceive.updater.relation_extractor;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.PerceiveCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.pojo.User;
|
||||
import work.slhaf.partner.core.interaction.data.context.InteractionContext;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractInput;
|
||||
import work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo.RelationExtractResult;
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class RelationExtractor extends SubModule<InteractionContext, RelationExtractResult> implements ActivateModel {
|
||||
public class RelationExtractor extends AgentInteractionSubModule<InteractionContext, RelationExtractResult> implements ActivateModel {
|
||||
|
||||
private static volatile RelationExtractor relationExtractor;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package work.slhaf.partner.module.modules.perceive.updater.relation_extractor.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -4,14 +4,14 @@ import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.api.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.common.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.flow.abstracts.AgentInteractionSubModule;
|
||||
import work.slhaf.partner.core.cognation.cognation.CognationCapability;
|
||||
import work.slhaf.partner.core.cognation.submodule.perceive.PerceiveCapability;
|
||||
import work.slhaf.partner.core.interaction.data.context.InteractionContext;
|
||||
import work.slhaf.partner.module.common.model.ActivateModel;
|
||||
import work.slhaf.partner.module.common.model.ModelConstant;
|
||||
import work.slhaf.partner.module.common.module.SubModule;
|
||||
import work.slhaf.partner.module.modules.perceive.updater.static_extractor.data.StaticMemoryExtractInput;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -19,7 +19,7 @@ import java.util.HashMap;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class StaticMemoryExtractor extends SubModule<InteractionContext, HashMap<String, String>> implements ActivateModel {
|
||||
public class StaticMemoryExtractor extends AgentInteractionSubModule<InteractionContext, HashMap<String, String>> implements ActivateModel {
|
||||
|
||||
private static volatile StaticMemoryExtractor staticMemoryExtractor;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.module.modules.perceive.updater.static_extractor.data
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import work.slhaf.partner.common.chat.pojo.Message;
|
||||
import work.slhaf.partner.api.common.chat.pojo.Message;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user