聊天服务接口提供完整的聊天功能集成能力,包含消息收发、会话管理、语音转换等核心功能。所有接口均需要有效的API密钥进行身份验证。 使用DifyChat
接口实例。
ChatMessageSendResponse send(ChatMessageSendRequest sendRequest);
ChatMessageSendRequest
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
conversationId | String | 否 | 聊天对话编号 |
content | String | 是 | 消息内容 |
files | List<ChatMessageFile> | 否 | 文件 |
inputs | Map<String, Object> | 否 | 自定义参数 |
ChatMessageSendResponse
参数名 | 类型 | 描述 |
---|
conversationId | String | 会话 id |
messageId | String | 消息id |
createdAt | Long | 创建时间戳 |
taskId | String | 任务 id |
id | String | id |
answer | String | 回答 |
Flux<ChatMessageSendResponse> sendChatMessageStream(ChatMessageSendRequest sendRequest);
与发送消息接口相同
返回消息流,每条消息格式与发送消息响应相同
void stopMessagesStream(String apiKey, String taskId, String userId);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
taskId | String | 是 | 任务 id |
userId | String | 是 | 用户 id |
MessageFeedbackResponse messageFeedback(MessageFeedbackRequest messageFeedbackRequest);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
messageId | String | 是 | 消息 id |
rating | Rating | 是 | 评级 |
content | String | 是 | 消息反馈的具体信息 |
MessageFeedbackResponse
参数名 | 类型 | 描述 |
---|
result | String | 固定返回 success |
DifyPageResult<MessagesResponseVO> messages(MessagesRequest request);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
conversationId | String | 是 | 会话 id |
firstId | String | 否 | 第一条记录 id |
limit | Integer | 否 | 每页记录数,默认20条 |
List<String> messagesSuggested(String messageId, String apiKey, String userId);
参数名 | 类型 | 是否必须 | 描述 |
---|
messageId | String | 是 | 消息 id |
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
返回建议回复文本列表
DifyPageResult<MessageConversationsResponse> conversations(MessageConversationsRequest request);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
lastId | String | 否 | 最后一条记录 id |
limit | Integer | 否 | 每页记录数,默认20 |
sortBy | String | 否 | 排序字段,默认-updated_at |
MessageConversationsResponse
参数名 | 类型 | 描述 |
---|
id | String | 会话 id |
name | String | 会话名称 |
inputs | Map<String,Object> | 输入参数 |
status | String | 会话状态 |
introduction | String | 开场白 |
createdAt | Long | 创建时间戳 |
updatedAt | Long | 更新时间戳 |
void deleteConversation(String conversationId, String apiKey, String userId);
参数名 | 类型 | 是否必须 | 描述 |
---|
conversationId | String | 是 | 会话 id |
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
MessageConversationsResponse renameConversation(RenameConversationRequest renameConversationRequest);
参数名 | 类型 | 是否必须 | 描述 |
---|
conversationId | String | 是 | 会话 id |
name | String | 是 | 会话名称 |
autoGenerate | String | 否 | 自动生成标题,默认 false |
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
MessageConversationsResponse
参数名 | 类型 | 描述 |
---|
id | String | 会话 id |
name | String | 会话名称 |
inputs | Map<String,Object> | 输入参数 |
status | String | 会话状态 |
introduction | String | 开场白 |
createdAt | Long | 创建时间戳 |
updatedAt | Long | 更新时间戳 |
void textToAudio(TextToAudioRequest request, HttpServletResponse response);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
text | String | 是 | 转换文本 |
messageId | String | 否 | 消息 id |
返回音频文件流
DifyTextVO audioToText(AudioToTextRequest request);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
userId | String | 是 | 用户 id |
file | MultipartFile | 是 | 音频文件 |
AppParametersResponseVO parameters(String apiKey);
参数名 | 类型 | 是否必须 | 描述 |
---|
apiKey | String | 是 | apiKey |
AppParametersResponseVO
参数名 | 类型 | 描述 |
---|
openingStatement | String | 开场白 |
suggestedQuestions | List<String> | 开场推荐问题列表 |
suggestedQuestionsAfterAnswer | Enabled | 启用回答后给出推荐问题 |
speechToText | Enabled | 语音转文本功能配置 |
textToSpeech | TextToSpeech | 文本转语音功能配置 |
retrieverResource | Enabled | 引用和归属功能配置 |
annotationReply | Enabled | 标记回复功能配置 |
moreLikeThis | Enabled | 更多类似功能配置 |
userInputForm | List<UserInputForm> | 用户输入表单配置 |
sensitiveWordAvoidance | Enabled | 敏感词规避功能配置 |
fileUpload | FileUpload | 文件上传配置 |
systemParameters | FileUploadConfig | 系统参数配置 |
Enabled 对象结构:
参数名 | 类型 | 描述 |
---|
enabled | Boolean | 是否启用 |
TextToSpeech 对象结构:
参数名 | 类型 | 描述 |
---|
enabled | Boolean | 是否启用 |
voice | String | 语音类型 |
FileUpload 对象结构:
参数名 | 类型 | 描述 |
---|
enabled | Boolean | 是否启用文件上传功能 |
image | FileUploadImage | 图片上传配置 |
allowedFileTypes | List<String> | 允许的文件类型列表 |
allowedFileExtensions | List<String> | 允许的文件扩展名列表 |
allowedFileUploadMethods | List<String> | 允许的文件上传方式列表 |
numberLimits | Integer | 文件数量限制 |
fileUploadConfig | FileUploadConfig | 文件上传详细配置 |
FileUploadImage 对象结构:
参数名 | 类型 | 描述 |
---|
enabled | Boolean | 是否启用图片上传功能 |
numberLimits | Integer | 图片数量限制,默认3 |
transferMethods | List<String> | 传递方式列表,可选值:remote_url, local_file |
FileUploadConfig 对象结构:
参数名 | 类型 | 描述 |
---|
fileSizeLimit | Integer | 文件大小限制(MB) |
batchCountLimit | Integer | 批量上传数量限制 |
imageFileSizeLimit | Integer | 图片文件大小限制(MB) |
videoFileSizeLimit | Integer | 视频文件大小限制(MB) |
audioFileSizeLimit | Integer | 音频文件大小限制(MB) |
workflowFileUploadLimit | Integer | 工作流文件上传限制 |
UserInputForm 对象结构:
参数名 | 类型 | 描述 |
---|
textInput | TextInput | 文本输入控件配置 |
paragraph | Paragraph | 段落文本输入控件配置 |
select | Select | 下拉控件配置 |
TextInput 对象结构:
参数名 | 类型 | 描述 |
---|
label | String | 控件展示标签名 |
variable | String | 控件ID |
required | Boolean | 是否必填 |
maxLength | Integer | 最大长度限制 |
defaultValue | String | 默认值 |
Paragraph 对象结构: 继承自 TextInput,具有相同的字段结构
Select 对象结构:
参数名 | 类型 | 描述 |
---|
label | String | 控件展示标签名 |
variable | String | 控件ID |
required | Boolean | 是否必填 |
maxLength | Integer | 最大长度限制 |
defaultValue | String | 默认值 |
type | String | 下拉类型 |
options | List<String> | 选项列表 |