Commit 7876e3fa authored by alex yao's avatar alex yao

fix: 初始化 valueMemory 函数

parent ef6af236
...@@ -422,7 +422,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -422,7 +422,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
if (MapUtils.isNotEmpty(map)) { if (MapUtils.isNotEmpty(map)) {
Set<Object> keySet = map.keySet(); Set<Object> keySet = map.keySet();
for (Object key : keySet) { for (Object key : keySet) {
stringBuilder.append(key.toString()).append(":").append(map.get(key).toString()).append(StringUtils.LF); stringBuilder.append(key.toString()).append(":").append(map.get(key)).append(StringUtils.LF);
} }
} }
promptTemplate = promptTemplate.replace("${valueMemoryResult}", stringBuilder.toString()); promptTemplate = promptTemplate.replace("${valueMemoryResult}", stringBuilder.toString());
......
package cn.com.poc.agent_application.dto;
public class AgentApplicationValueMemoryDto {
private String key;
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
...@@ -94,6 +94,11 @@ public interface AgentApplicationInfoRest extends BaseRest { ...@@ -94,6 +94,11 @@ public interface AgentApplicationInfoRest extends BaseRest {
* */ * */
void collectOrCancelAgentInPerson(@RequestParam String agentId) throws Exception; void collectOrCancelAgentInPerson(@RequestParam String agentId) throws Exception;
/**
* 获取【变量】列表
*/
List<AgentApplicationValueMemoryDto> getVariableList(@RequestParam String agentId) throws Exception;
/** /**
* 获取应用的记忆片段 * 获取应用的记忆片段
* *
......
...@@ -223,7 +223,8 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -223,7 +223,8 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
String key = variable.getKey(); String key = variable.getKey();
String variableDefault = variable.getVariableDefault(); String variableDefault = variable.getVariableDefault();
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put(key, variableDefault); jsonObject.put("contentName", key);
jsonObject.put("contentValue", variableDefault);
LargeModelFunctionEnum.valueOf(functionName).getFunction().doFunction(jsonObject.toJSONString(), agentId); LargeModelFunctionEnum.valueOf(functionName).getFunction().doFunction(jsonObject.toJSONString(), agentId);
} }
} }
...@@ -331,6 +332,31 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -331,6 +332,31 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
agentApplicationInfoService.collectOrCancelAgentInPerson(agentId); agentApplicationInfoService.collectOrCancelAgentInPerson(agentId);
} }
@Override
public List<AgentApplicationValueMemoryDto> getVariableList(String agentId) {
Map<Object, Object> map = GetValueMemory.get(agentId);
List<AgentApplicationValueMemoryDto> result = new ArrayList<>();
if (MapUtils.isEmpty(map)) {
BizAgentApplicationInfoEntity infoEntity = bizAgentApplicationInfoService.getByAgentId(agentId);
List<Variable> variableStructure = infoEntity.getVariableStructure();
for (Variable variable : variableStructure) {
AgentApplicationValueMemoryDto valueMemoryDto = new AgentApplicationValueMemoryDto();
valueMemoryDto.setKey(variable.getKey());
valueMemoryDto.setValue(variable.getVariableDefault());
result.add(valueMemoryDto);
}
} else {
Set<Object> keySet = map.keySet();
for (Object key : keySet) {
AgentApplicationValueMemoryDto valueMemoryDto = new AgentApplicationValueMemoryDto();
valueMemoryDto.setKey(key.toString());
valueMemoryDto.setValue(map.get(key).toString());
result.add(valueMemoryDto);
}
}
return result;
}
@Override @Override
public List<AgentLongMemoryDto> getLongMemoryList(String agentId) throws Exception { public List<AgentLongMemoryDto> getLongMemoryList(String agentId) throws Exception {
Assert.notNull(agentId); Assert.notNull(agentId);
......
...@@ -324,7 +324,8 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -324,7 +324,8 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
String key = variable.getKey(); String key = variable.getKey();
String variableDefault = variable.getVariableDefault(); String variableDefault = variable.getVariableDefault();
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put(key, variableDefault); jsonObject.put("contentName", key);
jsonObject.put("contentValue", variableDefault);
LargeModelFunctionEnum.valueOf(functionName).getFunction().doFunction(jsonObject.toJSONString(), identifier); LargeModelFunctionEnum.valueOf(functionName).getFunction().doFunction(jsonObject.toJSONString(), identifier);
} }
} }
......
...@@ -3,6 +3,7 @@ package cn.com.poc.thirdparty.resource.demand.ai.function.value_memory; ...@@ -3,6 +3,7 @@ package cn.com.poc.thirdparty.resource.demand.ai.function.value_memory;
import cn.com.poc.agent_application.entity.Variable; import cn.com.poc.agent_application.entity.Variable;
import cn.com.poc.common.service.RedisService; import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunction; import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunction;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
...@@ -65,7 +66,11 @@ public class SetValueMemoryFunction extends AbstractLargeModelFunction { ...@@ -65,7 +66,11 @@ public class SetValueMemoryFunction extends AbstractLargeModelFunction {
Map<String, Object> contentName = new HashMap<>(); Map<String, Object> contentName = new HashMap<>();
contentName.put("type", "string"); contentName.put("type", "string");
contentName.put("description", "内容名"); contentName.put("description", "内容名");
contentName.put("enum", variableStructure); // 设置变量 List<String> enumList = new ArrayList<>();
for (Variable variable : variableStructure) {
enumList.add(variable.getKey());
}
contentName.put("enum", JsonUtils.serialize(enumList)); // 设置变量
Map<String, Object> contentValue = new HashMap<>(); Map<String, Object> contentValue = new HashMap<>();
contentValue.put("type", "string"); contentValue.put("type", "string");
contentValue.put("description", "内容值"); contentValue.put("description", "内容值");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment