fix
This commit is contained in:
1983
db/init-table-postgres-full.sql
Normal file
1983
db/init-table-postgres-full.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* 发号器配置类
|
||||
* @author sr on 2021-03-23
|
||||
*/
|
||||
@Configuration
|
||||
//@Configuration
|
||||
@AutoConfigureAfter(CommonConfiguration.class)
|
||||
@Slf4j
|
||||
public class CodeConfiguration {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.senmesh.sdk.dify.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -28,10 +29,12 @@ public class DifyChatRequest implements Serializable {
|
||||
private String query;
|
||||
|
||||
/** 响应模式: blocking/streaming */
|
||||
@JsonProperty("response_mode")
|
||||
@Builder.Default
|
||||
private String responseMode = "blocking";
|
||||
|
||||
/** 会话ID */
|
||||
@JsonProperty("conversation_id")
|
||||
private String conversationId;
|
||||
|
||||
/** 用户标识 */
|
||||
@@ -55,6 +58,7 @@ public class DifyChatRequest implements Serializable {
|
||||
private String type;
|
||||
|
||||
/** 传输方式: remote_url/local_file */
|
||||
@JsonProperty("transfer_method")
|
||||
@Builder.Default
|
||||
private String transferMethod = "local_file";
|
||||
|
||||
@@ -62,6 +66,7 @@ public class DifyChatRequest implements Serializable {
|
||||
private String url;
|
||||
|
||||
/** 上传文件ID */
|
||||
@JsonProperty("upload_file_id")
|
||||
private String uploadFileId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.senmesh.sdk.dify.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -21,9 +22,11 @@ public class DifyChatResponse implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 消息ID */
|
||||
@JsonProperty("message_id")
|
||||
private String messageId;
|
||||
|
||||
/** 会话ID */
|
||||
@JsonProperty("conversation_id")
|
||||
private String conversationId;
|
||||
|
||||
/** 模式 */
|
||||
@@ -36,6 +39,7 @@ public class DifyChatResponse implements Serializable {
|
||||
private Metadata metadata;
|
||||
|
||||
/** 创建时间 */
|
||||
@JsonProperty("created_at")
|
||||
private Long createdAt;
|
||||
|
||||
/**
|
||||
@@ -53,6 +57,7 @@ public class DifyChatResponse implements Serializable {
|
||||
private Usage usage;
|
||||
|
||||
/** 检索器资源 */
|
||||
@JsonProperty("retriever_resources")
|
||||
private List<RetrieverResource> retrieverResources;
|
||||
}
|
||||
|
||||
@@ -68,33 +73,43 @@ public class DifyChatResponse implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 提示词token数 */
|
||||
@JsonProperty("prompt_tokens")
|
||||
private Integer promptTokens;
|
||||
|
||||
/** 提示词单位价格 */
|
||||
@JsonProperty("prompt_unit_price")
|
||||
private String promptUnitPrice;
|
||||
|
||||
/** 提示词价格单位 */
|
||||
@JsonProperty("prompt_price_unit")
|
||||
private String promptPriceUnit;
|
||||
|
||||
/** 提示词价格 */
|
||||
@JsonProperty("prompt_price")
|
||||
private String promptPrice;
|
||||
|
||||
/** 完成token数 */
|
||||
@JsonProperty("completion_tokens")
|
||||
private Integer completionTokens;
|
||||
|
||||
/** 完成单位价格 */
|
||||
@JsonProperty("completion_unit_price")
|
||||
private String completionUnitPrice;
|
||||
|
||||
/** 完成价格单位 */
|
||||
@JsonProperty("completion_price_unit")
|
||||
private String completionPriceUnit;
|
||||
|
||||
/** 完成价格 */
|
||||
@JsonProperty("completion_price")
|
||||
private String completionPrice;
|
||||
|
||||
/** 总token数 */
|
||||
@JsonProperty("total_tokens")
|
||||
private Integer totalTokens;
|
||||
|
||||
/** 总价格 */
|
||||
@JsonProperty("total_price")
|
||||
private String totalPrice;
|
||||
|
||||
/** 货币 */
|
||||
@@ -119,18 +134,23 @@ public class DifyChatResponse implements Serializable {
|
||||
private Integer position;
|
||||
|
||||
/** 数据集ID */
|
||||
@JsonProperty("dataset_id")
|
||||
private String datasetId;
|
||||
|
||||
/** 数据集名称 */
|
||||
@JsonProperty("dataset_name")
|
||||
private String datasetName;
|
||||
|
||||
/** 文档ID */
|
||||
@JsonProperty("document_id")
|
||||
private String documentId;
|
||||
|
||||
/** 文档名称 */
|
||||
@JsonProperty("document_name")
|
||||
private String documentName;
|
||||
|
||||
/** 分段ID */
|
||||
@JsonProperty("segment_id")
|
||||
private String segmentId;
|
||||
|
||||
/** 分数 */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.senmesh.sdk.dify.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -32,13 +33,15 @@ public class DifyFileUploadResponse implements Serializable {
|
||||
private String extension;
|
||||
|
||||
/** MIME类型 */
|
||||
@JsonProperty("mime_type")
|
||||
private String mimeType;
|
||||
|
||||
/** 创建者 */
|
||||
@JsonProperty("created_by")
|
||||
private String createdBy;
|
||||
|
||||
/** 创建时间 */
|
||||
@JsonProperty("created_at")
|
||||
private Long createdAt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<select id="statisticsByCategory" resultType="com.senmesh.sfile.dto.UserFileStatisticsDTO">
|
||||
SELECT
|
||||
COALESCE(fc.file_category, '未分类') AS file_category,
|
||||
fc.file_category AS file_category,
|
||||
COUNT(t.id) AS file_count,
|
||||
COALESCE(SUM(fr.file_size), 0) AS total_size
|
||||
FROM x_user_file t
|
||||
|
||||
@@ -25,8 +25,11 @@ import com.senmesh.sfile.dto.FileRiskDTO;
|
||||
import com.senmesh.sfile.dto.FileRiskQueryDTO;
|
||||
import com.senmesh.sfile.entity.FileRisk;
|
||||
import com.senmesh.sfile.service.FileRiskService;
|
||||
import com.senmesh.usercenter.constants.OrgConstants;
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -47,6 +50,7 @@ public class FileRiskServiceImpl implements FileRiskService {
|
||||
|
||||
private static final String RISK_RULE_CONFIG_CODE = "risk_rule";
|
||||
private static final String MIN_AUDIT_RISK_LEVEL_CONFIG_CODE = "min_audit_risk_level";
|
||||
private static final String DIFY_USER_ID = "senmeshfile";
|
||||
|
||||
/**
|
||||
* 规则生成 API Key
|
||||
@@ -130,7 +134,6 @@ public class FileRiskServiceImpl implements FileRiskService {
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public FileRiskDTO scanFileRisk(String fileCode) {
|
||||
// 1. 查询或创建记录
|
||||
FileRiskQueryDTO queryDTO = FileRiskQueryDTO.builder().fileCode(fileCode).build();
|
||||
@@ -140,7 +143,7 @@ public class FileRiskServiceImpl implements FileRiskService {
|
||||
// 1.1 记录不存在,创建新记录
|
||||
log.info("文件风险不存在,创建新记录,fileCode: {}", fileCode);
|
||||
FileRiskCreateDTO createDTO = FileRiskCreateDTO.builder()
|
||||
.fileCode(fileCode)
|
||||
// .fileCode("aa.png")
|
||||
.build();
|
||||
fileRiskDTO = this.create(createDTO);
|
||||
}
|
||||
@@ -160,15 +163,20 @@ public class FileRiskServiceImpl implements FileRiskService {
|
||||
|
||||
// 3. 如果 riskJson 为空,则调用 Dify Chat 分析
|
||||
|
||||
DifyChatRequest chatRequest = DifyChatRequest.builder()
|
||||
.query("请分析这个文件的风险")
|
||||
.user(String.valueOf(UserContextHolder.getLoginUserId()))
|
||||
.files(Collections.singletonList(
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
inputs.put("gz", this.getRiskRule(OrgConstants.PLATFORM_ORG_ID));
|
||||
inputs.put("srwj",
|
||||
Collections.singletonList(
|
||||
DifyChatRequest.DifyFileInfo.builder()
|
||||
.type(uploadResponse.getMimeType())
|
||||
.type("image")
|
||||
.uploadFileId(uploadResponse.getId())
|
||||
.build()
|
||||
))
|
||||
));
|
||||
DifyChatRequest chatRequest = DifyChatRequest.builder()
|
||||
.query("请分析这个文件的风险")
|
||||
.user(DIFY_USER_ID)
|
||||
.inputs(inputs)
|
||||
.files(Lists.emptyList())
|
||||
.build();
|
||||
|
||||
AlitaResult<DifyChatResponse> chatResult = DifyClient.chatMessages(riskScanApiKey, chatRequest);
|
||||
@@ -234,7 +242,7 @@ public class FileRiskServiceImpl implements FileRiskService {
|
||||
DifyFileUploadRequest uploadRequest = DifyFileUploadRequest.builder()
|
||||
.inputStream(fileStream)
|
||||
.fileName(fileCode)
|
||||
.user(String.valueOf(UserContextHolder.getLoginUserId()))
|
||||
.user(DIFY_USER_ID)
|
||||
.build();
|
||||
|
||||
AlitaResult<DifyFileUploadResponse> uploadResult = DifyClient.uploadFile(apiKey, uploadRequest);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.senmesh.common.CommonConfiguration,\
|
||||
com.senmesh.codegenerator.config.CodeConfiguration,\
|
||||
com.senmesh.frame.redis.config.RedisCacheConfig,\
|
||||
com.senmesh.frame.redis.redisson.RedissonConfig
|
||||
@@ -74,33 +74,6 @@ spring.redis.lettuce.pool.max-active=10
|
||||
spring.redis.lettuce.pool.max-wait=-1ms
|
||||
spring.redis.database=1
|
||||
|
||||
##mq
|
||||
spring.rabbitmq.host=121.37.2.171
|
||||
spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=lettuce.co
|
||||
#开启发送失败返回
|
||||
spring.rabbitmq.publisher-returns=true
|
||||
#开启发送确认
|
||||
spring.rabbitmq.publisher-confirms=true
|
||||
#监听类型,每个consumer都有对应的channel,consumer的线程共享
|
||||
spring.rabbitmq.listener.type=direct
|
||||
#none发送消息后直接确认消息/auto根据消息消费的情况,智能判定消息的确认情况/manual手动确认消息的情况
|
||||
spring.rabbitmq.listener.direct.acknowledge-mode=auto
|
||||
#每个队列消费者数
|
||||
spring.rabbitmq.listener.direct.consumers-per-queue=3
|
||||
#每个消费者处理未确认消息的最大数量
|
||||
spring.rabbitmq.listener.direct.prefetch=100
|
||||
spring.rabbitmq.listener.direct.default-requeue-rejected=true
|
||||
#支持消息的确认与返回
|
||||
spring.rabbitmq.template.mandatory=true
|
||||
#定制化配置
|
||||
#exchange名称
|
||||
rabbitmq.custom.topicExchangeName=alita_exchange
|
||||
#指定消息消费者ip
|
||||
rabbitmq.custom.consumerAppId=
|
||||
|
||||
|
||||
security.useLocal=true
|
||||
security.ignoring=/*.html,/favicon.ico
|
||||
security.anonymous=/anon/**,/druid/**,/ws/**
|
||||
@@ -144,7 +117,7 @@ sms.phoneSms=
|
||||
|
||||
#dify配置
|
||||
dify.enable=false
|
||||
dify.host=https://flow.senmesh.com
|
||||
dify.host=http://114.242.42.23:8501
|
||||
# 规则生成 API Key
|
||||
dify.risk.rule.api-key=app-agFkKV5EsAEZfCC6wGSDraak
|
||||
# 文件智能风险预警 API Key
|
||||
|
||||
Reference in New Issue
Block a user