Commit 64db3129 authored by alex yao's avatar alex yao

feat:agent 应用积分统计区分模型与插件

parent 0b33fb3c
...@@ -21,6 +21,7 @@ import cn.com.poc.equity.constants.RuleType; ...@@ -21,6 +21,7 @@ import cn.com.poc.equity.constants.RuleType;
import cn.com.poc.equity.domain.MemberEquityInfo; import cn.com.poc.equity.domain.MemberEquityInfo;
import cn.com.poc.equity.domain.modifyEquityInfo.AgentUseModifyEventInfo; import cn.com.poc.equity.domain.modifyEquityInfo.AgentUseModifyEventInfo;
import cn.com.poc.equity.entity.BizPointDeductionRulesEntity; import cn.com.poc.equity.entity.BizPointDeductionRulesEntity;
import cn.com.poc.equity.entity.PointDeductionEntity;
import cn.com.poc.equity.service.BizPointDeductionRulesService; import cn.com.poc.equity.service.BizPointDeductionRulesService;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
...@@ -270,11 +271,14 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -270,11 +271,14 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
// 判断是否调用function // 判断是否调用function
//计算扣分数 //计算扣分数
CheckPluginUseEntity checkPluginUseEntity = AgentApplicationTools.checkPluginUse(dto.getMessages(), tools, fileUrls, imageUrls); CheckPluginUseEntity checkPluginUseEntity = AgentApplicationTools.checkPluginUse(dto.getMessages(), tools, fileUrls, imageUrls);
Long pointDeductionNum = pointDeductionRulesService.calculatePointDeductionNum(model, communicationTurn, checkPluginUseEntity.getDeductionTools()); PointDeductionEntity pointDeductionEntity = pointDeductionRulesService.calculatePointDeductionNum(model, communicationTurn, checkPluginUseEntity.getDeductionTools());
long pointDeductionNum = pointDeductionEntity.getModelPoint() + pointDeductionEntity.getPluginPoint();
AgentUseModifyEventInfo agentUseModifyEventInfo = new AgentUseModifyEventInfo(); AgentUseModifyEventInfo agentUseModifyEventInfo = new AgentUseModifyEventInfo();
agentUseModifyEventInfo.setAgentId(agentId); agentUseModifyEventInfo.setAgentId(agentId);
agentUseModifyEventInfo.setIsPublish(CommonConstant.IsDeleted.N); agentUseModifyEventInfo.setIsPublish(CommonConstant.IsDeleted.N);
reduceSn = memberEquityService.reducePoint(userBaseEntity.getUserId(), pointDeductionNum, ModifyEventEnum.use, agentUseModifyEventInfo); reduceSn = memberEquityService.reducePoint(userBaseEntity.getUserId(), pointDeductionNum, ModifyEventEnum.use, agentUseModifyEventInfo);
//调用应用服务 //调用应用服务
agentApplicationService.callAgentApplication(agentId, dialogueId, model, agentApplicationService.callAgentApplication(agentId, dialogueId, model,
agentSystem, kdIds.toArray(new Integer[0]), communicationTurn, topP, agentSystem, kdIds.toArray(new Integer[0]), communicationTurn, topP,
...@@ -285,7 +289,8 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -285,7 +289,8 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
if (StringUtils.isBlank(dto.getChannel())) { if (StringUtils.isBlank(dto.getChannel())) {
dto.setChannel(DataAnalyzeChannelEnum.preview.getChannel()); dto.setChannel(DataAnalyzeChannelEnum.preview.getChannel());
} }
dataAnalyzeReportService.dataReport(dto.getAgentId(), DataAnalyzeChannelEnum.valueOf(dto.getChannel()), userBaseEntity.getUserId(), userBaseEntity.getUserId(), pointDeductionNum); // dataAnalyzeReportService.dataReport(dto.getAgentId(), DataAnalyzeChannelEnum.valueOf(dto.getChannel()), userBaseEntity.getUserId(), userBaseEntity.getUserId(), pointDeductionNum);
dataAnalyzeReportService.dataReport(dto.getAgentId(), DataAnalyzeChannelEnum.valueOf(dto.getChannel()), userBaseEntity.getUserId(), userBaseEntity.getUserId(), pointDeductionEntity);
} catch (Exception e) { } catch (Exception e) {
httpServletResponse.setContentType("text/event-stream"); httpServletResponse.setContentType("text/event-stream");
PrintWriter writer = httpServletResponse.getWriter(); PrintWriter writer = httpServletResponse.getWriter();
......
...@@ -2,6 +2,7 @@ package cn.com.poc.data_analyze.aggregate; ...@@ -2,6 +2,7 @@ package cn.com.poc.data_analyze.aggregate;
import cn.com.poc.data_analyze.constants.DataAnalyzeChannelEnum; import cn.com.poc.data_analyze.constants.DataAnalyzeChannelEnum;
import cn.com.poc.data_analyze.constants.DataAnalyzeTypeEnum; import cn.com.poc.data_analyze.constants.DataAnalyzeTypeEnum;
import cn.com.poc.equity.entity.PointDeductionEntity;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -45,4 +46,16 @@ public interface DataAnalyzeReportService { ...@@ -45,4 +46,16 @@ public interface DataAnalyzeReportService {
* @param pointDeductionNum 积分扣除数量-单位分 * @param pointDeductionNum 积分扣除数量-单位分
*/ */
boolean dataReport(String agentId, DataAnalyzeChannelEnum channel, Long userId, Long deducted, Long pointDeductionNum); boolean dataReport(String agentId, DataAnalyzeChannelEnum channel, Long userId, Long deducted, Long pointDeductionNum);
/**
* 数据上报-聚合上报【对话次数+积分使用情况】
*
* @param agentId 应用ID
* @param channel 渠道
* @param userId 使用者
* @param deducted 积分扣减者
* @param pointDeductionEntity 积分扣除实体
* @return
*/
boolean dataReport(String agentId, DataAnalyzeChannelEnum channel, Long userId, Long deducted, PointDeductionEntity pointDeductionEntity);
} }
...@@ -7,6 +7,7 @@ import cn.com.poc.data_analyze.constants.DataAnalyzeTypeEnum; ...@@ -7,6 +7,7 @@ import cn.com.poc.data_analyze.constants.DataAnalyzeTypeEnum;
import cn.com.poc.data_analyze.entity.*; import cn.com.poc.data_analyze.entity.*;
import cn.com.poc.data_analyze.service.BizDataAnalyzeDialogueRecordService; import cn.com.poc.data_analyze.service.BizDataAnalyzeDialogueRecordService;
import cn.com.poc.data_analyze.service.BizDataAnalyzePointRecordService; import cn.com.poc.data_analyze.service.BizDataAnalyzePointRecordService;
import cn.com.poc.equity.entity.PointDeductionEntity;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -70,4 +71,15 @@ public class DataAnalyzeReportServiceImpl implements DataAnalyzeReportService { ...@@ -70,4 +71,15 @@ public class DataAnalyzeReportServiceImpl implements DataAnalyzeReportService {
this.dataReportByPoint(deducted, points, DataAnalyzeTypeEnum.AGENT, agentId, channel); this.dataReportByPoint(deducted, points, DataAnalyzeTypeEnum.AGENT, agentId, channel);
return true; return true;
} }
@Override
public boolean dataReport(String agentId, DataAnalyzeChannelEnum channel, Long userId, Long deducted, PointDeductionEntity pointDeductionEntity) {
long pointDeductionNum = pointDeductionEntity.getModelPoint() + pointDeductionEntity.getPluginPoint();
BigDecimal modelPoint = new BigDecimal(pointDeductionEntity.getModelPoint()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
BigDecimal pluginPoints = new BigDecimal(pointDeductionEntity.getPluginPoint()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
this.dataReportByDialogue(userId, DataAnalyzeTypeEnum.AGENT, agentId, userId.equals(deducted) ? pointDeductionNum : 0, channel);
this.dataReportByPoint(deducted, modelPoint, DataAnalyzeTypeEnum.AGENT, agentId, channel);
this.dataReportByPoint(deducted, pluginPoints, DataAnalyzeTypeEnum.PLUGIN, agentId, channel);
return true;
}
} }
...@@ -8,6 +8,8 @@ public enum DataAnalyzeTypeEnum { ...@@ -8,6 +8,8 @@ public enum DataAnalyzeTypeEnum {
AGENT("agent"), AGENT("agent"),
PLUGIN("plugin"),
; ;
private String type; private String type;
......
select * SELECT bmi.nick_name AS owner,
from (select bmi.nick_name as owner, COUNT(bdapr.relation_id) AS usage_count,
baai.agent_title, CASE WHEN baai.agent_publish_status = 'publish' THEN baap.agent_title
count(bdadr.relation_id) as usage_count, ELSE baai.agent_title END AS agent_title,
ifnull(sum(bdadr.point_num), 0) as total_points, MAX(bdapr.`datetime`) AS last_usage_time,
max(bdadr.datetime) as last_usage_time, SUM(bdapr.point_num) AS total_points,
(case when baai.agent_publish_status = "publish" then "Y" else "N" end) as publish_status SUM(CASE WHEN bdapr.type = 'agent' THEN bdapr.point_num ELSE 0 END) AS agent_points,
from biz_data_analyze_dialogue_record bdadr SUM(CASE WHEN bdapr.type = 'plugin' THEN bdapr.point_num ELSE 0 END) AS plugin_points,
left join biz_agent_application_info baai on baai.agent_id = bdadr.relation_id CASE WHEN baai.agent_publish_status = "publish" THEN "Y" ELSE "N" END AS publish_status
left join biz_member_info bmi on bmi.member_id = baai.member_id FROM biz_data_analyze_point_record bdapr
where 1=1 LEFT JOIN biz_agent_application_info baai ON baai.agent_id = bdapr.relation_id
<< and bdadr.member_id = :memberId>> LEFT JOIN biz_agent_application_publish baap ON baap.agent_id = bdapr.relation_id
group by bdadr.relation_id, bdadr.member_id) as t1 LEFT JOIN biz_member_info bmi ON bmi.member_id = baai.member_id
where 1 = 1 << and t1.last_usage_time >= :startDate and t1.last_usage_time <= :endDate >> WHERE 1 = 1
order by t1.last_usage_time desc AND bdapr.relation_id IN (SELECT DISTINCT bdadr.relation_id FROM biz_data_analyze_dialogue_record bdadr WHERE bdadr.member_id = bdapr.member_id)
\ No newline at end of file << AND bdapr.member_id = :memberId >>
<< AND bdapr.`datetime` >= :startDate AND bdapr.`datetime` <= :endDate>>
GROUP BY
bdapr.relation_id,
bdapr.member_id
ORDER BY last_usage_time DESC
\ No newline at end of file
...@@ -3,97 +3,132 @@ package cn.com.poc.data_analyze.query; ...@@ -3,97 +3,132 @@ package cn.com.poc.data_analyze.query;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import cn.com.yict.framemax.data.model.BaseItemClass; import cn.com.yict.framemax.data.model.BaseItemClass;
/** /**
* Query Item class for MemberAgentUsageDetailsQuery * Query Item class for MemberAgentUsageDetailsQuery
*/ */
@Entity @Entity
public class MemberAgentUsageDetailsQueryItem extends BaseItemClass implements Serializable{ public class MemberAgentUsageDetailsQueryItem extends BaseItemClass implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** owner /**
*owner * owner
* owner
*/ */
private java.lang.String owner; private java.lang.String owner;
@Column(name = "owner") @Column(name = "owner")
public java.lang.String getOwner(){ public java.lang.String getOwner() {
return this.owner; return this.owner;
} }
public void setOwner(java.lang.String owner){ public void setOwner(java.lang.String owner) {
this.owner = owner; this.owner = owner;
} }
/** agent_title /**
*agent_title * agent_title
* agent_title
*/ */
private java.lang.String agentTitle; private java.lang.String agentTitle;
@Column(name = "agent_title") @Column(name = "agent_title")
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;
} }
/** usage_count /**
*usage_count * usage_count
* usage_count
*/ */
private java.lang.Long usageCount; private java.lang.Long usageCount;
@Column(name = "usage_count") @Column(name = "usage_count")
public java.lang.Long getUsageCount(){ public java.lang.Long getUsageCount() {
return this.usageCount; return this.usageCount;
} }
public void setUsageCount(java.lang.Long usageCount){ public void setUsageCount(java.lang.Long usageCount) {
this.usageCount = usageCount; this.usageCount = usageCount;
} }
/** total_points /**
*total_points * total_points
* total_points
*/ */
private java.lang.Double totalPoints; private java.lang.Double totalPoints;
@Column(name = "total_points") @Column(name = "total_points")
public java.lang.Double getTotalPoints(){ public java.lang.Double getTotalPoints() {
return this.totalPoints; return this.totalPoints;
} }
public void setTotalPoints(java.lang.Double totalPoints){ public void setTotalPoints(java.lang.Double totalPoints) {
this.totalPoints = totalPoints; this.totalPoints = totalPoints;
} }
/** last_usage_time /**
*last_usage_time * last_usage_time
* last_usage_time
*/ */
private java.util.Date lastUsageTime; private java.util.Date lastUsageTime;
@Column(name = "last_usage_time") @Column(name = "last_usage_time")
public java.util.Date getLastUsageTime(){ public java.util.Date getLastUsageTime() {
return this.lastUsageTime; return this.lastUsageTime;
} }
public void setLastUsageTime(java.util.Date lastUsageTime){ public void setLastUsageTime(java.util.Date lastUsageTime) {
this.lastUsageTime = lastUsageTime; this.lastUsageTime = lastUsageTime;
} }
/** publish_status /**
*publish_status * agent_points
*/
private Double agentPoints;
@Column(name = "agent_points")
public Double getAgentPoints() {
return agentPoints;
}
public void setAgentPoints(Double agentPoints) {
this.agentPoints = agentPoints;
}
/**
* plugin_points
*/
private Double pluginPoints;
@Column(name = "plugin_points")
public Double getPluginPoints() {
return pluginPoints;
}
public void setPluginPoints(Double pluginPoints) {
this.pluginPoints = pluginPoints;
}
/**
* publish_status
* publish_status
*/ */
private java.lang.String publishStatus; private java.lang.String publishStatus;
@Column(name = "publish_status") @Column(name = "publish_status")
public java.lang.String getPublishStatus(){ public java.lang.String getPublishStatus() {
return this.publishStatus; return this.publishStatus;
} }
public void setPublishStatus(java.lang.String publishStatus){ public void setPublishStatus(java.lang.String publishStatus) {
this.publishStatus = publishStatus; this.publishStatus = publishStatus;
} }
......
package cn.com.poc.equity.aggregate; package cn.com.poc.equity.aggregate;
import cn.com.poc.equity.entity.PointDeductionEntity;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool;
import java.util.List; import java.util.List;
...@@ -15,6 +16,6 @@ public interface PointDeductionRulesService { ...@@ -15,6 +16,6 @@ public interface PointDeductionRulesService {
/** /**
* 积分扣减数计算 -单位: 分 * 积分扣减数计算 -单位: 分
*/ */
Long calculatePointDeductionNum(String modelName, Integer communicationTurn, List<Tool> tools); PointDeductionEntity calculatePointDeductionNum(String modelName, Integer communicationTurn, List<Tool> tools);
} }
...@@ -5,6 +5,7 @@ import cn.com.poc.common.utils.StringUtils; ...@@ -5,6 +5,7 @@ import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.equity.aggregate.PointDeductionRulesService; import cn.com.poc.equity.aggregate.PointDeductionRulesService;
import cn.com.poc.equity.constants.RuleType; import cn.com.poc.equity.constants.RuleType;
import cn.com.poc.equity.entity.BizPointDeductionRulesEntity; import cn.com.poc.equity.entity.BizPointDeductionRulesEntity;
import cn.com.poc.equity.entity.PointDeductionEntity;
import cn.com.poc.equity.service.BizPointDeductionRulesService; import cn.com.poc.equity.service.BizPointDeductionRulesService;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -25,8 +26,54 @@ public class PointDeductionRulesServiceImpl implements PointDeductionRulesServic ...@@ -25,8 +26,54 @@ public class PointDeductionRulesServiceImpl implements PointDeductionRulesServic
@Resource @Resource
private BizPointDeductionRulesService bizPointDeductionRulesService; private BizPointDeductionRulesService bizPointDeductionRulesService;
// @Override
// public Long calculatePointDeductionNum(String modelName, Integer communicationTurn, List<Tool> tools) {
// Long pointDeductionNum = 0L;
// BizPointDeductionRulesEntity bizPointDeductionRulesEntity = new BizPointDeductionRulesEntity();
// bizPointDeductionRulesEntity.setIsDeleted(CommonConstant.IsDeleted.N);
// List<BizPointDeductionRulesEntity> entities = bizPointDeductionRulesService.findByExample(bizPointDeductionRulesEntity, null);
// Map<String, List<BizPointDeductionRulesEntity>> map = entities.stream().collect(Collectors.groupingBy(BizPointDeductionRulesEntity::getRuleType, Collectors.toList()));
// // 模型扣分
// if (StringUtils.isNotBlank(modelName) && map.containsKey(RuleType.MODEL.getRuleType())) {
// List<BizPointDeductionRulesEntity> modelDeductionRules = map.get(RuleType.MODEL.getRuleType());
// for (BizPointDeductionRulesEntity modelDeductionRule : modelDeductionRules) {
// if (modelDeductionRule.getRelationId().equals(modelName)) {
// pointDeductionNum = pointDeductionNum + modelDeductionRule.getNumber();
// break;
// }
// }
// }
// //轮次 1-5-10-15 1轮和5轮扣模型原始的积分 10轮 原始积分*2 15轮 原始积分*3
// if (communicationTurn != null && map.containsKey(RuleType.COMMUNICATION_TURN.getRuleType())) {
// List<BizPointDeductionRulesEntity> communicationTurnRules = map.get(RuleType.COMMUNICATION_TURN.getRuleType());
// for (BizPointDeductionRulesEntity communicationTurnRule : communicationTurnRules) {
// if (communicationTurnRule.getRelationId().equals(String.valueOf(communicationTurn))) {
// pointDeductionNum = pointDeductionNum * communicationTurnRule.getNumber();
// break;
// }
// }
// }
// // 插件扣分
// if (CollectionUtils.isNotEmpty(tools) && map.containsKey(RuleType.PLUGIN.getRuleType())) {
// List<BizPointDeductionRulesEntity> pluginRules = map.get(RuleType.PLUGIN.getRuleType());
// for (Tool tool : tools) {
// for (BizPointDeductionRulesEntity pluginRule : pluginRules) {
// if (pluginRule.getRelationId().equals(tool.getFunction().getName())) {
// pointDeductionNum = pointDeductionNum + pluginRule.getNumber();
// break;
// }
// }
// }
// }
// return pointDeductionNum;
// }
@Override @Override
public Long calculatePointDeductionNum(String modelName, Integer communicationTurn, List<Tool> tools) { public PointDeductionEntity calculatePointDeductionNum(String modelName, Integer communicationTurn, List<Tool> tools) {
PointDeductionEntity pointDeductionEntity = new PointDeductionEntity();
pointDeductionEntity.setModelPoint(0L);
pointDeductionEntity.setPluginPoint(0L);
Long pointDeductionNum = 0L; Long pointDeductionNum = 0L;
BizPointDeductionRulesEntity bizPointDeductionRulesEntity = new BizPointDeductionRulesEntity(); BizPointDeductionRulesEntity bizPointDeductionRulesEntity = new BizPointDeductionRulesEntity();
bizPointDeductionRulesEntity.setIsDeleted(CommonConstant.IsDeleted.N); bizPointDeductionRulesEntity.setIsDeleted(CommonConstant.IsDeleted.N);
...@@ -52,18 +99,21 @@ public class PointDeductionRulesServiceImpl implements PointDeductionRulesServic ...@@ -52,18 +99,21 @@ public class PointDeductionRulesServiceImpl implements PointDeductionRulesServic
} }
} }
} }
pointDeductionEntity.setModelPoint(pointDeductionNum);
// 插件扣分 // 插件扣分
if (CollectionUtils.isNotEmpty(tools) && map.containsKey(RuleType.PLUGIN.getRuleType())) { if (CollectionUtils.isNotEmpty(tools) && map.containsKey(RuleType.PLUGIN.getRuleType())) {
List<BizPointDeductionRulesEntity> pluginRules = map.get(RuleType.PLUGIN.getRuleType()); List<BizPointDeductionRulesEntity> pluginRules = map.get(RuleType.PLUGIN.getRuleType());
for (Tool tool : tools) { for (Tool tool : tools) {
for (BizPointDeductionRulesEntity pluginRule : pluginRules) { for (BizPointDeductionRulesEntity pluginRule : pluginRules) {
if (pluginRule.getRelationId().equals(tool.getFunction().getName())) { if (pluginRule.getRelationId().equals(tool.getFunction().getName())) {
pointDeductionNum = pointDeductionNum + pluginRule.getNumber(); pointDeductionEntity.setPluginPoint(pluginRule.getNumber());
break; break;
} }
} }
} }
} }
return pointDeductionNum; return pointDeductionEntity;
} }
} }
package cn.com.poc.equity.entity;
/**
* @author alex.yao
* @date 2025/3/11
*/
public class PointDeductionEntity {
/**
* 模型积分
*/
private Long modelPoint;
/**
* 插件积分
*/
private Long pluginPoint;
public Long getModelPoint() {
return modelPoint;
}
public void setModelPoint(Long modelPoint) {
this.modelPoint = modelPoint;
}
public Long getPluginPoint() {
return pluginPoint;
}
public void setPluginPoint(Long pluginPoint) {
this.pluginPoint = pluginPoint;
}
}
...@@ -15,6 +15,7 @@ import cn.com.poc.equity.aggregate.MemberEquityService; ...@@ -15,6 +15,7 @@ import cn.com.poc.equity.aggregate.MemberEquityService;
import cn.com.poc.equity.aggregate.PointDeductionRulesService; import cn.com.poc.equity.aggregate.PointDeductionRulesService;
import cn.com.poc.equity.constants.ModifyEventEnum; import cn.com.poc.equity.constants.ModifyEventEnum;
import cn.com.poc.equity.domain.modifyEquityInfo.AgentUseModifyEventInfo; import cn.com.poc.equity.domain.modifyEquityInfo.AgentUseModifyEventInfo;
import cn.com.poc.equity.entity.PointDeductionEntity;
import cn.com.poc.expose.aggregate.AgentApplicationApiService; import cn.com.poc.expose.aggregate.AgentApplicationApiService;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.support.security.oauth.constants.OauthConstants; import cn.com.poc.support.security.oauth.constants.OauthConstants;
...@@ -159,7 +160,9 @@ public class AgentApplicationApiServiceImpl implements AgentApplicationApiServic ...@@ -159,7 +160,9 @@ public class AgentApplicationApiServiceImpl implements AgentApplicationApiServic
//计算扣分数 //计算扣分数
// 判断是否调用function // 判断是否调用function
CheckPluginUseEntity checkPluginUseEntity = AgentApplicationTools.checkPluginUse(messages, tools, fileUrls, imageUrls); CheckPluginUseEntity checkPluginUseEntity = AgentApplicationTools.checkPluginUse(messages, tools, fileUrls, imageUrls);
Long pointDeductionNum = pointDeductionRulesService.calculatePointDeductionNum(infoEntity.getLargeModel(), infoEntity.getCommunicationTurn(), checkPluginUseEntity.getDeductionTools()); PointDeductionEntity pointDeductionEntity = pointDeductionRulesService.calculatePointDeductionNum(infoEntity.getLargeModel(), infoEntity.getCommunicationTurn(), checkPluginUseEntity.getDeductionTools());
Long pointDeductionNum = pointDeductionEntity.getModelPoint() + pointDeductionEntity.getPluginPoint();
AgentUseModifyEventInfo agentUseModifyEventInfo = new AgentUseModifyEventInfo(); AgentUseModifyEventInfo agentUseModifyEventInfo = new AgentUseModifyEventInfo();
agentUseModifyEventInfo.setAgentId(agentId); agentUseModifyEventInfo.setAgentId(agentId);
agentUseModifyEventInfo.setIsPublish(CommonConstant.IsDeleted.Y); agentUseModifyEventInfo.setIsPublish(CommonConstant.IsDeleted.Y);
...@@ -178,7 +181,7 @@ public class AgentApplicationApiServiceImpl implements AgentApplicationApiServic ...@@ -178,7 +181,7 @@ public class AgentApplicationApiServiceImpl implements AgentApplicationApiServic
memberEquityService.rollbackPoint(reduceSn); memberEquityService.rollbackPoint(reduceSn);
} }
//数据采集 //数据采集
dataAnalyzeReportService.dataReport(agentId, DataAnalyzeChannelEnum.api, profileEntity.getMemberId(), deducted, pointDeductionNum); dataAnalyzeReportService.dataReport(agentId, DataAnalyzeChannelEnum.api, profileEntity.getMemberId(), deducted, pointDeductionEntity);
} }
private void setAPIUserInfoContext(BizAgentApplicationApiProfileEntity profileEntity) { private void setAPIUserInfoContext(BizAgentApplicationApiProfileEntity profileEntity) {
......
...@@ -19,6 +19,7 @@ import cn.com.poc.equity.aggregate.MemberEquityService; ...@@ -19,6 +19,7 @@ import cn.com.poc.equity.aggregate.MemberEquityService;
import cn.com.poc.equity.aggregate.PointDeductionRulesService; import cn.com.poc.equity.aggregate.PointDeductionRulesService;
import cn.com.poc.equity.constants.ModifyEventEnum; import cn.com.poc.equity.constants.ModifyEventEnum;
import cn.com.poc.equity.domain.modifyEquityInfo.AgentUseModifyEventInfo; import cn.com.poc.equity.domain.modifyEquityInfo.AgentUseModifyEventInfo;
import cn.com.poc.equity.entity.PointDeductionEntity;
import cn.com.poc.expose.aggregate.AgentApplicationExposeService; import cn.com.poc.expose.aggregate.AgentApplicationExposeService;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
...@@ -170,7 +171,9 @@ public class AgentApplicationExposeServiceImpl implements AgentApplicationExpose ...@@ -170,7 +171,9 @@ public class AgentApplicationExposeServiceImpl implements AgentApplicationExpose
//计算扣分数 //计算扣分数
// 判断是否调用function // 判断是否调用function
CheckPluginUseEntity checkPluginUseEntity = AgentApplicationTools.checkPluginUse(messages, tools, fileUrls, imageUrls); CheckPluginUseEntity checkPluginUseEntity = AgentApplicationTools.checkPluginUse(messages, tools, fileUrls, imageUrls);
Long pointDeductionNum = pointDeductionRulesService.calculatePointDeductionNum(infoEntity.getLargeModel(), infoEntity.getCommunicationTurn(), checkPluginUseEntity.getDeductionTools()); PointDeductionEntity pointDeductionEntity = pointDeductionRulesService.calculatePointDeductionNum(infoEntity.getLargeModel(), infoEntity.getCommunicationTurn(), checkPluginUseEntity.getDeductionTools());
Long pointDeductionNum = pointDeductionEntity.getModelPoint() + pointDeductionEntity.getPluginPoint();
AgentUseModifyEventInfo agentUseModifyEventInfo = new AgentUseModifyEventInfo(); AgentUseModifyEventInfo agentUseModifyEventInfo = new AgentUseModifyEventInfo();
agentUseModifyEventInfo.setAgentId(agentId); agentUseModifyEventInfo.setAgentId(agentId);
agentUseModifyEventInfo.setIsPublish(CommonConstant.IsDeleted.Y); agentUseModifyEventInfo.setIsPublish(CommonConstant.IsDeleted.Y);
...@@ -201,7 +204,7 @@ public class AgentApplicationExposeServiceImpl implements AgentApplicationExpose ...@@ -201,7 +204,7 @@ public class AgentApplicationExposeServiceImpl implements AgentApplicationExpose
if (StringUtils.isBlank(channel)) { if (StringUtils.isBlank(channel)) {
channel = DataAnalyzeChannelEnum.link_share.getChannel(); channel = DataAnalyzeChannelEnum.link_share.getChannel();
} }
dataAnalyzeReportService.dataReport(agentId, DataAnalyzeChannelEnum.valueOf(channel), userBaseEntity.getUserId(), deducted, pointDeductionNum); dataAnalyzeReportService.dataReport(agentId, DataAnalyzeChannelEnum.valueOf(channel), userBaseEntity.getUserId(), deducted, pointDeductionEntity);
} catch (Exception e) { } catch (Exception e) {
memberEquityService.rollbackPoint(reduceSn); memberEquityService.rollbackPoint(reduceSn);
throw new BusinessException(e.getMessage()); throw new BusinessException(e.getMessage());
......
...@@ -19,6 +19,7 @@ import cn.com.poc.common.utils.StringUtils; ...@@ -19,6 +19,7 @@ import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.common.utils.UUIDTool; import cn.com.poc.common.utils.UUIDTool;
import cn.com.poc.equity.aggregate.PointDeductionRulesService; import cn.com.poc.equity.aggregate.PointDeductionRulesService;
import cn.com.poc.equity.entity.BizPointDeductionRulesEntity; import cn.com.poc.equity.entity.BizPointDeductionRulesEntity;
import cn.com.poc.equity.entity.PointDeductionEntity;
import cn.com.poc.expose.aggregate.AgentApplicationExposeService; import cn.com.poc.expose.aggregate.AgentApplicationExposeService;
import cn.com.poc.expose.dto.*; import cn.com.poc.expose.dto.*;
import cn.com.poc.expose.rest.AgentApplicationRest; import cn.com.poc.expose.rest.AgentApplicationRest;
...@@ -157,7 +158,9 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -157,7 +158,9 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
bizPointDeductionRulesEntity.setIsDeleted(CommonConstant.IsDeleted.N); bizPointDeductionRulesEntity.setIsDeleted(CommonConstant.IsDeleted.N);
if (CollectionUtils.isNotEmpty(entities)) { if (CollectionUtils.isNotEmpty(entities)) {
result = entities.stream().map(value -> { result = entities.stream().map(value -> {
Long pointDeductionNum = pointDeductionRulesService.calculatePointDeductionNum(value.getLargeModel(), value.getCommunicationTurn(), null); PointDeductionEntity pointDeductionEntity = pointDeductionRulesService.calculatePointDeductionNum(value.getLargeModel(), value.getCommunicationTurn(), null);
Long pointDeductionNum = pointDeductionEntity.getModelPoint() + pointDeductionEntity.getPluginPoint();
SearchAgentApplicationDto searchAgentApplicationDto = new SearchAgentApplicationDto(); SearchAgentApplicationDto searchAgentApplicationDto = new SearchAgentApplicationDto();
searchAgentApplicationDto.setAgentId(value.getAgentId()); searchAgentApplicationDto.setAgentId(value.getAgentId());
searchAgentApplicationDto.setAgentTitle(value.getAgentTitle()); searchAgentApplicationDto.setAgentTitle(value.getAgentTitle());
......
...@@ -22,6 +22,8 @@ import java.io.FileOutputStream; ...@@ -22,6 +22,8 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* @author alex.yao * @author alex.yao
...@@ -49,24 +51,45 @@ public class KnowledgeServiceTest { ...@@ -49,24 +51,45 @@ public class KnowledgeServiceTest {
// @Test // @Test
public static void main(String[] args) throws IOException, InvalidFormatException { public static void main(String[] args) throws IOException, InvalidFormatException {
String markdownContent = readMarkdownFile("C:\\Users\\52747\\Desktop\\1.md"); String r = "AI在艺术创作中的应用越来越多样,这里举几个有趣的例子:\n" +
String htmlContent = convertMarkdownToHtml(markdownContent); "\n" +
"1. **动态画布**:比如纽约有位艺术家用AI实时分析观众微表情,生成会「呼吸变色」的数字壁画,去年在MoMA展出时排队3小时才能体验5分钟。\n" +
" \n" +
"2. **气味交响乐**:伦敦一个实验剧团用GPT-4分析莎士比亚剧本情感曲线,控制128个微型香氛装置,让《仲夏夜之梦》的森林气息能跟着剧情起伏变化。\n" +
" \n" +
"3. **文物「生长」**:敦煌研究院最近用扩散模型推演壁画的千年褪色过程,观众戴上AR眼镜能看到飞天衣裙从氧化变黑逐渐恢复成初绘时的青金石蓝。\n" +
" \n" +
"4. **AI策展人**:苏富比去年拍卖会引入的算法,能根据买家过往竞拍记录,即时生成虚拟展厅,把不同拍品组合出专属艺术史叙事线。\n" +
" \n" +
"\n" +
"这些创新不是要取代艺术家,更像是给创作者装了「第三只手」——比如现在很多雕塑家会先用GAN生成1000个概念模型,再选最有灵气的3个手工打磨。最近威尼斯双年展有个获奖装置,就是人类雕刻家与AI迭代了147个版本才确定的最终形态。";
// String markdownContent = readMarkdownFile("C:\\Users\\52747\\Desktop\\1.md");
String htmlContent = convertMarkdownToHtml(r);
convertHtmlToWord(htmlContent, "C:\\Users\\52747\\Desktop\\1.docx"); convertHtmlToWord(htmlContent, "C:\\Users\\52747\\Desktop\\1.docx");
} //
// String html = "<p>AI在艺术创作中的应用越来越多样,这里举几个有趣的例子:</p><ol><li><p><strong>动态画布</strong>:比如纽约有位艺术家用AI实时分析观众微表情,生成会「呼吸变色」的数字壁画,去年在MoMA展出时排队3小时才能体验5分钟。</p></li><li><p><strong>气味交响乐</strong>:伦敦一个实验剧团用GPT-4分析莎士比亚剧本情感曲线,控制128个微型香氛装置,让《仲夏夜之梦》的森林气息能跟着剧情起伏变化。</p></li><li><p><strong>文物「生长」</strong>:敦煌研究院最近用扩散模型推演壁画的千年褪色过程,观众戴上AR眼镜能看到飞天衣裙从氧化变黑逐渐恢复成初绘时的青金石蓝。</p></li><li><p><strong>AI策展人</strong>:苏富比去年拍卖会引入的算法,能根据买家过往竞拍记录,即时生成虚拟展厅,把不同拍品组合出专属艺术史叙事线。</p></li></ol><p>这些创新不是要取代艺术家,更像是给创作者装了「第三只手」——比如现在很多雕塑家会先用GAN生成1000个概念模型,再选最有灵气的3个手工打磨。最近威尼斯双年展有个获奖装置,就是人类雕刻家与AI迭代了147个版本才确定的最终形态。</p>";
// convertHtmlToWord(html, "C:\\Users\\52747\\Desktop\\1.docx");
private static String readMarkdownFile(String filePath) {
try {
return new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
e.printStackTrace();
return "";
}
} }
// private static String readMarkdownFile(String filePath) {
// try {
// return new String(Files.readAllBytes(Paths.get(filePath)));
// } catch (IOException e) {
// e.printStackTrace();
// return "";
// }
// }
private static String convertMarkdownToHtml(String markdown) { private static String convertMarkdownToHtml(String markdown) {
Pattern p = Pattern.compile("(\r?\n(\\s*\r?\n)+)");
Matcher m = p.matcher(markdown);
String result = m.replaceAll("\r\n");
Parser parser = Parser.builder().build(); Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build(); HtmlRenderer renderer = HtmlRenderer.builder().build();
Document document = parser.parse(markdown); Document document = parser.parse(result);
return renderer.render(document); return renderer.render(document);
} }
......
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