Commit cbfef1d5 authored by alex yao's avatar alex yao

Merge branch 'release' into task/1004390

# Conflicts:
#	src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
#	src/main/java/cn/com/poc/agent_application/entity/BizAgentApplicationPublishEntity.java
parents a3dcd50a 05a09c72
...@@ -107,12 +107,6 @@ ...@@ -107,12 +107,6 @@
<version>8.0.28</version> <version>8.0.28</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- ES --> <!-- ES -->
<dependency> <dependency>
<groupId>org.elasticsearch.client</groupId> <groupId>org.elasticsearch.client</groupId>
...@@ -245,11 +239,14 @@ ...@@ -245,11 +239,14 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<version>4.1.2</version> <version>4.1.2</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId> <artifactId>poi-ooxml-schemas</artifactId>
...@@ -260,6 +257,13 @@ ...@@ -260,6 +257,13 @@
<artifactId>ooxml-schemas</artifactId> <artifactId>ooxml-schemas</artifactId>
<version>1.1</version> <version>1.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.1.2</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
...@@ -277,11 +281,6 @@ ...@@ -277,11 +281,6 @@
<version>3.6.0</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-http --> <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-http -->
<dependency> <dependency>
......
...@@ -19,7 +19,7 @@ public interface AgentApplicationInfoService { ...@@ -19,7 +19,7 @@ public interface AgentApplicationInfoService {
* 应用预览 * 应用预览
*/ */
String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem, String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem,
Integer[] knowledgeIds, Integer communicationTurn, Float topP, Integer[] knowledgeIds, Integer communicationTurn, Float topP, Float temperature,
List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception; List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception;
/** /**
......
...@@ -103,7 +103,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -103,7 +103,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
@Override @Override
public String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem, Integer[] kdIds, Integer communicationTurn, Float topP, List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception { public String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem, Integer[] kdIds, Integer communicationTurn, Float topP, Float temperature, List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception {
logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" + " communicationTurn:{},topP:{},messages:{}--------------", largeModel, unitIds, agentSystem, kdIds, communicationTurn, topP, messages); logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" + " communicationTurn:{},topP:{},messages:{}--------------", largeModel, unitIds, agentSystem, kdIds, communicationTurn, topP, messages);
String model = modelConvert(largeModel); String model = modelConvert(largeModel);
...@@ -324,6 +324,13 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -324,6 +324,13 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return JsonUtils.deSerialize(res.substring(start, end + 1), CreateAgentTitleAndDescEntity.class); return JsonUtils.deSerialize(res.substring(start, end + 1), CreateAgentTitleAndDescEntity.class);
} }
@Override
public boolean unPublish(String agentId) throws Exception {
bizAgentApplicationPublishService.deleteByAgentId(agentId);
bizAgentApplicationInfoService.unPublish(agentId);
return true;
}
/** /**
* 构建应用信息提示词 * 构建应用信息提示词
* *
...@@ -373,7 +380,14 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -373,7 +380,14 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
knowledgeIds.add(knowledgeDocumentEntity.getKnowledgeId()); knowledgeIds.add(knowledgeDocumentEntity.getKnowledgeId());
} }
List<String> knowledgeResults = demandKnowledgeService.searchKnowledge(messages.get(messages.size() - 1).getContent().get(0).getText(), knowledgeIds, 3); Object content = messages.get(messages.size() - 1).getContent();
String query = "";
if (content instanceof List) {
query = ((List<MultiContent>) content).get(0).getText();
} else {
query = content.toString();
}
List<String> knowledgeResults = demandKnowledgeService.searchKnowledge(query, knowledgeIds, 3);
promptTemplate = promptTemplate.replace("${knowledgeResults}", knowledgeResults.toString()); promptTemplate = promptTemplate.replace("${knowledgeResults}", knowledgeResults.toString());
} }
// 记忆 // 记忆
...@@ -585,7 +599,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -585,7 +599,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param promptTemplate * @param promptTemplate
* @return * @return
*/ */
private static Message[] buildMessages(List<Message> messages, Integer communicationTurn, String promptTemplate) { private Message[] buildMessages(List<Message> messages, Integer communicationTurn, String promptTemplate) {
int messLength = messages.size() - 1; int messLength = messages.size() - 1;
int skip = communicationTurn * 2; int skip = communicationTurn * 2;
if (skip < messLength) { if (skip < messLength) {
...@@ -593,17 +607,24 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -593,17 +607,24 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
if (StringUtils.isNotBlank(promptTemplate)) { if (StringUtils.isNotBlank(promptTemplate)) {
List<MultiContent> content = new ArrayList<>();
MultiContent multiContent = new MultiContent();
multiContent.setText(promptTemplate);
multiContent.setType("text");
content.add(multiContent);
Message systemMessage = new Message(); Message systemMessage = new Message();
systemMessage.setRole(AgentApplicationDialoguesRecordConstants.ROLE.SYSTEM); systemMessage.setRole(AgentApplicationDialoguesRecordConstants.ROLE.SYSTEM);
systemMessage.setContent(content); systemMessage.setContent(promptTemplate);
messages.add(0, systemMessage); messages.add(0, systemMessage);
} }
return messages.toArray(new Message[0]); // 转换消息体
Message[] messageArray = new Message[messages.size()];
int index = 0;
for (Message message : messages) {
if (message.getContent() instanceof List) {
List<HashMap<String,Object>> content = (List<HashMap<String,Object>>) message.getContent();
if (content.get(0).get("type").equals("text")) {
message.setContent(content.get(0).get("text").toString());
}
}
messageArray[index++] = message;
}
return messageArray;
} }
......
...@@ -58,6 +58,7 @@ public class AgentApplicationInfoConvert { ...@@ -58,6 +58,7 @@ public class AgentApplicationInfoConvert {
} }
entity.setLargeModel(model.getLargeModel()); entity.setLargeModel(model.getLargeModel());
entity.setTopP(model.getTopP()); entity.setTopP(model.getTopP());
entity.setTemperature(model.getTemperature());
if (StringUtils.isNotBlank(model.getUnitIds())) { if (StringUtils.isNotBlank(model.getUnitIds())) {
entity.setUnitIds(JsonUtils.deSerialize(model.getUnitIds(), String[].class)); entity.setUnitIds(JsonUtils.deSerialize(model.getUnitIds(), String[].class));
} }
...@@ -98,6 +99,7 @@ public class AgentApplicationInfoConvert { ...@@ -98,6 +99,7 @@ public class AgentApplicationInfoConvert {
} }
model.setLargeModel(entity.getLargeModel()); model.setLargeModel(entity.getLargeModel());
model.setTopP(entity.getTopP()); model.setTopP(entity.getTopP());
model.setTemperature(entity.getTemperature());
if (ArrayUtils.isNotEmpty(entity.getUnitIds())) { if (ArrayUtils.isNotEmpty(entity.getUnitIds())) {
model.setUnitIds(JsonUtil.toJson(entity.getUnitIds())); model.setUnitIds(JsonUtil.toJson(entity.getUnitIds()));
} }
...@@ -137,6 +139,7 @@ public class AgentApplicationInfoConvert { ...@@ -137,6 +139,7 @@ public class AgentApplicationInfoConvert {
AgentApplicationCommModelConfig commModelConfig = new AgentApplicationCommModelConfig(); AgentApplicationCommModelConfig commModelConfig = new AgentApplicationCommModelConfig();
commModelConfig.setLargeModel(entity.getLargeModel()); commModelConfig.setLargeModel(entity.getLargeModel());
commModelConfig.setTopP(entity.getTopP()); commModelConfig.setTopP(entity.getTopP());
commModelConfig.setTemperature(entity.getTemperature());
commModelConfig.setCommunicationTurn(entity.getCommunicationTurn()); commModelConfig.setCommunicationTurn(entity.getCommunicationTurn());
AgentApplicationInfoDto dto = new AgentApplicationInfoDto(); AgentApplicationInfoDto dto = new AgentApplicationInfoDto();
...@@ -184,6 +187,7 @@ public class AgentApplicationInfoConvert { ...@@ -184,6 +187,7 @@ public class AgentApplicationInfoConvert {
if (ObjectUtil.isNotEmpty(dto.getCommModelConfig())) { if (ObjectUtil.isNotEmpty(dto.getCommModelConfig())) {
entity.setLargeModel(dto.getCommModelConfig().getLargeModel()); entity.setLargeModel(dto.getCommModelConfig().getLargeModel());
entity.setTopP(dto.getCommModelConfig().getTopP()); entity.setTopP(dto.getCommModelConfig().getTopP());
entity.setTemperature(dto.getCommModelConfig().getTemperature());
entity.setCommunicationTurn(dto.getCommModelConfig().getCommunicationTurn()); entity.setCommunicationTurn(dto.getCommModelConfig().getCommunicationTurn());
} }
...@@ -225,6 +229,7 @@ public class AgentApplicationInfoConvert { ...@@ -225,6 +229,7 @@ public class AgentApplicationInfoConvert {
} }
entity.setLargeModel(infoQueryItem.getLargeModel()); entity.setLargeModel(infoQueryItem.getLargeModel());
entity.setTopP(infoQueryItem.getTopP()); entity.setTopP(infoQueryItem.getTopP());
entity.setTemperature(infoQueryItem.getTemperature());
if (StringUtils.isNotBlank(infoQueryItem.getUnitIds())) { if (StringUtils.isNotBlank(infoQueryItem.getUnitIds())) {
entity.setUnitIds(JsonUtils.deSerialize(infoQueryItem.getUnitIds(), String[].class)); entity.setUnitIds(JsonUtils.deSerialize(infoQueryItem.getUnitIds(), String[].class));
} }
......
...@@ -46,6 +46,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -46,6 +46,7 @@ public class BizAgentApplicationPublishConvert {
} }
entity.setLargeModel(model.getLargeModel()); entity.setLargeModel(model.getLargeModel());
entity.setTopP(model.getTopP()); entity.setTopP(model.getTopP());
entity.setTemperature(model.getTemperature());
if (StringUtils.isNotBlank(model.getUnitIds())) { if (StringUtils.isNotBlank(model.getUnitIds())) {
entity.setUnitIds(JsonUtils.deSerialize(model.getUnitIds(), String[].class)); entity.setUnitIds(JsonUtils.deSerialize(model.getUnitIds(), String[].class));
} }
...@@ -84,6 +85,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -84,6 +85,7 @@ public class BizAgentApplicationPublishConvert {
} }
model.setLargeModel(entity.getLargeModel()); model.setLargeModel(entity.getLargeModel());
model.setTopP(entity.getTopP()); model.setTopP(entity.getTopP());
model.setTemperature(entity.getTemperature());
if (ArrayUtils.isNotEmpty(entity.getUnitIds())) { if (ArrayUtils.isNotEmpty(entity.getUnitIds())) {
model.setUnitIds(JsonUtil.toJson(entity.getUnitIds())); model.setUnitIds(JsonUtil.toJson(entity.getUnitIds()));
} }
...@@ -123,6 +125,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -123,6 +125,7 @@ public class BizAgentApplicationPublishConvert {
AgentApplicationCommModelConfig commModelConfig = new AgentApplicationCommModelConfig(); AgentApplicationCommModelConfig commModelConfig = new AgentApplicationCommModelConfig();
commModelConfig.setLargeModel(entity.getLargeModel()); commModelConfig.setLargeModel(entity.getLargeModel());
commModelConfig.setTopP(entity.getTopP()); commModelConfig.setTopP(entity.getTopP());
commModelConfig.setTemperature(entity.getTemperature());
commModelConfig.setCommunicationTurn(entity.getCommunicationTurn()); commModelConfig.setCommunicationTurn(entity.getCommunicationTurn());
dto.setBaseInfo(baseInfo); dto.setBaseInfo(baseInfo);
...@@ -170,6 +173,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -170,6 +173,7 @@ public class BizAgentApplicationPublishConvert {
if (ObjectUtil.isNotEmpty(dto.getCommModelConfig())) { if (ObjectUtil.isNotEmpty(dto.getCommModelConfig())) {
entity.setLargeModel(dto.getCommModelConfig().getLargeModel()); entity.setLargeModel(dto.getCommModelConfig().getLargeModel());
entity.setTopP(dto.getCommModelConfig().getTopP()); entity.setTopP(dto.getCommModelConfig().getTopP());
entity.setTemperature(dto.getCommModelConfig().getTemperature());
} }
entity.setUnitIds(dto.getUnitIds()); entity.setUnitIds(dto.getUnitIds());
......
...@@ -33,6 +33,20 @@ public class AgentApplicationCommModelConfig { ...@@ -33,6 +33,20 @@ public class AgentApplicationCommModelConfig {
this.topP = topP; this.topP = topP;
} }
/**
* temperature
* 对话模型温度配置 (0-1.0]
*/
private Float temperature;
public Float getTemperature() {
return temperature;
}
public void setTemperature(Float temperature) {
this.temperature = temperature;
}
/** /**
* communication_turn * communication_turn
* 对话上下文保存轮次 * 对话上下文保存轮次
......
...@@ -7,11 +7,50 @@ import java.util.List; ...@@ -7,11 +7,50 @@ import java.util.List;
public class AgentApplicationPreviewDto implements Serializable { public class AgentApplicationPreviewDto implements Serializable {
private String modelNickName;
private Float topP;
private Float temperature;
private String agentSystem;
private String agentId; private String agentId;
private List<Message> messages; private List<Message> messages;
public Float getTopP() {
return topP;
}
public void setTopP(Float topP) {
this.topP = topP;
}
public Float getTemperature() {
return temperature;
}
public void setTemperature(Float temperature) {
this.temperature = temperature;
}
public String getAgentSystem() {
return agentSystem;
}
public void setAgentSystem(String agentSystem) {
this.agentSystem = agentSystem;
}
public String getModelNickName() {
return modelNickName;
}
public void setModelNickName(String modelNickName) {
this.modelNickName = modelNickName;
}
public String getAgentId() { public String getAgentId() {
return agentId; return agentId;
} }
......
...@@ -6,332 +6,396 @@ import java.util.Arrays; ...@@ -6,332 +6,396 @@ import java.util.Arrays;
public class BizAgentApplicationInfoEntity { public class BizAgentApplicationInfoEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** id /**
*自增ID * id
* 自增ID
*/ */
private java.lang.Integer id; private java.lang.Integer id;
public java.lang.Integer getId(){ public java.lang.Integer getId() {
return this.id; return this.id;
} }
public void setId(java.lang.Integer id){ public void setId(java.lang.Integer id) {
this.id = id; this.id = id;
} }
/** member_id
*创建应用的用户ID /**
* member_id
* 创建应用的用户ID
*/ */
private java.lang.Integer memberId; private java.lang.Integer memberId;
public java.lang.Integer getMemberId(){ public java.lang.Integer getMemberId() {
return this.memberId; return this.memberId;
} }
public void setMemberId(java.lang.Integer memberId){ public void setMemberId(java.lang.Integer memberId) {
this.memberId = memberId; this.memberId = memberId;
} }
/** agent_id
*agent应用ID /**
* agent_id
* agent应用ID
*/ */
private java.lang.String agentId; private java.lang.String agentId;
public java.lang.String getAgentId(){ public java.lang.String getAgentId() {
return this.agentId; return this.agentId;
} }
public void setAgentId(java.lang.String agentId){ public void setAgentId(java.lang.String agentId) {
this.agentId = agentId; this.agentId = agentId;
} }
/** agent_avatar
*应用头像ICON地址 /**
* agent_avatar
* 应用头像ICON地址
*/ */
private java.lang.String agentAvatar; private java.lang.String agentAvatar;
public java.lang.String getAgentAvatar(){ public java.lang.String getAgentAvatar() {
return this.agentAvatar; return this.agentAvatar;
} }
public void setAgentAvatar(java.lang.String agentAvatar){ public void setAgentAvatar(java.lang.String agentAvatar) {
this.agentAvatar = agentAvatar; this.agentAvatar = agentAvatar;
} }
/** agent_title
*应用标题 /**
* agent_title
* 应用标题
*/ */
private java.lang.String agentTitle; private java.lang.String agentTitle;
public java.lang.String getAgentTitle(){ public java.lang.String getAgentTitle() {
return this.agentTitle; return this.agentTitle;
} }
public void setAgentTitle(java.lang.String agentTitle){ public void setAgentTitle(java.lang.String agentTitle) {
this.agentTitle = agentTitle; this.agentTitle = agentTitle;
} }
/** agent_desc
*应用描述 /**
* agent_desc
* 应用描述
*/ */
private java.lang.String agentDesc; private java.lang.String agentDesc;
public java.lang.String getAgentDesc(){ public java.lang.String getAgentDesc() {
return this.agentDesc; return this.agentDesc;
} }
public void setAgentDesc(java.lang.String agentDesc){ public void setAgentDesc(java.lang.String agentDesc) {
this.agentDesc = agentDesc; this.agentDesc = agentDesc;
} }
/** agent_system
*角色指令 /**
* agent_system
* 角色指令
*/ */
private java.lang.String agentSystem; private java.lang.String agentSystem;
public java.lang.String getAgentSystem(){ public java.lang.String getAgentSystem() {
return this.agentSystem; return this.agentSystem;
} }
public void setAgentSystem(java.lang.String agentSystem){ public void setAgentSystem(java.lang.String agentSystem) {
this.agentSystem = agentSystem; this.agentSystem = agentSystem;
} }
/** agent_publish_status
*应用发布状态 草稿-draft 发布-publish /**
* agent_publish_status
* 应用发布状态 草稿-draft 发布-publish
*/ */
private java.lang.String agentPublishStatus; private java.lang.String agentPublishStatus;
public java.lang.String getAgentPublishStatus(){ public java.lang.String getAgentPublishStatus() {
return this.agentPublishStatus; return this.agentPublishStatus;
} }
public void setAgentPublishStatus(java.lang.String agentPublishStatus){ public void setAgentPublishStatus(java.lang.String agentPublishStatus) {
this.agentPublishStatus = agentPublishStatus; this.agentPublishStatus = agentPublishStatus;
} }
/** publish_time
*发布时间 /**
* publish_time
* 发布时间
*/ */
private java.util.Date publishTime; private java.util.Date publishTime;
public java.util.Date getPublishTime(){ public java.util.Date getPublishTime() {
return this.publishTime; return this.publishTime;
} }
public void setPublishTime(java.util.Date publishTime){ public void setPublishTime(java.util.Date publishTime) {
this.publishTime = publishTime; this.publishTime = publishTime;
} }
/** preamble
*开场白 /**
* preamble
* 开场白
*/ */
private java.lang.String preamble; private java.lang.String preamble;
public java.lang.String getPreamble(){ public java.lang.String getPreamble() {
return this.preamble; return this.preamble;
} }
public void setPreamble(java.lang.String preamble){ public void setPreamble(java.lang.String preamble) {
this.preamble = preamble; this.preamble = preamble;
} }
/** featured_questions
*推荐问 /**
* featured_questions
* 推荐问
*/ */
private java.lang.String[] featuredQuestions; private java.lang.String[] featuredQuestions;
public java.lang.String[] getFeaturedQuestions(){ public java.lang.String[] getFeaturedQuestions() {
return this.featuredQuestions; return this.featuredQuestions;
} }
public void setFeaturedQuestions(java.lang.String[] featuredQuestions){ public void setFeaturedQuestions(java.lang.String[] featuredQuestions) {
this.featuredQuestions = featuredQuestions; this.featuredQuestions = featuredQuestions;
} }
/** communication_turn
*对话上下文保存轮次 0-100 /**
* communication_turn
* 对话上下文保存轮次 0-100
*/ */
private java.lang.Integer communicationTurn; private java.lang.Integer communicationTurn;
public java.lang.Integer getCommunicationTurn(){ public java.lang.Integer getCommunicationTurn() {
return this.communicationTurn; return this.communicationTurn;
} }
public void setCommunicationTurn(java.lang.Integer communicationTurn){ public void setCommunicationTurn(java.lang.Integer communicationTurn) {
this.communicationTurn = communicationTurn; this.communicationTurn = communicationTurn;
} }
/** continuous_question_status
*追问状态 默认-default 自定义-customizable 关闭-close /**
* continuous_question_status
* 追问状态 默认-default 自定义-customizable 关闭-close
*/ */
private java.lang.String continuousQuestionStatus; private java.lang.String continuousQuestionStatus;
public java.lang.String getContinuousQuestionStatus(){ public java.lang.String getContinuousQuestionStatus() {
return this.continuousQuestionStatus; return this.continuousQuestionStatus;
} }
public void setContinuousQuestionStatus(java.lang.String continuousQuestionStatus){ public void setContinuousQuestionStatus(java.lang.String continuousQuestionStatus) {
this.continuousQuestionStatus = continuousQuestionStatus; this.continuousQuestionStatus = continuousQuestionStatus;
} }
/** continuous_question_system
*追问prompt /**
* continuous_question_system
* 追问prompt
*/ */
private java.lang.String continuousQuestionSystem; private java.lang.String continuousQuestionSystem;
public java.lang.String getContinuousQuestionSystem(){ public java.lang.String getContinuousQuestionSystem() {
return this.continuousQuestionSystem; return this.continuousQuestionSystem;
} }
public void setContinuousQuestionSystem(java.lang.String continuousQuestionSystem){ public void setContinuousQuestionSystem(java.lang.String continuousQuestionSystem) {
this.continuousQuestionSystem = continuousQuestionSystem; this.continuousQuestionSystem = continuousQuestionSystem;
} }
/** continuous_question_turn
*追问轮次 1-5 /**
* continuous_question_turn
* 追问轮次 1-5
*/ */
private java.lang.Integer continuousQuestionTurn; private java.lang.Integer continuousQuestionTurn;
public java.lang.Integer getContinuousQuestionTurn(){ public java.lang.Integer getContinuousQuestionTurn() {
return this.continuousQuestionTurn; return this.continuousQuestionTurn;
} }
public void setContinuousQuestionTurn(java.lang.Integer continuousQuestionTurn){ public void setContinuousQuestionTurn(java.lang.Integer continuousQuestionTurn) {
this.continuousQuestionTurn = continuousQuestionTurn; this.continuousQuestionTurn = continuousQuestionTurn;
} }
/** knowledge_ids
*知识库ID /**
* knowledge_ids
* 知识库ID
*/ */
private java.lang.String[] knowledgeIds; private java.lang.String[] knowledgeIds;
public java.lang.String[] getKnowledgeIds(){ public java.lang.String[] getKnowledgeIds() {
return this.knowledgeIds; return this.knowledgeIds;
} }
public void setKnowledgeIds(java.lang.String[] knowledgeIds){ public void setKnowledgeIds(java.lang.String[] knowledgeIds) {
this.knowledgeIds = knowledgeIds; this.knowledgeIds = knowledgeIds;
} }
/** large_model
*问答模型 /**
* large_model
* 问答模型
*/ */
private java.lang.String largeModel; private java.lang.String largeModel;
public java.lang.String getLargeModel(){ public java.lang.String getLargeModel() {
return this.largeModel; return this.largeModel;
} }
public void setLargeModel(java.lang.String largeModel){ public void setLargeModel(java.lang.String largeModel) {
this.largeModel = largeModel; this.largeModel = largeModel;
} }
/** top_p
*对话模型 多样性 [0-1.00] /**
* top_p
* 对话模型 多样性 [0-1.00]
*/ */
private java.lang.Float topP; private java.lang.Float topP;
public java.lang.Float getTopP(){ public java.lang.Float getTopP() {
return this.topP; return this.topP;
} }
public void setTopP(java.lang.Float topP){ public void setTopP(java.lang.Float topP) {
this.topP = topP; this.topP = topP;
} }
/** unit_ids
*组件ID /**
* temperature
* 温度 (0-1.0]
*/
private java.lang.Float temperature;
public Float getTemperature() {
return temperature;
}
public void setTemperature(Float temperature) {
this.temperature = temperature;
}
/**
* unit_ids
* 组件ID
*/ */
private java.lang.String[] unitIds; private java.lang.String[] unitIds;
public java.lang.String[] getUnitIds(){ public java.lang.String[] getUnitIds() {
return this.unitIds; return this.unitIds;
} }
public void setUnitIds(java.lang.String[] unitIds){ public void setUnitIds(java.lang.String[] unitIds) {
this.unitIds = unitIds; this.unitIds = unitIds;
} }
/** variable_structure /**
*变量结构 * variable_structure
* 变量结构
*/ */
private java.lang.String[] variableStructure; private java.lang.String[] variableStructure;
public java.lang.String[] getVariableStructure(){ public java.lang.String[] getVariableStructure() {
return this.variableStructure; return this.variableStructure;
} }
public void setVariableStructure(java.lang.String[] variableStructure){ public void setVariableStructure(java.lang.String[] variableStructure) {
this.variableStructure = variableStructure; this.variableStructure = variableStructure;
} }
/** is_long_memory /**
*是否开启长期记忆 1、Y 是 2、N 否 * is_long_memory
* 是否开启长期记忆 1、Y 是 2、N 否
*/ */
private java.lang.String isLongMemory; private java.lang.String isLongMemory;
public java.lang.String getIsLongMemory(){ public java.lang.String getIsLongMemory() {
return this.isLongMemory; return this.isLongMemory;
} }
public void setIsLongMemory(java.lang.String isLongMemory){ public void setIsLongMemory(java.lang.String isLongMemory) {
this.isLongMemory = isLongMemory; this.isLongMemory = isLongMemory;
} }
/** is_deleted /**
*是否删除 1、Y 是 2、N 否 * is_deleted
* 是否删除 1、Y 是 2、N 否
*/ */
private java.lang.String isDeleted; private java.lang.String isDeleted;
public java.lang.String getIsDeleted(){ public java.lang.String getIsDeleted() {
return this.isDeleted; return this.isDeleted;
} }
public void setIsDeleted(java.lang.String isDeleted){ public void setIsDeleted(java.lang.String isDeleted) {
this.isDeleted = isDeleted; this.isDeleted = isDeleted;
} }
/** CREATOR
*创建人 /**
* CREATOR
* 创建人
*/ */
private java.lang.String creator; private java.lang.String creator;
public java.lang.String getCreator(){ public java.lang.String getCreator() {
return this.creator; return this.creator;
} }
public void setCreator(java.lang.String creator){ public void setCreator(java.lang.String creator) {
this.creator = creator; this.creator = creator;
} }
/** CREATED_TIME
*创建时间 /**
* CREATED_TIME
* 创建时间
*/ */
private java.util.Date createdTime; private java.util.Date createdTime;
public java.util.Date getCreatedTime(){ public java.util.Date getCreatedTime() {
return this.createdTime; return this.createdTime;
} }
public void setCreatedTime(java.util.Date createdTime){ public void setCreatedTime(java.util.Date createdTime) {
this.createdTime = createdTime; this.createdTime = createdTime;
} }
/** MODIFIER
*修改人 /**
* MODIFIER
* 修改人
*/ */
private java.lang.String modifier; private java.lang.String modifier;
public java.lang.String getModifier(){ public java.lang.String getModifier() {
return this.modifier; return this.modifier;
} }
public void setModifier(java.lang.String modifier){ public void setModifier(java.lang.String modifier) {
this.modifier = modifier; this.modifier = modifier;
} }
/** MODIFIED_TIME
*修改时间 /**
* MODIFIED_TIME
* 修改时间
*/ */
private java.util.Date modifiedTime; private java.util.Date modifiedTime;
public java.util.Date getModifiedTime(){ public java.util.Date getModifiedTime() {
return this.modifiedTime; return this.modifiedTime;
} }
public void setModifiedTime(java.util.Date modifiedTime){ public void setModifiedTime(java.util.Date modifiedTime) {
this.modifiedTime = modifiedTime; this.modifiedTime = modifiedTime;
} }
/** SYS_VERSION
*乐观锁,版本号 /**
* SYS_VERSION
* 乐观锁,版本号
*/ */
private java.lang.Integer sysVersion; private java.lang.Integer sysVersion;
public java.lang.Integer getSysVersion(){ public java.lang.Integer getSysVersion() {
return this.sysVersion; return this.sysVersion;
} }
public void setSysVersion(java.lang.Integer sysVersion){ public void setSysVersion(java.lang.Integer sysVersion) {
this.sysVersion = sysVersion; this.sysVersion = sysVersion;
} }
......
package cn.com.poc.agent_application.entity; package cn.com.poc.agent_application.entity;
import java.util.Arrays;
public class BizAgentApplicationPublishEntity { public class BizAgentApplicationPublishEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -236,6 +234,22 @@ public class BizAgentApplicationPublishEntity { ...@@ -236,6 +234,22 @@ public class BizAgentApplicationPublishEntity {
public void setTopP(java.lang.Float topP){ public void setTopP(java.lang.Float topP){
this.topP = topP; this.topP = topP;
} }
/** temperature
*对话模型 温度 [0-1.00]
*/
private java.lang.Float temperature;
public java.lang.Float getTemperature(){
return this.temperature;
}
public void setTemperature(java.lang.Float temperature){
this.temperature = temperature;
}
/** unit_ids /** unit_ids
*组件ID *组件ID
*/ */
...@@ -336,37 +350,4 @@ public class BizAgentApplicationPublishEntity { ...@@ -336,37 +350,4 @@ public class BizAgentApplicationPublishEntity {
public void setSysVersion(java.lang.Integer sysVersion){ public void setSysVersion(java.lang.Integer sysVersion){
this.sysVersion = sysVersion; this.sysVersion = sysVersion;
} }
@Override
public String toString() {
return "BizAgentApplicationPublishEntity{" +
"id=" + id +
", memberId=" + memberId +
", agentId='" + agentId + '\'' +
", agentAvatar='" + agentAvatar + '\'' +
", agentTitle='" + agentTitle + '\'' +
", agentDesc='" + agentDesc + '\'' +
", agentSystem='" + agentSystem + '\'' +
", agentPublishStatus='" + agentPublishStatus + '\'' +
", publishTime=" + publishTime +
", preamble='" + preamble + '\'' +
", variableStructure=" + Arrays.toString(variableStructure) +
", featuredQuestions=" + Arrays.toString(featuredQuestions) +
", communicationTurn=" + communicationTurn +
", continuousQuestionStatus='" + continuousQuestionStatus + '\'' +
", continuousQuestionSystem='" + continuousQuestionSystem + '\'' +
", continuousQuestionTurn=" + continuousQuestionTurn +
", knowledgeIds=" + Arrays.toString(knowledgeIds) +
", largeModel='" + largeModel + '\'' +
", topP=" + topP +
", unitIds=" + Arrays.toString(unitIds) +
", isLongMemory='" + isLongMemory + '\'' +
", isDeleted='" + isDeleted + '\'' +
", creator='" + creator + '\'' +
", createdTime=" + createdTime +
", modifier='" + modifier + '\'' +
", modifiedTime=" + modifiedTime +
", sysVersion=" + sysVersion +
'}';
}
} }
\ No newline at end of file
...@@ -314,6 +314,25 @@ public class BizAgentApplicationInfoModel extends BaseModelClass implements Seri ...@@ -314,6 +314,25 @@ public class BizAgentApplicationInfoModel extends BaseModelClass implements Seri
} }
/** temperature
*对话模型 温度 [0-1.00]
*/
private java.lang.Float temperature;
@Column(name = "temperature",length = 12)
public java.lang.Float getTemperature(){
return this.temperature;
}
public void setTemperature(java.lang.Float temperature){
this.temperature = temperature;
super.addValidField("temperature");
}
/** unit_ids /** unit_ids
*组件ID *组件ID
*/ */
......
...@@ -297,6 +297,23 @@ public class BizAgentApplicationPublishModel extends BaseModelClass implements S ...@@ -297,6 +297,23 @@ public class BizAgentApplicationPublishModel extends BaseModelClass implements S
} }
/** temperature
*对话模型 温度 [0-1.00]
*/
private java.lang.Float temperature;
@Column(name = "temperature",length = 12)
public java.lang.Float getTemperature(){
return this.temperature;
}
public void setTemperature(java.lang.Float temperature){
this.temperature = temperature;
super.addValidField("temperature");
}
/** unit_ids /** unit_ids
*组件ID *组件ID
*/ */
......
...@@ -17,6 +17,7 @@ select distinct ...@@ -17,6 +17,7 @@ select distinct
knowledge_ids, knowledge_ids,
large_model, large_model,
top_p, top_p,
temperature,
unit_ids, unit_ids,
variable_structure, variable_structure,
is_long_memory, is_long_memory,
......
...@@ -284,6 +284,23 @@ public class AgentApplicationInfoQueryItem extends BaseItemClass implements Seri ...@@ -284,6 +284,23 @@ public class AgentApplicationInfoQueryItem extends BaseItemClass implements Seri
this.topP = topP; this.topP = topP;
} }
/** temperature
*对话模型 温度 [0-1.00]
*/
private java.lang.Float temperature;
@Column(name = "temperature")
public java.lang.Float getTemperature(){
return this.temperature;
}
public void setTemperature(java.lang.Float temperature){
this.temperature = temperature;
}
/** /**
* unit_ids * unit_ids
* unit_ids * unit_ids
......
...@@ -187,22 +187,28 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -187,22 +187,28 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
List<Tool> tools = new ArrayList<>(); List<Tool> tools = new ArrayList<>();
//开启对话变量 //开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) { if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
String functionName = "set_value_memory"; String functionName = LargeModelFunctionEnum.set_value_memory.name();
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0); String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class); Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool); tools.add(tool);
} }
//开启长期记忆 //开启长期记忆
if (CommonConstant.YOrN.Y.equals(infoEntity.getIsLongMemory())) { if (CommonConstant.YOrN.Y.equals(infoEntity.getIsLongMemory())) {
String functionName = "set_long_memory"; String functionName = LargeModelFunctionEnum.set_long_memory.name();
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getLLMConfig().get(0); String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getLLMConfig().get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class); Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool); tools.add(tool);
} }
//对话大模型配置
String model = StringUtils.isNotBlank(dto.getModelNickName()) ? dto.getModelNickName() : infoEntity.getLargeModel();
Float topP = dto.getTopP() == null ? infoEntity.getTopP() : dto.getTopP();
Float temperature = dto.getTemperature() == null ? infoEntity.getTemperature() : dto.getTemperature();
String agentSystem = StringUtils.isBlank(dto.getAgentSystem()) ? infoEntity.getAgentSystem() : dto.getAgentSystem();
//调用应用服务 //调用应用服务
agentApplicationInfoService.callAgentApplication(agentId, infoEntity.getLargeModel(), infoEntity.getUnitIds() agentApplicationInfoService.callAgentApplication(agentId, model, infoEntity.getUnitIds()
, infoEntity.getAgentSystem(), kdIds.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getTopP() , agentSystem, kdIds.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), topP, temperature
, dto.getMessages(), tools, httpServletResponse); , dto.getMessages(), tools, httpServletResponse);
} catch (Exception e) { } catch (Exception e) {
httpServletResponse.setContentType("text/event-stream"); httpServletResponse.setContentType("text/event-stream");
......
package cn.com.poc.agent_application.scheduler;
import cn.com.poc.expose.aggregate.AgentApplicationService;
import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem;
import cn.com.poc.message.entity.KnowledgeTrainStatusMessage;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Component
public class RecommendQuestionScheduler {
@Resource
private AgentApplicationService agentApplicationService;
/**
* 每日凌晨
*
* @throws Exception
*/
@Scheduled(cron = "0 0 0 * * ?")
public void knowledgeInfoStatusUpdateScheduler() throws Exception {
agentApplicationService.createRecommendQuestion();
}
}
...@@ -173,6 +173,10 @@ public class BizAgentApplicationInfoServiceImpl extends BaseServiceImpl ...@@ -173,6 +173,10 @@ public class BizAgentApplicationInfoServiceImpl extends BaseServiceImpl
if (entity.getTopP() != null) { if (entity.getTopP() != null) {
Assert.isTrue(entity.getTopP() >= 0 && entity.getTopP() <= 1.00, "top p is error,must more than 0 and less than 1.0"); Assert.isTrue(entity.getTopP() >= 0 && entity.getTopP() <= 1.00, "top p is error,must more than 0 and less than 1.0");
} }
if (entity.getTemperature() != null) {
Assert.isTrue(entity.getTemperature() > 0 && entity.getTemperature() <= 1.0, "temperature is error,must greater than 0, less than or equal to 1.9");
}
model.setTemperature(entity.getTemperature());
model.setTopP(entity.getTopP()); model.setTopP(entity.getTopP());
model.setContinuousQuestionStatus(entity.getContinuousQuestionStatus()); model.setContinuousQuestionStatus(entity.getContinuousQuestionStatus());
model.setContinuousQuestionSystem(entity.getContinuousQuestionSystem()); model.setContinuousQuestionSystem(entity.getContinuousQuestionSystem());
......
...@@ -8,15 +8,15 @@ import java.util.concurrent.ThreadFactory; ...@@ -8,15 +8,15 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
/** /**
* Communication 线程池 * 公共业务线程池
*/ */
public class CommunicationThreadPoolExecutor { public class CommonThreadPoolExecutor {
final private static String THREAD_POOL_NAME = "CommunicationThreadExecutor"; final private static String THREAD_POOL_NAME = "Common_Thread_Executor";
final private static int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors(); final private static int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
final private static int MAXIMUM_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 5; final private static int MAXIMUM_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 20;
final private static int KEEP_ALIVE_TIME = 60; final private static int KEEP_ALIVE_TIME = 60;
......
...@@ -6,7 +6,7 @@ import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; ...@@ -6,7 +6,7 @@ import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripper;
//import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -31,7 +31,7 @@ public class DocumentLoad { ...@@ -31,7 +31,7 @@ public class DocumentLoad {
case "docx": case "docx":
return loadWordDocx(file); return loadWordDocx(file);
case "doc": case "doc":
return loadWordDocx(file); return loadWordDoc(file);
case "md": case "md":
return loadMarkDown(file); return loadMarkDown(file);
case "pdf": case "pdf":
...@@ -62,12 +62,12 @@ public class DocumentLoad { ...@@ -62,12 +62,12 @@ public class DocumentLoad {
return xwpfWordExtractor.getText(); return xwpfWordExtractor.getText();
} }
// public static String loadWordDoc(File file) throws IOException { public static String loadWordDoc(File file) throws IOException {
// FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
// HWPFDocument doc = new HWPFDocument(fis); WordExtractor wordExtractor = new WordExtractor(fis);
// fis.close(); fis.close();
// return doc.getText().toString(); return wordExtractor.getText().toString();
// } }
public static String loadTxt(File file) throws IOException { public static String loadTxt(File file) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
......
...@@ -18,4 +18,16 @@ public interface AgentApplicationService { ...@@ -18,4 +18,16 @@ public interface AgentApplicationService {
*/ */
List<String> createContinueQuestions(String input); List<String> createContinueQuestions(String input);
/**
* [首页] 获取推荐问
*/
List<String> getRecommendQuestions() throws InterruptedException;
/**
* [首页] 生成推荐问
*
* @throws InterruptedException
*/
void createRecommendQuestion() throws InterruptedException;
} }
...@@ -10,6 +10,8 @@ import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordSe ...@@ -10,6 +10,8 @@ import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordSe
import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService; import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.pool.CommonThreadPoolExecutor;
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.common.utils.JsonUtils;
import cn.com.poc.expose.aggregate.AgentApplicationService; import cn.com.poc.expose.aggregate.AgentApplicationService;
...@@ -33,14 +35,20 @@ import org.springframework.stereotype.Service; ...@@ -33,14 +35,20 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.*;
@Service @Service
public class AgentApplicationServiceImpl implements AgentApplicationService { public class AgentApplicationServiceImpl implements AgentApplicationService {
final private Logger logger = LoggerFactory.getLogger(AgentApplicationService.class); final private Logger logger = LoggerFactory.getLogger(AgentApplicationService.class);
final private String AGENT_APPLICATION_RECOMMEND_QUESTIONS = "AGENT_APPLICATION_RECOMMEND_QUESTIONS";
@Resource @Resource
private KnowledgeService knowledgeService; private KnowledgeService knowledgeService;
...@@ -59,6 +67,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -59,6 +67,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Resource @Resource
private LLMService llmService; private LLMService llmService;
@Resource
private RedisService redisService;
@Override @Override
public void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception { public void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception {
...@@ -77,59 +88,31 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -77,59 +88,31 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
throw new BusinessException("未找到应用"); throw new BusinessException("未找到应用");
} }
if (StringUtils.isBlank(dialogsId)) {
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空
dialogsId = agentId + "_" + userBaseEntity.getUserId();
}
//获取知识库配置 //获取知识库配置
List<Integer> kdIdList = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds()); List<Integer> kdIdList = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
// 构造对话参数 // 构造对话参数
List<Message> messages = new ArrayList<>(); List<Message> messages = buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), input);
buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), messages, input);
//配置对话function //配置对话function
List<Tool> tools = new ArrayList<>(); List<Tool> tools = buildMemoryConfig(infoEntity);
//开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
String functionName = "set_value_memory";
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
}
//开启长期记忆
if (CommonConstant.YOrN.Y.equals(infoEntity.getIsLongMemory())) {
String functionName = "set_long_memory";
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getLLMConfig().get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
}
//对话
String output = agentApplicationInfoService.callAgentApplication(dialogsId, infoEntity.getLargeModel(), String output = agentApplicationInfoService.callAgentApplication(dialogsId, infoEntity.getLargeModel(),
infoEntity.getUnitIds(), infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getUnitIds(), infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(),
infoEntity.getTopP(), messages, tools, httpServletResponse); infoEntity.getTopP(), infoEntity.getTemperature(), messages, tools, httpServletResponse);
//保存对话记录 //保存对话记录
// 例句回答时间戳 saveDialoguesRecord(dialogsId, input, infoEntity, userBaseEntity, inputTimestamp, output);
Long outputTimestamp = System.currentTimeMillis();
BizAgentApplicationDialoguesRecordEntity inputRecord = new BizAgentApplicationDialoguesRecordEntity();
inputRecord.setAgentId(infoEntity.getAgentId());
inputRecord.setMemberId(userBaseEntity.getUserId());
inputRecord.setContent(input);
inputRecord.setDialogsId(dialogsId);
inputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
inputRecord.setTimestamp(inputTimestamp);
BizAgentApplicationDialoguesRecordEntity outputRecord = new BizAgentApplicationDialoguesRecordEntity();
outputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.ASSISTANT);
outputRecord.setAgentId(infoEntity.getAgentId());
outputRecord.setDialogsId(dialogsId);
outputRecord.setMemberId(userBaseEntity.getUserId());
outputRecord.setContent(output);
outputRecord.setTimestamp(outputTimestamp);
bizAgentApplicationDialoguesRecordService.save(inputRecord);
bizAgentApplicationDialoguesRecordService.save(outputRecord);
} }
@Override @Override
public List<String> createContinueQuestions(String input) { public List<String> createContinueQuestions(String input) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_CONTINUE_QUESTIONS); BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_CONTINUE_QUESTIONS);
...@@ -157,12 +140,10 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -157,12 +140,10 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}}.toArray(new Message[1])); }}.toArray(new Message[1]));
largeModelResponse.setTopP(configEntity.getTopP()); largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-CONTINUE-QUESTIONS"); largeModelResponse.setUser("POC-CONTINUE-QUESTIONS");
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse); LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
if (largeModelDemandResult == null || !"0".equals(largeModelDemandResult.getCode())) { if (largeModelDemandResult == null || !"0".equals(largeModelDemandResult.getCode())) {
logger.error("continue question error ,largeModelDemandResult:{} , largeModelResponse:{}", largeModelDemandResult != null ? largeModelDemandResult.toString() : StringUtils.EMPTY logger.error("continue question error ,largeModelDemandResult:{} , largeModelResponse:{}", largeModelDemandResult != null ? largeModelDemandResult.toString() : StringUtils.EMPTY
, largeModelResponse); , largeModelResponse);
// throw new BusinessException("追问失败");
return null; return null;
} }
String res = largeModelDemandResult.getMessage(); String res = largeModelDemandResult.getMessage();
...@@ -172,7 +153,73 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -172,7 +153,73 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}.getType()); }.getType());
} }
private void buildMessages(String dialogsId, String agentId, Long userId, List<Message> messages, String input) throws Exception { @Override
public List<String> getRecommendQuestions() throws InterruptedException {
if (!redisService.hasKey(AGENT_APPLICATION_RECOMMEND_QUESTIONS)) {
synchronized (AgentApplicationInfoService.class) {
if (!redisService.hasKey(AGENT_APPLICATION_RECOMMEND_QUESTIONS)) {
createRecommendQuestion();
}
}
}
long size = redisService.lGetListSize(AGENT_APPLICATION_RECOMMEND_QUESTIONS);
if (size < 3) {
redisService.del(AGENT_APPLICATION_RECOMMEND_QUESTIONS);
return null;
}
Set<Long> indexSet = new HashSet<>();
SecureRandom secureRandom = new SecureRandom();
do {
indexSet.add((long) secureRandom.nextInt((int) size));
} while (indexSet.size() < 3);
List<String> result = new ArrayList<>();
for (Long index : indexSet) {
Object str = redisService.lGetIndex(AGENT_APPLICATION_RECOMMEND_QUESTIONS, index);
result.add(str.toString());
}
return result;
}
@Override
public void createRecommendQuestion() throws InterruptedException {
List<Object> questions = new CopyOnWriteArrayList<>();
CountDownLatch countDownLatch = new CountDownLatch(20);
for (int i = 0; i < 20; i++) {
CommonThreadPoolExecutor.addTask(() -> {
Message message = new Message();
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
MultiContent multiContent = new MultiContent();
multiContent.setText("请给我生成一个推荐问题,不超过50字,只需输出问题即可,不要输出额外的内容,不要换行");
multiContent.setType("text");
ArrayList<MultiContent> multiContents = new ArrayList<>();
multiContents.add(multiContent);
message.setContent(multiContents);
Message[] messages = new Message[]{message};
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("ERNIE-4.0-8K");
largeModelResponse.setMessages(messages);
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
questions.add(largeModelDemandResult.getMessage());
countDownLatch.countDown();
});
}
countDownLatch.await(2, TimeUnit.MINUTES);
if (CollectionUtils.isEmpty(questions)) {
throw new BusinessException("生成推荐问题失败");
}
redisService.del(AGENT_APPLICATION_RECOMMEND_QUESTIONS);
redisService.lSet(AGENT_APPLICATION_RECOMMEND_QUESTIONS, questions);
}
private List<Message> buildMessages(String dialogsId, String agentId, Long userId, String input) throws Exception {
List<Message> messages = new ArrayList<>();
BizAgentApplicationDialoguesRecordEntity recordEntity = new BizAgentApplicationDialoguesRecordEntity(); BizAgentApplicationDialoguesRecordEntity recordEntity = new BizAgentApplicationDialoguesRecordEntity();
recordEntity.setDialogsId(dialogsId); recordEntity.setDialogsId(dialogsId);
recordEntity.setMemberId(userId); recordEntity.setMemberId(userId);
...@@ -201,6 +248,49 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -201,6 +248,49 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER); message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
messages.add(message); messages.add(message);
logger.info("--------- Build Messages dialogsId:{},agentId:{},messages:{}--------------", dialogsId, agentId, messages); logger.info("--------- Build Messages dialogsId:{},agentId:{},messages:{}--------------", dialogsId, agentId, messages);
return messages;
} }
private void saveDialoguesRecord(String dialogsId, String input, BizAgentApplicationPublishEntity infoEntity, UserBaseEntity userBaseEntity, Long inputTimestamp, String output) throws Exception {
// 回答时间戳
Long outputTimestamp = System.currentTimeMillis();
BizAgentApplicationDialoguesRecordEntity inputRecord = new BizAgentApplicationDialoguesRecordEntity();
inputRecord.setAgentId(infoEntity.getAgentId());
inputRecord.setMemberId(userBaseEntity.getUserId());
inputRecord.setContent(input);
inputRecord.setDialogsId(dialogsId);
inputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
inputRecord.setTimestamp(inputTimestamp);
BizAgentApplicationDialoguesRecordEntity outputRecord = new BizAgentApplicationDialoguesRecordEntity();
outputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.ASSISTANT);
outputRecord.setAgentId(infoEntity.getAgentId());
outputRecord.setDialogsId(dialogsId);
outputRecord.setMemberId(userBaseEntity.getUserId());
outputRecord.setContent(output);
outputRecord.setTimestamp(outputTimestamp);
bizAgentApplicationDialoguesRecordService.save(inputRecord);
bizAgentApplicationDialoguesRecordService.save(outputRecord);
}
private List<Tool> buildMemoryConfig(BizAgentApplicationPublishEntity infoEntity) {
List<Tool> tools = new ArrayList<>();
//开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
String functionName = LargeModelFunctionEnum.set_value_memory.name();
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
}
//开启长期记忆
if (CommonConstant.YOrN.Y.equals(infoEntity.getIsLongMemory())) {
String functionName = LargeModelFunctionEnum.set_long_memory.name();
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getLLMConfig().get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
}
return tools;
}
} }
package cn.com.poc.expose.rest; package cn.com.poc.expose.rest;
import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto; import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
import cn.com.poc.expose.dto.AgentApplicationDto; import cn.com.poc.expose.dto.AgentApplicationDto;
...@@ -21,10 +20,15 @@ import java.util.List; ...@@ -21,10 +20,15 @@ import java.util.List;
@Permission(value = Access.Safety) @Permission(value = Access.Safety)
public interface AgentApplicationRest extends BaseRest { public interface AgentApplicationRest extends BaseRest {
/**
* 【首页】 获取推荐问
*/
List<String> getRecommendQuestions() throws Exception;
/** /**
* 创建对话 * 创建对话
*/ */
String createDialogues(@RequestParam String agentId) throws Exception; String createDialogues() throws Exception;
/** /**
* 调用 已发布Agent应用 * 调用 已发布Agent应用
...@@ -43,6 +47,12 @@ public interface AgentApplicationRest extends BaseRest { ...@@ -43,6 +47,12 @@ public interface AgentApplicationRest extends BaseRest {
@Permission(value = Access.Anonymous) @Permission(value = Access.Anonymous)
BizAgentApplicationPublishDto getInfo(@RequestParam String agentId) throws Exception; BizAgentApplicationPublishDto getInfo(@RequestParam String agentId) throws Exception;
/**
* 获取 已发布[官方]默认应用列表
*/
@Permission(value = Access.Anonymous)
List<SearchAgentApplicationDto> getDefaultList(PagingInfo pagingInfo) throws Exception;
/** /**
* 下架已发布应用 * 下架已发布应用
*/ */
......
...@@ -2,11 +2,9 @@ package cn.com.poc.expose.rest.impl; ...@@ -2,11 +2,9 @@ package cn.com.poc.expose.rest.impl;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert; import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert;
import cn.com.poc.agent_application.convert.BizAgentApplicationDialoguesRecordConvert;
import cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert; import cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert;
import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto; import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationDialoguesRecordDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
...@@ -57,7 +55,12 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -57,7 +55,12 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
private BizAgentApplicationDialoguesRecordService bizAgentApplicationDialoguesRecordService; private BizAgentApplicationDialoguesRecordService bizAgentApplicationDialoguesRecordService;
@Override @Override
public String createDialogues(String agentId) { public List<String> getRecommendQuestions() throws Exception {
return agentApplicationService.getRecommendQuestions();
}
@Override
public String createDialogues() {
return "DIA_" + UUIDTool.getUUID(); return "DIA_" + UUIDTool.getUUID();
} }
...@@ -102,6 +105,28 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -102,6 +105,28 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
return BizAgentApplicationPublishConvert.entityToDto(entity); return BizAgentApplicationPublishConvert.entityToDto(entity);
} }
@Override
public List<SearchAgentApplicationDto> getDefaultList(PagingInfo pagingInfo) throws Exception {
List<SearchAgentApplicationDto> result = new ArrayList<>();
BizAgentApplicationPublishEntity publishEntity = new BizAgentApplicationPublishEntity();
publishEntity.setMemberId(0);
publishEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizAgentApplicationPublishEntity> entities = bizAgentApplicationPublishService.findByExample(publishEntity, pagingInfo);
if (CollectionUtils.isNotEmpty(entities)) {
result = entities.stream().map(value -> {
SearchAgentApplicationDto searchAgentApplicationDto = new SearchAgentApplicationDto();
searchAgentApplicationDto.setAgentId(value.getAgentId());
searchAgentApplicationDto.setAgentTitle(value.getAgentTitle());
searchAgentApplicationDto.setAgentDesc(value.getAgentDesc());
searchAgentApplicationDto.setAgentAvatar(value.getAgentAvatar());
searchAgentApplicationDto.setPublishedTime(value.getModifiedTime());
searchAgentApplicationDto.setCreator("官方");
return searchAgentApplicationDto;
}).collect(Collectors.toList());
}
return result;
}
@Override @Override
public void unPublish(String agentId) throws Exception { public void unPublish(String agentId) throws Exception {
Assert.notBlank(agentId, "应用ID不能为空"); Assert.notBlank(agentId, "应用ID不能为空");
...@@ -127,7 +152,8 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -127,7 +152,8 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
result = memberDialoguesQueryItems.stream().map(item -> { result = memberDialoguesQueryItems.stream().map(item -> {
UserDialoguesDto userDialoguesDto = new UserDialoguesDto(); UserDialoguesDto userDialoguesDto = new UserDialoguesDto();
userDialoguesDto.setDialogsId(item.getDialogsId()); userDialoguesDto.setDialogsId(item.getDialogsId());
userDialoguesDto.setContent(item.getContent()); String content = item.getContent().length() > 20 ? item.getContent().substring(0, 20) : item.getContent();
userDialoguesDto.setContent(content);
return userDialoguesDto; return userDialoguesDto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
......
...@@ -61,7 +61,7 @@ public interface KnowledgeService { ...@@ -61,7 +61,7 @@ public interface KnowledgeService {
/** /**
* 获取知识库分片 * 获取知识库分片
*/ */
GetKnowledgeChunkInfoResult getChunkInfo(List<Integer> kdIds, PagingInfo pagingInfo); GetKnowledgeChunkInfoResult getChunkInfo(List<Integer> kdIds, String query, PagingInfo pagingInfo);
/** /**
* 开关知识库分片 * 开关知识库分片
......
...@@ -81,7 +81,7 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -81,7 +81,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
long fileSizeInBytes = file.length(); long fileSizeInBytes = file.length();
double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024); double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024);
if (fileSizeInMB > 10) { if (fileSizeInMB > 10) {
throw new BusinessException("上传的文件不能超过5M,文件名:" + documentName); throw new BusinessException("上传的文件不能超过10M,文件名:" + documentName);
} }
String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容 String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容
...@@ -91,8 +91,8 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -91,8 +91,8 @@ public class KnowledgeServiceImpl implements KnowledgeService {
//获取文件字符数 //获取文件字符数
long charCount = fileContent.length(); long charCount = fileContent.length();
//文件字符数不能超过100w //文件字符数不能超过100w
if (charCount > 2 * 10000) { if (charCount > 100 * 10000) {
throw new BusinessException("文件内容字符数不能超过2w,文件名: " + documentName); throw new BusinessException("文件内容字符数不能超过100w,文件名: " + documentName);
} }
//文件上传 //文件上传
...@@ -242,14 +242,14 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -242,14 +242,14 @@ public class KnowledgeServiceImpl implements KnowledgeService {
} }
@Override @Override
public GetKnowledgeChunkInfoResult getChunkInfo(List<Integer> kdIds, PagingInfo pagingInfo) { public GetKnowledgeChunkInfoResult getChunkInfo(List<Integer> kdIds, String query, PagingInfo pagingInfo) {
List<String> knowledgeIds = new ArrayList<>(); List<String> knowledgeIds = new ArrayList<>();
for (Integer kdId : kdIds) { for (Integer kdId : kdIds) {
BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId); BizKnowledgeDocumentEntity bizKnowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId(); String knowledgeId = bizKnowledgeDocumentEntity.getKnowledgeId();
knowledgeIds.add(knowledgeId); knowledgeIds.add(knowledgeId);
} }
return demandKnowledgeService.getKnowledgeChunkInfos(knowledgeIds, pagingInfo); return demandKnowledgeService.getKnowledgeChunkInfos(knowledgeIds, query, pagingInfo);
} }
@Override @Override
......
...@@ -52,7 +52,7 @@ public class BizKnowledgeInfoConvert { ...@@ -52,7 +52,7 @@ public class BizKnowledgeInfoConvert {
dto.setKdIds(entity.getKdIds()); dto.setKdIds(entity.getKdIds());
dto.setTrainStatus(entity.getTrainStatus()); dto.setTrainStatus(entity.getTrainStatus());
dto.setDesc(entity.getKnowledgeDesc()); dto.setDesc(entity.getKnowledgeDesc());
dto.setModifiedTime(entity.getModifiedTime()); dto.setCreatedTime(entity.getCreatedTime());
return dto; return dto;
} }
......
...@@ -101,18 +101,17 @@ public class BizKnowledgeInfoDto { ...@@ -101,18 +101,17 @@ public class BizKnowledgeInfoDto {
} }
/** /**
* MODIFIED_TIME * createdTime
* MODIFIED_TIME * createdTime
*/ */
private java.util.Date modifiedTime; private java.util.Date createdTime;
@Column(name = "MODIFIED_TIME") public java.util.Date getCreatedTime() {
public java.util.Date getModifiedTime() { return this.createdTime;
return this.modifiedTime;
} }
public void setModifiedTime(java.util.Date modifiedTime) { public void setCreatedTime(java.util.Date createdTime) {
this.modifiedTime = modifiedTime; this.createdTime = createdTime;
} }
} }
\ No newline at end of file
...@@ -142,5 +142,5 @@ public interface KnowledgeRest extends BaseRest { ...@@ -142,5 +142,5 @@ public interface KnowledgeRest extends BaseRest {
/** /**
* 获取知识库分片信息 * 获取知识库分片信息
*/ */
GetKnowledgeChunkInfoResult getChunks(@RequestParam List<Integer> kdIds, PagingInfo pagingInfo); GetKnowledgeChunkInfoResult getChunks(@RequestParam List<Integer> kdIds, @RequestParam String query, PagingInfo pagingInfo);
} }
...@@ -278,8 +278,8 @@ public class KnowledgeRestImpl implements KnowledgeRest { ...@@ -278,8 +278,8 @@ public class KnowledgeRestImpl implements KnowledgeRest {
} }
@Override @Override
public GetKnowledgeChunkInfoResult getChunks(List<Integer> kdIds, PagingInfo pagingInfo) { public GetKnowledgeChunkInfoResult getChunks(List<Integer> kdIds, String query, PagingInfo pagingInfo) {
Assert.notEmpty(kdIds); Assert.notEmpty(kdIds);
return knowledgeService.getChunkInfo(kdIds, pagingInfo); return knowledgeService.getChunkInfo(kdIds, query, pagingInfo);
} }
} }
package cn.com.poc.knowledge.scheduler; package cn.com.poc.knowledge.scheduler;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.knowledge.constant.KnowledgeConstant; import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition; import cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition;
import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem; import cn.com.poc.knowledge.query.KnowledgeInfosQueryItem;
import cn.com.poc.knowledge.service.BizKnowledgeDocumentService;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService; import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.message.entity.KnowledgeTrainStatusMessage; import cn.com.poc.message.entity.KnowledgeTrainStatusMessage;
import cn.com.poc.message.service.KnowledgeProducerService; import cn.com.poc.message.service.KnowledgeProducerService;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.poc.thirdparty.resource.demand.ai.constants.KnowledgeTrainStatusConstant;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection;
import java.util.List; import java.util.List;
@Component @Component
...@@ -22,6 +29,12 @@ public class KnowledgeInfoScheduler { ...@@ -22,6 +29,12 @@ public class KnowledgeInfoScheduler {
@Resource @Resource
private BizKnowledgeInfoService bizKnowledgeInfoService; private BizKnowledgeInfoService bizKnowledgeInfoService;
@Resource
private BizKnowledgeDocumentService bizKnowledgeDocumentService;
@Resource
private DemandKnowledgeService demandKnowledgeService;
@Scheduled(cron = "0 0/1 * * * ?") @Scheduled(cron = "0 0/1 * * * ?")
public void knowledgeInfoStatusUpdateScheduler() throws Exception { public void knowledgeInfoStatusUpdateScheduler() throws Exception {
KnowledgeInfosQueryCondition condition = new KnowledgeInfosQueryCondition(); KnowledgeInfosQueryCondition condition = new KnowledgeInfosQueryCondition();
...@@ -34,4 +47,34 @@ public class KnowledgeInfoScheduler { ...@@ -34,4 +47,34 @@ public class KnowledgeInfoScheduler {
knowledgeProducerService.knowledgeInfoStatusCheck(knowledgeTrainStatusMessage); knowledgeProducerService.knowledgeInfoStatusCheck(knowledgeTrainStatusMessage);
} }
} }
@Scheduled(cron = "0 0/1 * * * ?")
public void knowledgeDocumentStatusUpdateScheduler() throws Exception {
BizKnowledgeDocumentEntity knowledgeDocumentEntity = new BizKnowledgeDocumentEntity();
knowledgeDocumentEntity.setTrainStatus(KnowledgeConstant.TrainStatus.TRAINING);
knowledgeDocumentEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizKnowledgeDocumentEntity> entities = bizKnowledgeDocumentService.findByExample(knowledgeDocumentEntity, null);
if (CollectionUtils.isEmpty(entities)) {
return;
}
for (BizKnowledgeDocumentEntity entity : entities) {
String trainKnowledgeStatus = demandKnowledgeService.trainKnowledgeStatus(entity.getKnowledgeId());
if (KnowledgeTrainStatusConstant.fail.equals(trainKnowledgeStatus)) {
KnowledgeTrainStatusMessage message = new KnowledgeTrainStatusMessage();
message.setKdId(entity.getKdId());
message.setKnowledgeId(entity.getKnowledgeId());
message.setStatus(KnowledgeConstant.TrainStatus.FAIL);
knowledgeProducerService.trainStatusUpdate(message);
//记录失败原因
} else if (KnowledgeTrainStatusConstant.success.equals(trainKnowledgeStatus)) {
KnowledgeTrainStatusMessage message = new KnowledgeTrainStatusMessage();
message.setKdId(entity.getKdId());
message.setKnowledgeId(entity.getKnowledgeId());
message.setStatus(KnowledgeConstant.TrainStatus.COMPLETE);
knowledgeProducerService.trainStatusUpdate(message);
}
}
}
} }
...@@ -113,7 +113,7 @@ public class BizKnowledgeInfoServiceImpl extends BaseServiceImpl ...@@ -113,7 +113,7 @@ public class BizKnowledgeInfoServiceImpl extends BaseServiceImpl
@Override @Override
public List<KnowledgeInfosQueryItem> knowledgeInfos(KnowledgeInfosQueryCondition condition, PagingInfo pagingInfo) throws Exception { public List<KnowledgeInfosQueryItem> knowledgeInfos(KnowledgeInfosQueryCondition condition, PagingInfo pagingInfo) throws Exception {
return this.sqlDao.query(condition, KnowledgeInfosQueryItem.class, "MODIFIED_TIME DESC",pagingInfo); return this.sqlDao.query(condition, KnowledgeInfosQueryItem.class, "CREATED_TIME DESC",pagingInfo);
} }
@Override @Override
......
...@@ -17,6 +17,7 @@ import cn.com.poc.message.service.KnowledgeConsumerService; ...@@ -17,6 +17,7 @@ import cn.com.poc.message.service.KnowledgeConsumerService;
import cn.com.poc.message.service.KnowledgeProducerService; import cn.com.poc.message.service.KnowledgeProducerService;
import cn.com.poc.message.topic.KnowledgeTopic; import cn.com.poc.message.topic.KnowledgeTopic;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService; import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.poc.thirdparty.resource.demand.ai.constants.KnowledgeTrainStatusConstant;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.tumbleweed.client.annotation.Consumer; import cn.com.yict.framemax.tumbleweed.client.annotation.Consumer;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
...@@ -50,66 +51,17 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -50,66 +51,17 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
private BizKnowledgeInfoService bizKnowledgeInfoService; private BizKnowledgeInfoService bizKnowledgeInfoService;
/**
* 训练知识库
*
* @param message
* @return
*/
@Override @Override
@Consumer(topic = KnowledgeTopic.TRAIN_KNOWLEDGE, scale = 3, retry = true) @Consumer(topic = KnowledgeTopic.TRAIN_KNOWLEDGE, scale = 3, retry = true)
public void trainKnowledge(TrainKnowledgeMessage message) throws Exception { public void trainKnowledge(TrainKnowledgeMessage message) throws Exception {
//修改训练状态 //修改训练状态
String knowledgeId = demandKnowledgeService.trainKnowledgeEvent(message.getFileUrl(), message.getSegmentationConfig());
KnowledgeTrainStatusMessage trainStatusMessage = new KnowledgeTrainStatusMessage(); KnowledgeTrainStatusMessage trainStatusMessage = new KnowledgeTrainStatusMessage();
trainStatusMessage.setStatus(KnowledgeConstant.TrainStatus.TRAINING); trainStatusMessage.setStatus(KnowledgeConstant.TrainStatus.TRAINING);
trainStatusMessage.setKdId(message.getKid()); trainStatusMessage.setKdId(message.getKid());
trainStatusMessage.setKnowledgeInfoId(message.getKnowledgeInfoId()); trainStatusMessage.setKnowledgeInfoId(message.getKnowledgeInfoId());
trainStatusMessage.setKnowledgeId(knowledgeId);
knowledgeProducerService.trainStatusUpdate(trainStatusMessage); knowledgeProducerService.trainStatusUpdate(trainStatusMessage);
try {
String knowledgeId = demandKnowledgeService.trainKnowledge(message.getFileUrl(), message.getSegmentationConfig());
//训练日志
BizKnowledgeTrainLogEntity bizKnowledgeTrainLogEntity = new BizKnowledgeTrainLogEntity();
bizKnowledgeTrainLogEntity.setKdId(message.getKid());
bizKnowledgeTrainLogEntity.setTimestamp(System.currentTimeMillis());
bizKnowledgeTrainLogEntity.setTrainStatus(KnowledgeConstant.TrainStatus.COMPLETE);
bizKnowledgeTrainLogEntity.setFailureLog("");
bizKnowledgeTrainLogEntity.setIsDeleted(CommonConstant.IsDeleted.N);
bizKnowledgeTrainLogService.save(bizKnowledgeTrainLogEntity);
//训练完成
KnowledgeTrainStatusMessage completeMessage = new KnowledgeTrainStatusMessage();
completeMessage.setStatus(KnowledgeConstant.TrainStatus.COMPLETE);
completeMessage.setKdId(message.getKid());
completeMessage.setKnowledgeId(knowledgeId);
completeMessage.setKnowledgeInfoId(message.getKnowledgeInfoId());
knowledgeProducerService.trainStatusUpdate(completeMessage);
} catch (BusinessException e) {
logger.warn("--------------message:{},知识库训练失败:{}------------", message, e.getMessage());
//记录状态 训练失败
trainStatusMessage.setStatus(KnowledgeConstant.TrainStatus.FAIL);
trainStatusMessage.setKdId(message.getKid());
knowledgeProducerService.trainStatusUpdate(trainStatusMessage);
logger.warn("-------保存知识库训练失败状态----------");
//训练日志
BizKnowledgeTrainLogEntity bizKnowledgeTrainLogEntity = new BizKnowledgeTrainLogEntity();
bizKnowledgeTrainLogEntity.setKdId(message.getKid());
bizKnowledgeTrainLogEntity.setTimestamp(System.currentTimeMillis());
bizKnowledgeTrainLogEntity.setTrainStatus(KnowledgeConstant.TrainStatus.FAIL);
bizKnowledgeTrainLogEntity.setFailureLog(e.getMessage());
bizKnowledgeTrainLogEntity.setIsDeleted(CommonConstant.IsDeleted.N);
bizKnowledgeTrainLogService.save(bizKnowledgeTrainLogEntity);
logger.warn("-------保存知识库训练失败日志----------");
BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(message.getKnowledgeInfoId());
bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.FAIL);
bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
logger.warn("-------保存知识库训练失败状态----------");
}
} }
...@@ -120,7 +72,6 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -120,7 +72,6 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
bizKnowledgeDocumentEntity.setTrainStatus(message.getStatus()); bizKnowledgeDocumentEntity.setTrainStatus(message.getStatus());
bizKnowledgeDocumentEntity.setKnowledgeId(message.getKnowledgeId()); bizKnowledgeDocumentEntity.setKnowledgeId(message.getKnowledgeId());
bizKnowledgeDocumentService.update(message.getKdId(), bizKnowledgeDocumentEntity); bizKnowledgeDocumentService.update(message.getKdId(), bizKnowledgeDocumentEntity);
knowledgeProducerService.knowledgeInfoStatusCheck(message);
} }
...@@ -141,17 +92,20 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService { ...@@ -141,17 +92,20 @@ public class KnowledgeConsumerServiceImpl implements KnowledgeConsumerService {
logger.info("-------知识库训练状态检查,kdIds:{}-------", kdIds); logger.info("-------知识库训练状态检查,kdIds:{}-------", kdIds);
for (Integer kdId : kdIdList) { for (Integer kdId : kdIdList) {
BizKnowledgeDocumentEntity documentEntity = bizKnowledgeDocumentService.get(kdId); BizKnowledgeDocumentEntity documentEntity = bizKnowledgeDocumentService.get(kdId);
if (KnowledgeConstant.TrainStatus.FAIL.equals(documentEntity.getTrainStatus())) {
bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.FAIL);
bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
}
if (!documentEntity.getTrainStatus().equals(KnowledgeConstant.TrainStatus.COMPLETE)) { if (!documentEntity.getTrainStatus().equals(KnowledgeConstant.TrainStatus.COMPLETE)) {
isAllComplete = false; isAllComplete = false;
break; break;
} }
} }
if (isAllComplete) { if (isAllComplete) {
logger.info("-------知识库训练状态检查,全部完成, knowledgeInfoId:{}-------", knowledgeTrainStatusMessage.getKnowledgeInfoId()); logger.info("-------知识库训练状态检查,全部完成, knowledgeInfoId:{}-------", knowledgeTrainStatusMessage.getKnowledgeInfoId());
bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.COMPLETE); bizKnowledgeInfoEntity.setTrainStatus(KnowledgeConstant.TrainStatus.COMPLETE);
bizKnowledgeInfoService.update(bizKnowledgeInfoEntity); bizKnowledgeInfoService.update(bizKnowledgeInfoEntity);
} }
} }
} }
...@@ -240,7 +240,10 @@ public interface DgtoolsApiConstants { ...@@ -240,7 +240,10 @@ public interface DgtoolsApiConstants {
* 知识库 * 知识库
*/ */
String TRAIN_KNOWLEDGE = "knowLedgeRest/trainKnowLedge.json"; String TRAIN_KNOWLEDGE = "knowLedgeRest/trainKnowLedge.json";
String TRAIN_KNOWLEDGE_EVENT = "knowLedgeRest/trainKnowLedgeEvent.json";
String TRAIN_KNOWLEDGE_STATUS = "/knowLedgeRest/trainKnowLedgeStatus.json";
String DEL_KNOWLEDGE = "knowLedgeRest/delKnowLedge.json"; String DEL_KNOWLEDGE = "knowLedgeRest/delKnowLedge.json";
String SEARCH_KNOWLEDGE = "knowLedgeRest/searchKnowledge.json"; String SEARCH_KNOWLEDGE = "knowLedgeRest/searchKnowledge.json";
......
...@@ -19,6 +19,22 @@ public interface DemandKnowledgeService { ...@@ -19,6 +19,22 @@ public interface DemandKnowledgeService {
*/ */
String trainKnowledge(String fileURL, SegmentationConfigRequest segmentationConfig); String trainKnowledge(String fileURL, SegmentationConfigRequest segmentationConfig);
/**
* 训练知识库-异步
*
* @param fileURL 训练文档
* @return 知识库id
*/
String trainKnowledgeEvent(String fileURL, SegmentationConfigRequest segmentationConfig);
/**
* 获取知识库训练状态
*
* @param knowledgeId
* @return 训练状态
*/
String trainKnowledgeStatus(String knowledgeId);
/** /**
* 删除知识库 * 删除知识库
* *
...@@ -40,9 +56,10 @@ public interface DemandKnowledgeService { ...@@ -40,9 +56,10 @@ public interface DemandKnowledgeService {
* 获取知识库分片 * 获取知识库分片
* *
* @param knowledgeIds 知识库id * @param knowledgeIds 知识库id
* @param query 查询文本
* @param pagingInfo 分页信息 * @param pagingInfo 分页信息
*/ */
GetKnowledgeChunkInfoResult getKnowledgeChunkInfos(List<String> knowledgeIds, PagingInfo pagingInfo); GetKnowledgeChunkInfoResult getKnowledgeChunkInfos(List<String> knowledgeIds, String query, PagingInfo pagingInfo);
/** /**
* 开关知识库分片 * 开关知识库分片
......
...@@ -40,6 +40,31 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService { ...@@ -40,6 +40,31 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService {
return trainKnowledgeResult.getKnowledgeId(); return trainKnowledgeResult.getKnowledgeId();
} }
@Override
public String trainKnowledgeEvent(String fileURL, SegmentationConfigRequest segmentationConfig) {
Assert.notBlank(fileURL);
TrainKnowledgeRequest request = new TrainKnowledgeRequest();
request.setDocumentUrl(fileURL);
request.setSegmentationConfig(segmentationConfig);
TrainKnowledgeResult trainKnowledgeResult = dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.TRAIN_KNOWLEDGE_EVENT, request, getHeaders());
if (null == trainKnowledgeResult) {
throw new BusinessException("train knowledge error");
}
return trainKnowledgeResult.getKnowledgeId();
}
@Override
public String trainKnowledgeStatus(String knowledgeId) {
Assert.notBlank(knowledgeId);
TrainKnowledgeStatusRequest request = new TrainKnowledgeStatusRequest();
request.setKnowledgeId(knowledgeId);
TrainKnowledgeStatusResult trainKnowledgeStatusResult = dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.TRAIN_KNOWLEDGE_STATUS, request, getHeaders());
if (null == trainKnowledgeStatusResult) {
throw new BusinessException("get knowledge train status error");
}
return trainKnowledgeStatusResult.getTrainStatus();
}
@Override @Override
public void delKnowledge(String knowledgeId) { public void delKnowledge(String knowledgeId) {
Assert.notBlank(knowledgeId); Assert.notBlank(knowledgeId);
...@@ -72,9 +97,10 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService { ...@@ -72,9 +97,10 @@ public class DemandKnowledgeServiceImpl implements DemandKnowledgeService {
} }
@Override @Override
public GetKnowledgeChunkInfoResult getKnowledgeChunkInfos(List<String> knowledgeIds, PagingInfo pagingInfo) { public GetKnowledgeChunkInfoResult getKnowledgeChunkInfos(List<String> knowledgeIds, String query, PagingInfo pagingInfo) {
GetKnowledgeChunkInfoRequest request = new GetKnowledgeChunkInfoRequest(); GetKnowledgeChunkInfoRequest request = new GetKnowledgeChunkInfoRequest();
request.setKnowledgeIds(knowledgeIds); request.setKnowledgeIds(knowledgeIds);
request.setQuery(query);
return dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.GET_KNOWLEDGE_CHUNK_INFOS, request, getHeaders(), pagingInfo); return dgToolsAbstractHttpClient.doRequest(DgtoolsApiConstants.DgtoolsAI.GET_KNOWLEDGE_CHUNK_INFOS, request, getHeaders(), pagingInfo);
} }
......
...@@ -12,19 +12,28 @@ import java.util.List; ...@@ -12,19 +12,28 @@ import java.util.List;
public class Message { public class Message {
private List<MultiContent> content; // private List<MultiContent> content;
private Object content;
private String role; private String role;
private List<FunctionCall> function_call; private List<FunctionCall> function_call;
private String name; private String name;
public List<MultiContent> getContent() { // public List<MultiContent> getContent() {
// return content;
// }
//
// public void setContent(List<MultiContent> content) {
// this.content = content;
// }
public Object getContent() {
return content; return content;
} }
public void setContent(List<MultiContent> content) { public void setContent(Object content) {
this.content = content; this.content = content;
} }
......
package cn.com.poc.thirdparty.resource.demand.ai.constants;
public interface KnowledgeTrainStatusConstant {
String unTrain = "unTrain";
String line = "line";
String train = "train";
String fail = "fail";
String success = "success";
}
...@@ -9,6 +9,8 @@ public class GetKnowledgeChunkInfoRequest extends AbstractRequest<GetKnowledgeCh ...@@ -9,6 +9,8 @@ public class GetKnowledgeChunkInfoRequest extends AbstractRequest<GetKnowledgeCh
private List<String> knowledgeIds; private List<String> knowledgeIds;
private String query;
public List<String> getKnowledgeIds() { public List<String> getKnowledgeIds() {
return knowledgeIds; return knowledgeIds;
} }
...@@ -17,6 +19,14 @@ public class GetKnowledgeChunkInfoRequest extends AbstractRequest<GetKnowledgeCh ...@@ -17,6 +19,14 @@ public class GetKnowledgeChunkInfoRequest extends AbstractRequest<GetKnowledgeCh
this.knowledgeIds = knowledgeIds; this.knowledgeIds = knowledgeIds;
} }
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
@Override @Override
public String getMethod() throws Exception { public String getMethod() throws Exception {
return null; return null;
......
...@@ -9,8 +9,17 @@ public class GetKnowledgeChunkInfoResult extends AbstractResult implements Seria ...@@ -9,8 +9,17 @@ public class GetKnowledgeChunkInfoResult extends AbstractResult implements Seria
private static final long serialVersionUID = 11243413567468L; private static final long serialVersionUID = 11243413567468L;
private Integer totalChunk;
private List<ChunkInfo> chunkInfos; private List<ChunkInfo> chunkInfos;
public Integer getTotalChunk() {
return totalChunk;
}
public void setTotalChunk(Integer totalChunk) {
this.totalChunk = totalChunk;
}
public List<ChunkInfo> getChunkInfos() { public List<ChunkInfo> getChunkInfos() {
return chunkInfos; return chunkInfos;
...@@ -22,8 +31,9 @@ public class GetKnowledgeChunkInfoResult extends AbstractResult implements Seria ...@@ -22,8 +31,9 @@ public class GetKnowledgeChunkInfoResult extends AbstractResult implements Seria
@Override @Override
public String toString() { public String toString() {
return "{" + return "GetKnowledgeChunkInfoResult{" +
"chunkInfos:" + chunkInfos + "totalChunk=" + totalChunk +
", chunkInfos=" + chunkInfos +
'}'; '}';
} }
} }
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
import cn.com.poc.support.dgTools.request.AbstractRequest;
import java.io.Serializable;
public class TrainKnowledgeStatusRequest extends AbstractRequest<TrainKnowledgeStatusResult> implements Serializable {
private String knowledgeId;
public String getKnowledgeId() {
return knowledgeId;
}
public void setKnowledgeId(String knowledgeId) {
this.knowledgeId = knowledgeId;
}
@Override
public String getMethod() throws Exception {
return null;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.entity.knowledge;
import cn.com.poc.support.dgTools.result.AbstractResult;
import java.io.Serializable;
public class TrainKnowledgeStatusResult extends AbstractResult implements Serializable {
private String trainStatus;
public String getTrainStatus() {
return trainStatus;
}
public void setTrainStatus(String trainStatus) {
this.trainStatus = trainStatus;
}
}
package cn.com.poc.user.convert; package cn.com.poc.user.convert;
import cn.com.poc.user.dto.MemberInfoDto;
import cn.com.poc.user.entity.MemberInfoEntity; import cn.com.poc.user.entity.MemberInfoEntity;
import cn.com.poc.user.model.BizMemberInfoModel; import cn.com.poc.user.model.BizMemberInfoModel;
...@@ -43,4 +44,39 @@ public class MemberInfoConvert { ...@@ -43,4 +44,39 @@ public class MemberInfoConvert {
return memberInfoEntity; return memberInfoEntity;
} }
public static MemberInfoDto converEntity2Dto(MemberInfoEntity memberInfoEntity) {
if (memberInfoEntity == null) {
return null;
}
MemberInfoDto memberInfoDto = new MemberInfoDto();
memberInfoDto.setMemberId(memberInfoEntity.getMemberId());
memberInfoDto.setAccount(memberInfoEntity.getAccount());
memberInfoDto.setNickName(memberInfoEntity.getNickName());
memberInfoDto.setAvatarUrl(memberInfoEntity.getAvatarUrl());
memberInfoDto.setMobilePhone(memberInfoEntity.getMobilePhone());
memberInfoDto.setEmail(memberInfoEntity.getEmail());
memberInfoDto.setRemark(memberInfoEntity.getRemark());
memberInfoDto.setLastLoginTime(memberInfoEntity.getLastLoginTime());
memberInfoDto.setShareCode(memberInfoEntity.getShareCode());
memberInfoDto.setModelState(memberInfoEntity.getModelState());
return memberInfoDto;
}
public static MemberInfoEntity convertDto2Entity(MemberInfoDto memberInfoDto) {
if (memberInfoDto == null) {
return null;
}
MemberInfoEntity memberInfoEntity = new MemberInfoEntity();
memberInfoEntity.setMemberId(memberInfoDto.getMemberId());
memberInfoEntity.setAccount(memberInfoDto.getAccount());
memberInfoEntity.setNickName(memberInfoDto.getNickName());
memberInfoEntity.setAvatarUrl(memberInfoDto.getAvatarUrl());
memberInfoEntity.setMobilePhone(memberInfoDto.getMobilePhone());
memberInfoEntity.setEmail(memberInfoDto.getEmail());
memberInfoEntity.setRemark(memberInfoDto.getRemark());
memberInfoEntity.setLastLoginTime(memberInfoDto.getLastLoginTime());
memberInfoEntity.setShareCode(memberInfoDto.getShareCode());
memberInfoEntity.setModelState(memberInfoDto.getModelState());
return memberInfoEntity;
}
} }
\ No newline at end of file
package cn.com.poc.user.dto;
import cn.com.yict.framemax.data.model.BaseModelClass;
import java.util.Date;
/**
* @Author:Roger Wu
* @Date:2024-07-25 11:06
*/
public class MemberInfoDto extends BaseModelClass {
/**
* member_id
* 会员id
*/
private Integer memberId;
public Integer getMemberId() {
return this.memberId;
}
public void setMemberId(Integer memberId) {
this.memberId = memberId;
}
/**
* account
* 账号
*/
private String account;
public String getAccount() {
return this.account;
}
public void setAccount(String account) {
this.account = account;
}
/**
* nick_name
* 用户昵称
*/
private String nickName;
public String getNickName() {
return this.nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
/**
* avatar_url
* 用户头像图片的 URL
*/
private String avatarUrl;
public String getAvatarUrl() {
return this.avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
/**
* mobile_phone
* 用户手机号
*/
private String mobilePhone;
public String getMobilePhone() {
return this.mobilePhone;
}
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}
/**
* email
* 用户邮箱
*/
private String email;
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
/**
* remark
* 备注
*/
private String remark;
public String getRemark() {
return this.remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
/** last_login_time
*用户账号
*/
private Date lastLoginTime;
public Date getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
private String shareCode;
public String getShareCode() {
return shareCode;
}
public void setShareCode(String shareCode) {
this.shareCode = shareCode;
}
}
package cn.com.poc.user.rest; package cn.com.poc.user.rest;
import cn.com.poc.user.dto.MemberInfoDto;
import cn.com.poc.user.dto.MemberLoginRequestDto; import cn.com.poc.user.dto.MemberLoginRequestDto;
import cn.com.poc.user.dto.MemberLoginResponseDto; import cn.com.poc.user.dto.MemberLoginResponseDto;
import cn.com.poc.user.dto.MemberPasswordRequestDto; import cn.com.poc.user.dto.MemberPasswordRequestDto;
...@@ -33,4 +34,11 @@ public interface BizMemberInfoRest extends BaseRest { ...@@ -33,4 +34,11 @@ public interface BizMemberInfoRest extends BaseRest {
*/ */
@Permission(Access.Anonymous) @Permission(Access.Anonymous)
void forgetMemberPassword(@RequestBody MemberPasswordRequestDto memberPasswordRequestDto) throws Exception; void forgetMemberPassword(@RequestBody MemberPasswordRequestDto memberPasswordRequestDto) throws Exception;
/**
* 获取用户信息
*
* @return
*/
MemberInfoDto getCurrentMemberInfo() throws Exception;
} }
\ No newline at end of file
...@@ -3,13 +3,17 @@ package cn.com.poc.user.rest.impl; ...@@ -3,13 +3,17 @@ package cn.com.poc.user.rest.impl;
import javax.annotation.Resource; import javax.annotation.Resource;
import cn.com.poc.common.utils.Assert; import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.support.security.oauth.constants.OauthConstants; import cn.com.poc.support.security.oauth.constants.OauthConstants;
import cn.com.poc.user.convert.MemberInfoConvert;
import cn.com.poc.user.dto.MemberInfoDto;
import cn.com.poc.user.dto.MemberLoginRequestDto; import cn.com.poc.user.dto.MemberLoginRequestDto;
import cn.com.poc.user.dto.MemberLoginResponseDto; import cn.com.poc.user.dto.MemberLoginResponseDto;
import cn.com.poc.user.dto.MemberPasswordRequestDto; import cn.com.poc.user.dto.MemberPasswordRequestDto;
import cn.com.poc.user.aggregation.MemberInfoService; import cn.com.poc.user.aggregation.MemberInfoService;
import cn.com.poc.user.builder.LoginChannelBuilder; import cn.com.poc.user.builder.LoginChannelBuilder;
import cn.com.poc.user.entity.MemberInfoEntity; import cn.com.poc.user.entity.MemberInfoEntity;
import cn.com.poc.user.service.BizMemberInfoService;
import cn.com.yict.framemax.security.oauth.OauthAccesstokenManager; import cn.com.yict.framemax.security.oauth.OauthAccesstokenManager;
import cn.com.yict.framemax.security.oauth.entity.OauthResultEntity; import cn.com.yict.framemax.security.oauth.entity.OauthResultEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -27,6 +31,9 @@ public class BizMemberInfoRestImpl implements BizMemberInfoRest { ...@@ -27,6 +31,9 @@ public class BizMemberInfoRestImpl implements BizMemberInfoRest {
@Resource @Resource
private MemberInfoService memberInfoService; private MemberInfoService memberInfoService;
@Resource
private BizMemberInfoService bizMemberInfoService;
/** /**
* 用户登录 * 用户登录
...@@ -93,4 +100,15 @@ public class BizMemberInfoRestImpl implements BizMemberInfoRest { ...@@ -93,4 +100,15 @@ public class BizMemberInfoRestImpl implements BizMemberInfoRest {
memberInfoService.configureMemberPassword(memberPasswordRequestDto); memberInfoService.configureMemberPassword(memberPasswordRequestDto);
} }
/**
* 获取用户信息
*
* @return
*/
@Override
public MemberInfoDto getCurrentMemberInfo() throws Exception {
MemberInfoEntity memberInfoEntity = bizMemberInfoService.getById(BlContext.getCurrentUser().getUserId().intValue());
return MemberInfoConvert.converEntity2Dto(memberInfoEntity);
}
} }
\ No newline at end of file
...@@ -2,6 +2,8 @@ package cn.com.poc; ...@@ -2,6 +2,8 @@ package cn.com.poc;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.expose.aggregate.AgentApplicationService;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService; import cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService;
import cn.com.yict.framemax.core.spring.SingleContextInitializer; import cn.com.yict.framemax.core.spring.SingleContextInitializer;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -30,6 +32,9 @@ public class AgentApplicationInfoTest { ...@@ -30,6 +32,9 @@ public class AgentApplicationInfoTest {
@Resource @Resource
private DemandKnowledgeService demandKnowledgeService; private DemandKnowledgeService demandKnowledgeService;
@Resource
private RedisService redisService;
/** /**
* Agent 应用标题,描述生成 * Agent 应用标题,描述生成
*/ */
...@@ -46,4 +51,19 @@ public class AgentApplicationInfoTest { ...@@ -46,4 +51,19 @@ public class AgentApplicationInfoTest {
System.out.println(list.toString()); System.out.println(list.toString());
} }
@Test
public void test() {
List<Object> list = Lists.newArrayList("1", "2", "3", "4", "5", "6", "7", "8", "9", "1");
redisService.lSet("key",list);
}
@Resource
private AgentApplicationService agentApplicationService;
@Test
public void test2() throws InterruptedException {
agentApplicationService.createRecommendQuestion();
}
} }
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