Commit 802b8915 authored by alex yao's avatar alex yao

feat(dbChain): 新增上下文内容

parent fe27629d
...@@ -1133,6 +1133,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -1133,6 +1133,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
return null; return null;
} }
String query = getMessageQuestion(messages); String query = getMessageQuestion(messages);
String context = getContext(messages);
List<DBChainResult> results = new ArrayList<>(); List<DBChainResult> results = new ArrayList<>();
for (Integer databaseId : databaseIds) { for (Integer databaseId : databaseIds) {
BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(databaseId.longValue()); BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(databaseId.longValue());
...@@ -1141,6 +1142,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -1141,6 +1142,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
} }
DBChainResponse dbChainResponse = new DBChainResponse(); DBChainResponse dbChainResponse = new DBChainResponse();
dbChainResponse.setQuestion(query); dbChainResponse.setQuestion(query);
dbChainResponse.setContext(context);
dbChainResponse.setPrompt(null); dbChainResponse.setPrompt(null);
dbChainResponse.setTableFilters(null); dbChainResponse.setTableFilters(null);
dbChainResponse.setMysqlUser(bizKnowledgeDatabaseEntity.getDbUsername()); dbChainResponse.setMysqlUser(bizKnowledgeDatabaseEntity.getDbUsername());
...@@ -1168,6 +1170,20 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -1168,6 +1170,20 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
return query; return query;
} }
private String getContext(List<Message> messages) {
StringBuilder context = new StringBuilder();
if (messages.size() >= 6) {
for (int i = 6; i > 0; i--) {
Message message = messages.get(messages.size() - i);
context.append(message.getRole()).append(":").append(message.getContent()).append(StringUtils.LF);
}
} else {
for (Message message : messages) {
context.append(message.getRole()).append(":").append(message.getContent()).append(StringUtils.LF);
}
}
return context.toString();
}
/** /**
* 更新【记忆变量】结构 * 更新【记忆变量】结构
......
...@@ -15,6 +15,8 @@ public class DBChainResponse extends AbstractRequest<DBChainResult> implements S ...@@ -15,6 +15,8 @@ public class DBChainResponse extends AbstractRequest<DBChainResult> implements S
private String prompt; private String prompt;
private String context;
private List<String> tableFilters; private List<String> tableFilters;
private String mysqlUser; private String mysqlUser;
...@@ -29,6 +31,13 @@ public class DBChainResponse extends AbstractRequest<DBChainResult> implements S ...@@ -29,6 +31,13 @@ public class DBChainResponse extends AbstractRequest<DBChainResult> implements S
private String apiKey; private String apiKey;
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getQuestion() { public String getQuestion() {
return question; return question;
......
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