对话流实现 文件上传
This commit is contained in:
@@ -2,6 +2,7 @@ package org.xyzh.api.ai.chat;
|
||||
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.api.ai.dto.DifyFileInfo;
|
||||
import org.xyzh.common.dto.ai.TbAiConversation;
|
||||
import org.xyzh.common.dto.ai.TbAiMessage;
|
||||
|
||||
@@ -17,20 +18,27 @@ import java.util.List;
|
||||
public interface AiChatService {
|
||||
|
||||
/**
|
||||
* 流式对话(SSE)- 使用SseEmitter实现真正的流式推送
|
||||
* 准备对话会话(POST传递复杂参数)
|
||||
* @param agentId 智能体ID
|
||||
* @param conversationId 会话ID(可选,为空则创建新会话)
|
||||
* @param query 用户问题
|
||||
* @param knowledgeIds 使用的知识库ID列表(可选,用于知识库隔离)
|
||||
* @return SseEmitter 流式推送对象
|
||||
* @param filesData 上传的文件列表(Dify文件信息)
|
||||
* @return ResultDomain<String> 返回sessionId
|
||||
*/
|
||||
SseEmitter streamChatWithSse(
|
||||
ResultDomain<String> prepareChatSession(
|
||||
String agentId,
|
||||
String conversationId,
|
||||
String query,
|
||||
List<String> knowledgeIds
|
||||
List<DifyFileInfo> filesData
|
||||
);
|
||||
|
||||
/**
|
||||
* 流式对话(SSE)- 使用sessionId建立SSE连接
|
||||
* @param sessionId 会话标识
|
||||
* @return SseEmitter 流式推送对象
|
||||
*/
|
||||
SseEmitter streamChatWithSse(String sessionId);
|
||||
|
||||
/**
|
||||
* 阻塞式对话(非流式)
|
||||
* @param agentId 智能体ID
|
||||
@@ -42,8 +50,7 @@ public interface AiChatService {
|
||||
ResultDomain<TbAiMessage> blockingChat(
|
||||
String agentId,
|
||||
String conversationId,
|
||||
String query,
|
||||
List<String> knowledgeIds
|
||||
String query
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.xyzh.api.ai.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description Dify文件信息(用于对话文件上传和请求)
|
||||
* @filename DifyFileInfo.java
|
||||
* @author AI Assistant
|
||||
* @copyright xyzh
|
||||
* @since 2025-11-06
|
||||
*/
|
||||
@Data
|
||||
public class DifyFileInfo {
|
||||
/**
|
||||
* 文件ID(Dify返回)
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 文件大小(字节)
|
||||
*/
|
||||
private Integer size;
|
||||
|
||||
/**
|
||||
* 文件扩展名
|
||||
*/
|
||||
private String extension;
|
||||
|
||||
/**
|
||||
* 文件MIME类型
|
||||
*/
|
||||
@JsonProperty("mime_type")
|
||||
private String mimeType;
|
||||
|
||||
/**
|
||||
* 上传人ID
|
||||
*/
|
||||
@JsonProperty("created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
* 上传时间(时间戳)
|
||||
*/
|
||||
@JsonProperty("created_at")
|
||||
private Long createdAt;
|
||||
|
||||
/**
|
||||
* 预览URL
|
||||
*/
|
||||
@JsonProperty("preview_url")
|
||||
private String previewUrl;
|
||||
|
||||
/**
|
||||
* 源文件URL
|
||||
*/
|
||||
@JsonProperty("source_url")
|
||||
private String sourceUrl;
|
||||
|
||||
/**
|
||||
* 文件类型:image、document、audio、video、file
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 传输方式:remote_url、local_file
|
||||
*/
|
||||
@JsonProperty("transfer_method")
|
||||
private String transferMethod;
|
||||
|
||||
/**
|
||||
* 文件URL或ID
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 本地文件上传ID
|
||||
*/
|
||||
@JsonProperty("upload_file_id")
|
||||
private String uploadFileId;
|
||||
|
||||
/**
|
||||
* 系统文件ID
|
||||
*/
|
||||
@JsonProperty("sys_file_id")
|
||||
private String sysFileId;
|
||||
|
||||
/**
|
||||
* 文件路径(从系统文件表获取)
|
||||
*/
|
||||
@JsonProperty("file_path")
|
||||
private String filePath;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.ai.TbAiUploadFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description AI文件上传服务接口
|
||||
@@ -17,6 +18,17 @@ import java.util.List;
|
||||
*/
|
||||
public interface AiUploadFileService {
|
||||
|
||||
/**
|
||||
* 上传文件用于对话(图文多模态)
|
||||
* @param file 上传的文件
|
||||
* @param agentId 智能体ID
|
||||
* @return Dify文件信息(包含id、name、size等)
|
||||
*/
|
||||
ResultDomain<Map<String, Object>> uploadFileForChat(
|
||||
MultipartFile file,
|
||||
String agentId
|
||||
);
|
||||
|
||||
/**
|
||||
* 上传文件到知识库(同步到Dify)
|
||||
* @param knowledgeId 知识库ID
|
||||
@@ -92,4 +104,11 @@ public interface AiUploadFileService {
|
||||
* @return 同步结果
|
||||
*/
|
||||
ResultDomain<TbAiUploadFile> syncKnowledgeFiles(String knowledgeId);
|
||||
|
||||
/**
|
||||
* 查询消息关联的文件列表
|
||||
* @param messageId 消息ID
|
||||
* @return 文件列表
|
||||
*/
|
||||
ResultDomain<TbAiUploadFile> listFilesByMessageId(String messageId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user