(feature)(chat)Add switch to enable LLM-based memory review, as it leads to more token costs. #1385

This commit is contained in:
jerryjzhang
2024-07-10 21:08:02 +08:00
parent 78a91ad8c2
commit 9bb95ca4be
7 changed files with 19 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ public class Agent extends RecordInfo {
private Integer id;
private Integer enableSearch;
private Integer enableMemoryReview;
private String name;
private String description;
@@ -60,6 +61,10 @@ public class Agent extends RecordInfo {
return enableSearch != null && enableSearch == 1;
}
public boolean enableMemoryReview() {
return enableMemoryReview != null && enableMemoryReview == 1;
}
public static boolean containsAllModel(Set<Long> detectViewIds) {
return !CollectionUtils.isEmpty(detectViewIds) && detectViewIds.contains(-1L);
}

View File

@@ -32,7 +32,7 @@ public class MemoryReviewTask {
+ "please take a review and give your opinion.\n"
+ "#Rules: "
+ "1.ALWAYS follow the output format: `opinion=(POSITIVE|NEGATIVE),comment=(your comment)`."
+ "2.DO NOT check the usage of `数据日期` field and `datediff()` function.\n"
+ "2.ALWAYS recognize `数据日期` as the date field.\n"
+ "#Question: %s\n"
+ "#Schema: %s\n"
+ "#SQL: %s\n"
@@ -51,7 +51,7 @@ public class MemoryReviewTask {
memoryService.getMemoriesForLlmReview().stream()
.forEach(m -> {
Agent chatAgent = agentService.getAgent(m.getAgentId());
if (Objects.nonNull(chatAgent)) {
if (Objects.nonNull(chatAgent) && chatAgent.enableMemoryReview()) {
String promptStr = String.format(INSTRUCTION, m.getQuestion(), m.getDbSchema(), m.getS2sql());
Prompt prompt = PromptTemplate.from(promptStr).apply(Collections.EMPTY_MAP);
@@ -72,7 +72,7 @@ public class MemoryReviewTask {
log.debug("ChatLanguageModel not found for agent:{}", chatAgent.getId());
}
} else {
log.debug("Agent not found for memory:{}", m.getAgentId());
log.debug("Agent id {} not found or memory review disabled", m.getAgentId());
}
});
}

View File

@@ -65,6 +65,7 @@ public class AgentDO {
*
*/
private Integer enableSearch;
private Integer enableMemoryReview;
private String modelConfig;
private String multiTurnConfig;