接口 DifyChatClient
- 所有超级接口:
AutoCloseable,DifyBaseClient
- 所有已知子接口:
DifyChatflowClient,DifyClient
- 所有已知实现类:
DefaultDifyClient
Dify 对话型应用客户端接口
包含对话型应用相关的功能
-
方法概要
修饰符和类型方法说明annotationReply(String action, String embeddingProviderName, String embeddingModelName, Integer scoreThreshold) 标注回复初始设置audioToText(File file, String user) 语音转文字audioToText(InputStream inputStream, String fileName, String user) 语音转文字deleteAnnotation(String annotationId) 删除标注deleteConversation(String conversationId, String user) 删除会话feedbackMessage(String messageId, String rating, String user, String content) 消息反馈(点赞)getAnnotationReply(String action, String jobId) 查询标注回复初始设置任务状态getAnnotations(Integer page, Integer limit) 获取标注列表获取应用元数据getConversations(String user, String lastId, Integer limit, String sortBy) 获取会话列表getConversationVariables(String conversationId, String user, String lastId, Integer limit, String variableName) 获取对话变量 从特定对话中检索变量。getMessages(String conversationId, String user, String firstId, Integer limit) 获取会话历史消息getSuggestedQuestions(String messageId, String user) 获取下一轮建议问题列表renameConversation(String conversationId, String name, Boolean autoGenerate, String user) 会话重命名saveAnnotation(String question, String answer) 创建标注sendChatMessage(ChatMessage message) 发送对话消息(阻塞模式)voidsendChatMessageStream(ChatMessage message, ChatStreamCallback callback) 发送对话消息(流式模式) 注:Agent模式下不允许blockingstopChatMessage(String taskId, String user) 停止对话消息byte[]textToAudio(String messageId, String text, String user) 文字转语音updateAnnotation(String annotationId, String question, String answer) 更新标注从接口继承的方法 io.github.imfangs.dify.client.DifyBaseClient
close, getAppInfo, getAppParameters, getAppWebAppSettings, previewFile, previewFile, uploadFile, uploadFile, uploadFile
-
方法详细资料
-
sendChatMessage
发送对话消息(阻塞模式)- 参数:
message- 消息- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
sendChatMessageStream
void sendChatMessageStream(ChatMessage message, ChatStreamCallback callback) throws IOException, DifyApiException 发送对话消息(流式模式) 注:Agent模式下不允许blocking- 参数:
message- 消息callback- 回调- 抛出:
IOException- IO异常DifyApiException- API异常
-
stopChatMessage
停止对话消息- 参数:
taskId- 任务 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
feedbackMessage
SimpleResponse feedbackMessage(String messageId, String rating, String user, String content) throws IOException, DifyApiException 消息反馈(点赞)- 参数:
messageId- 消息 IDrating- 评分user- 用户标识content- 内容- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getSuggestedQuestions
SuggestedQuestionsResponse getSuggestedQuestions(String messageId, String user) throws IOException, DifyApiException 获取下一轮建议问题列表- 参数:
messageId- 消息 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getMessages
MessageListResponse getMessages(String conversationId, String user, String firstId, Integer limit) throws IOException, DifyApiException 获取会话历史消息- 参数:
conversationId- 会话 IDuser- 用户标识firstId- 当前页第一条聊天记录的 IDlimit- 一次请求返回多少条聊天记录- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getConversations
ConversationListResponse getConversations(String user, String lastId, Integer limit, String sortBy) throws IOException, DifyApiException 获取会话列表- 参数:
user- 用户标识lastId- 当前页最后面一条记录的 IDlimit- 一次请求返回多少条记录sortBy- 排序字段- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
deleteConversation
SimpleResponse deleteConversation(String conversationId, String user) throws IOException, DifyApiException 删除会话- 参数:
conversationId- 会话 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
renameConversation
Conversation renameConversation(String conversationId, String name, Boolean autoGenerate, String user) throws IOException, DifyApiException 会话重命名- 参数:
conversationId- 会话 IDname- 名称autoGenerate- 自动生成标题user- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
audioToText
语音转文字- 参数:
file- 文件user- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
audioToText
AudioToTextResponse audioToText(InputStream inputStream, String fileName, String user) throws IOException, DifyApiException 语音转文字- 参数:
inputStream- 输入流fileName- 文件名user- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
textToAudio
文字转语音- 参数:
messageId- 消息 IDtext- 文本user- 用户标识- 返回:
- 音频数据
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getAppMeta
获取应用元数据- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getAnnotations
AnnotationListResponse getAnnotations(Integer page, Integer limit) throws IOException, DifyApiException 获取标注列表- 参数:
page- 页码limit- 每页数量- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
saveAnnotation
创建标注- 参数:
question- 问题answer- 答案内容- 返回:
- 标注
- 抛出:
IOException- IO异常DifyApiException- API异常
-
updateAnnotation
Annotation updateAnnotation(String annotationId, String question, String answer) throws IOException, DifyApiException 更新标注- 参数:
annotationId- 标注 IDquestion- 问题answer- 答案内容- 返回:
- 标注
- 抛出:
IOException- IO异常DifyApiException- API异常
-
deleteAnnotation
删除标注- 参数:
annotationId- 标注 ID- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
annotationReply
AnnotationReply annotationReply(String action, String embeddingProviderName, String embeddingModelName, Integer scoreThreshold) throws IOException, DifyApiException 标注回复初始设置- 参数:
action- 动作,只能是 'enable' 或 'disable'embeddingProviderName- 指定的嵌入模型提供商, 必须先在系统内设定好接入的模型,对应的是provider字段embeddingModelName- 指定的嵌入模型,对应的是model字段scoreThreshold- 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复- 返回:
- 标注回复
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getAnnotationReply
AnnotationReply getAnnotationReply(String action, String jobId) throws IOException, DifyApiException 查询标注回复初始设置任务状态- 参数:
action- 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致jobId- 任务 ID,从标注回复初始设置接口返回的 jobId- 返回:
- 标注回复
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getConversationVariables
VariableResponse getConversationVariables(String conversationId, String user, String lastId, Integer limit, String variableName) throws DifyApiException, IOException 获取对话变量 从特定对话中检索变量。此端点对于提取对话过程中捕获的结构化数据非常有用。- 参数:
conversationId- 会话 IDuser- 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。重要说明: Service API 不共享 WebApp 创建的对话。通过 API 创建的对话与 WebApp 界面中创建的对话是相互隔离的。lastId- (选填)当前页最后面一条记录的 ID,默认 null。limit- 一次请求返回多少条记录,默认 20 条,最大 100 条,最小 1 条。variableName- (选填)按变量名称筛选。- 返回:
- 抛出:
DifyApiExceptionIOException
-