mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
调整了 ActionInterventor 中数据构建方法的组织方式
This commit is contained in:
@@ -55,6 +55,9 @@ public class ActionInterventor extends PreRunningModule implements ActivateModel
|
||||
@InjectCapability
|
||||
private MemoryCapability memoryCapability;
|
||||
|
||||
private final AssemblyHelper assemblyHelper = new AssemblyHelper();
|
||||
private final PromptHelper promptHelper = new PromptHelper();
|
||||
|
||||
/**
|
||||
* 键: 本次调用uuid;
|
||||
* 值:本次调用对应的prompt;
|
||||
@@ -71,15 +74,15 @@ public class ActionInterventor extends PreRunningModule implements ActivateModel
|
||||
String uuid = context.getUuid();
|
||||
String userId = context.getUserId();
|
||||
RecognizerResult recognizerResult = interventionRecognizer
|
||||
.execute(buildRecognizerInput(userId, context.getInput())); // 此处的输入内容携带了所有 PhaserRecord
|
||||
.execute(assemblyHelper.buildRecognizerInput(userId, context.getInput())); // 此处的输入内容携带了所有 PhaserRecord
|
||||
if (!recognizerResult.isOk()) {
|
||||
setupNoInterventionPrompt(uuid);
|
||||
promptHelper.setupNoInterventionPrompt(uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
// 干预意图评估
|
||||
EvaluatorResult evaluatorResult = interventionEvaluator
|
||||
.execute(buildEvaluatorInput(recognizerResult, userId));
|
||||
.execute(assemblyHelper.buildEvaluatorInput(recognizerResult, userId));
|
||||
List<EvaluatedInterventionData> executingDataList = evaluatorResult.getExecutingDataList();
|
||||
List<EvaluatedInterventionData> preparedDataList = evaluatorResult.getPreparedDataList();
|
||||
|
||||
@@ -90,10 +93,10 @@ public class ActionInterventor extends PreRunningModule implements ActivateModel
|
||||
invalidActionKeysFilter(preparedDataList);
|
||||
|
||||
// 同步写入prompt,异步处理干预行为,‘异步’在 interventionHandler 中体现
|
||||
setupInterventionPrompt(uuid, executingDataList, preparedDataList);
|
||||
interventionHandler.execute(buildHandlerInput(executingDataList, preparedDataList, recognizerResult));
|
||||
promptHelper.setupInterventionPrompt(uuid, executingDataList, preparedDataList);
|
||||
interventionHandler.execute(assemblyHelper.buildHandlerInput(executingDataList, preparedDataList, recognizerResult));
|
||||
} else {
|
||||
setupInterventionIgnoredPrompt(uuid, executingDataList, preparedDataList);
|
||||
promptHelper.setupInterventionIgnoredPrompt(uuid, executingDataList, preparedDataList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,6 +139,30 @@ public class ActionInterventor extends PreRunningModule implements ActivateModel
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelKey() {
|
||||
return "action_identifier";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withBasicPrompt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getPromptDataMap(PartnerRunningFlowContext context) {
|
||||
return interventionPrompt.remove(context.getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String moduleName() {
|
||||
return "[行动干预识别模块]";
|
||||
}
|
||||
|
||||
private final class AssemblyHelper {
|
||||
private AssemblyHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param executingDataList 对应评估结果中的‘执行中行动’
|
||||
* @param preparedDataList 对应评估结果中的‘待执行行动’
|
||||
@@ -193,6 +220,32 @@ public class ActionInterventor extends PreRunningModule implements ActivateModel
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private RecognizerInput buildRecognizerInput(String userId, String input) {
|
||||
RecognizerInput recognizerInput = new RecognizerInput();
|
||||
recognizerInput.setInput(input);
|
||||
recognizerInput.setUserDialogMapStr(memoryCapability.getUserDialogMapStr(userId));
|
||||
// 参考的对话列表大小或需调整
|
||||
recognizerInput.setRecentMessages(cognationCapability.getChatMessages());
|
||||
recognizerInput.setExecutingActions(actionCapability.listPhaserRecords());
|
||||
recognizerInput.setPreparedActions(actionCapability.listPreparedAction(userId));
|
||||
return recognizerInput;
|
||||
}
|
||||
|
||||
private EvaluatorInput buildEvaluatorInput(RecognizerResult recognizerResult, String userId) {
|
||||
EvaluatorInput input = new EvaluatorInput();
|
||||
input.setExecutingInterventions(recognizerResult.getExecutingInterventions());
|
||||
input.setPreparedInterventions(recognizerResult.getPreparedInterventions());
|
||||
input.setRecentMessages(cognationCapability.getChatMessages());
|
||||
input.setActivatedSlices(memoryCapability.getActivatedSlices(userId));
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
private final class PromptHelper {
|
||||
private PromptHelper() {
|
||||
}
|
||||
|
||||
private void setupInterventionIgnoredPrompt(String uuid, List<EvaluatedInterventionData> executingDataList, List<EvaluatedInterventionData> preparedDataList) {
|
||||
List<EvaluatedInterventionData> total = Stream.concat(executingDataList.stream(), preparedDataList.stream()).toList();
|
||||
|
||||
@@ -246,44 +299,5 @@ public class ActionInterventor extends PreRunningModule implements ActivateModel
|
||||
"[识别状态] <是否识别到干预已存在行动的意图>", "未识别到干预意图",
|
||||
"[干预行动] <将对已存在行动做出的行为>", "无行动"));
|
||||
}
|
||||
|
||||
private EvaluatorInput buildEvaluatorInput(RecognizerResult recognizerResult, String userId) {
|
||||
EvaluatorInput input = new EvaluatorInput();
|
||||
input.setExecutingInterventions(recognizerResult.getExecutingInterventions());
|
||||
input.setPreparedInterventions(recognizerResult.getPreparedInterventions());
|
||||
input.setRecentMessages(cognationCapability.getChatMessages());
|
||||
input.setActivatedSlices(memoryCapability.getActivatedSlices(userId));
|
||||
return input;
|
||||
}
|
||||
|
||||
private RecognizerInput buildRecognizerInput(String userId, String input) {
|
||||
RecognizerInput recognizerInput = new RecognizerInput();
|
||||
recognizerInput.setInput(input);
|
||||
recognizerInput.setUserDialogMapStr(memoryCapability.getUserDialogMapStr(userId));
|
||||
// 参考的对话列表大小或需调整
|
||||
recognizerInput.setRecentMessages(cognationCapability.getChatMessages());
|
||||
recognizerInput.setExecutingActions(actionCapability.listPhaserRecords());
|
||||
recognizerInput.setPreparedActions(actionCapability.listPreparedAction(userId));
|
||||
return recognizerInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelKey() {
|
||||
return "action_identifier";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withBasicPrompt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getPromptDataMap(PartnerRunningFlowContext context) {
|
||||
return interventionPrompt.remove(context.getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String moduleName() {
|
||||
return "[行动干预识别模块]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package work.slhaf.partner.module.modules.action.planner;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.Init;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.InjectModule;
|
||||
import work.slhaf.partner.api.chat.pojo.Message;
|
||||
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
|
||||
import work.slhaf.partner.common.vector.VectorClient;
|
||||
import work.slhaf.partner.core.action.ActionCapability;
|
||||
import work.slhaf.partner.core.action.ActionCore;
|
||||
import work.slhaf.partner.core.action.entity.ActionData;
|
||||
import work.slhaf.partner.core.action.entity.ImmediateActionData;
|
||||
import work.slhaf.partner.core.action.entity.MetaAction;
|
||||
@@ -32,10 +33,12 @@ import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowCon
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* 负责针对本次输入生成基础的行动计划,在主模型传达意愿后,执行行动或者放入计划池
|
||||
*/
|
||||
@Slf4j
|
||||
@AgentModule(name = "action_planner", order = 2)
|
||||
public class ActionPlanner extends PreRunningModule {
|
||||
|
||||
@@ -55,21 +58,25 @@ public class ActionPlanner extends PreRunningModule {
|
||||
@InjectModule
|
||||
private ActionConfirmer actionConfirmer;
|
||||
|
||||
private InteractionThreadPoolExecutor executor;
|
||||
private ActionAssemblyHelper assemblyHelper;
|
||||
private ExecutorService executor;
|
||||
|
||||
private final ActionAssemblyHelper assemblyHelper = new ActionAssemblyHelper();
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
executor = InteractionThreadPoolExecutor.getInstance();
|
||||
assemblyHelper = new ActionAssemblyHelper();
|
||||
executor = actionCapability.getExecutor(ActionCore.ExecutorType.VIRTUAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(PartnerRunningFlowContext context) {
|
||||
try {
|
||||
List<Callable<Void>> tasks = new ArrayList<>();
|
||||
addConfirmTask(tasks, context);
|
||||
addNewActionTask(tasks, context);
|
||||
executor.invokeAll(tasks);
|
||||
} catch (Exception e) {
|
||||
log.error("执行异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +207,7 @@ public class ActionPlanner extends PreRunningModule {
|
||||
return "[行动模块]";
|
||||
}
|
||||
|
||||
private class ActionAssemblyHelper {
|
||||
private final class ActionAssemblyHelper {
|
||||
private ActionAssemblyHelper() {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user