mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
推进 ActionExtractor: 完善大致逻辑,开始语义-行为缓存相关部分
This commit is contained in:
@@ -28,6 +28,12 @@
|
||||
<version>1.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
|
||||
<dependency>
|
||||
<groupId>org.nd4j</groupId>
|
||||
<artifactId>nd4j-api</artifactId>
|
||||
<version>1.0.0-M2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
@@ -49,7 +55,8 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>work.slhaf.partner.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
|
||||
@@ -18,4 +18,6 @@ public interface ActionCapability {
|
||||
List<MetaActionInfo> listPendingAction(String userId);
|
||||
|
||||
void putPendingActions(String userId, MetaActionInfo metaActionInfo);
|
||||
|
||||
List<String> computeActionCache(String input);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.Setter;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.Capability;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityMethod;
|
||||
import work.slhaf.partner.core.PartnerCore;
|
||||
import work.slhaf.partner.core.action.entity.ActionCacheData;
|
||||
import work.slhaf.partner.core.action.entity.MetaActionInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -27,6 +28,11 @@ public class ActionCore extends PartnerCore<ActionCore> {
|
||||
*/
|
||||
private HashMap<String, List<MetaActionInfo>> pendingActions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 语义缓存与行为倾向映射
|
||||
*/
|
||||
private List<ActionCacheData> actionCache = new ArrayList<>();
|
||||
|
||||
//TODO 添加语义缓存,可借由简单向量模型,设想以向量结果为键、行动倾向为值
|
||||
public ActionCore() throws IOException, ClassNotFoundException {
|
||||
}
|
||||
@@ -73,6 +79,14 @@ public class ActionCore extends PartnerCore<ActionCore> {
|
||||
return pendingActions.get(userId);
|
||||
}
|
||||
|
||||
@CapabilityMethod
|
||||
public List<String> computeActionCache(String input){
|
||||
//计算本次输入的向量
|
||||
|
||||
//与现有缓存比对,如果存在,则使缓存计数+1
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCoreKey() {
|
||||
return "action-core";
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package work.slhaf.partner.core.action.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActionCacheData {
|
||||
private INDArray inputArray;
|
||||
private INDArray tendencyArray;
|
||||
private String tendency;
|
||||
private int count;
|
||||
private List<String> activateInputs = new ArrayList<>();
|
||||
private boolean activated;
|
||||
}
|
||||
@@ -1,19 +1,48 @@
|
||||
package work.slhaf.partner.module.modules.action.planner.extractor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.AgentRunningSubModule;
|
||||
import work.slhaf.partner.api.chat.constant.ChatConstant;
|
||||
import work.slhaf.partner.api.chat.pojo.ChatResponse;
|
||||
import work.slhaf.partner.api.chat.pojo.Message;
|
||||
import work.slhaf.partner.core.action.ActionCapability;
|
||||
import work.slhaf.partner.module.modules.action.planner.extractor.entity.ExtractorInput;
|
||||
import work.slhaf.partner.module.modules.action.planner.extractor.entity.ExtractorResult;
|
||||
|
||||
@Slf4j
|
||||
@AgentSubModule
|
||||
public class ActionExtractor extends AgentRunningSubModule<ExtractorInput, ExtractorResult> implements ActivateModel {
|
||||
|
||||
@InjectCapability
|
||||
private ActionCapability actionCapability;
|
||||
|
||||
@Override
|
||||
public ExtractorResult execute(ExtractorInput data) {
|
||||
//TODO 添加语义缓存判断
|
||||
// TODO 添加语义缓存判断
|
||||
List<String> tendencyCache = actionCapability.computeActionCache(data.getInput());
|
||||
if ( tendencyCache == null || !tendencyCache.isEmpty()) {
|
||||
ExtractorResult result = new ExtractorResult();
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
this.chatMessages().add(new Message(ChatConstant.Character.USER, JSONObject.toJSONString(data)));
|
||||
ChatResponse response = this.chat();
|
||||
return JSONObject.parseObject(response.getMessage(), ExtractorResult.class);
|
||||
} catch (Exception e) {
|
||||
log.error("[ActionExtractor] 提取信息出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
return new ExtractorResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,9 +2,10 @@ package work.slhaf.partner.module.modules.action.planner.extractor.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ExtractorResult {
|
||||
private List<String> tendencies;
|
||||
private List<String> tendencies = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
@AgentModule(name = "perceive_updater", order = 7)
|
||||
public class PerceiveUpdater extends PostRunningModule {
|
||||
|
||||
private static volatile PerceiveUpdater perceiveUpdater;
|
||||
|
||||
@InjectCapability
|
||||
private PerceiveCapability perceiveCapability;
|
||||
@InjectCapability
|
||||
|
||||
@@ -21,8 +21,6 @@ import java.util.HashMap;
|
||||
@AgentSubModule
|
||||
public class StaticMemoryExtractor extends AgentRunningSubModule<PartnerRunningFlowContext, HashMap<String, String>> implements ActivateModel {
|
||||
|
||||
private static volatile StaticMemoryExtractor staticMemoryExtractor;
|
||||
|
||||
@InjectCapability
|
||||
private CognationCapability cognationCapability;
|
||||
@InjectCapability
|
||||
|
||||
@@ -22,8 +22,6 @@ import java.util.HashMap;
|
||||
@AgentModule(name = "preprocess_executor", order = 1)
|
||||
public class PreprocessExecutor extends PreRunningModule {
|
||||
|
||||
private static volatile PreprocessExecutor preprocessExecutor;
|
||||
|
||||
@InjectCapability
|
||||
private CognationCapability cognationCapability;
|
||||
@InjectCapability
|
||||
|
||||
Reference in New Issue
Block a user