类 DefaultDifyClient
java.lang.Object
io.github.imfangs.dify.client.impl.AbstractDifyClient
io.github.imfangs.dify.client.impl.DifyBaseClientImpl
io.github.imfangs.dify.client.impl.DefaultDifyClient
- 所有已实现的接口:
DifyBaseClient,DifyChatClient,DifyChatflowClient,DifyClient,DifyCompletionClient,DifyWorkflowClient,AutoCloseable
Dify API 客户端默认实现
提供对话型应用、文本生成型应用和工作流应用的完整功能
-
字段概要
从类继承的字段 io.github.imfangs.dify.client.impl.AbstractDifyClient
apiKey, AUDIO, baseUrl, httpClient, JSON, OCTET_STREAM -
构造器概要
构造器构造器说明DefaultDifyClient(String baseUrl, String apiKey) 构造函数DefaultDifyClient(String baseUrl, String apiKey, okhttp3.OkHttpClient httpClient) 构造函数 -
方法概要
修饰符和类型方法说明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) 获取下一轮建议问题列表getWorkflowLogs(String keyword, String status, Integer page, Integer limit) 获取工作流日志getWorkflowRun(String workflowRunId) 获取工作流运行状态renameConversation(String conversationId, String name, Boolean autoGenerate, String user) 会话重命名runWorkflow(WorkflowRunRequest request) 执行工作流(阻塞模式)voidrunWorkflowStream(WorkflowRunRequest request, WorkflowStreamCallback callback) 执行工作流(流式模式)saveAnnotation(String question, String answer) 创建标注sendChatMessage(ChatMessage message) 发送对话消息(阻塞模式)voidsendChatMessageStream(ChatMessage message, ChatflowStreamCallback callback) 发送对话消息(流式模式,支持工作流) 注:Agent模式下不允许blockingvoidsendChatMessageStream(ChatMessage message, ChatStreamCallback callback) 发送对话消息(流式模式) 注:Agent模式下不允许blockingsendCompletionMessage(CompletionRequest request) 发送文本生成请求(阻塞模式)voidsendCompletionMessageStream(CompletionRequest request, CompletionStreamCallback callback) 发送文本生成请求(流式模式)stopChatMessage(String taskId, String user) 停止对话消息stopCompletion(String taskId, String user) 停止文本生成stopWorkflow(String taskId, String user) 停止工作流byte[]textToAudio(String messageId, String text, String user) 文字转语音updateAnnotation(String annotationId, String question, String answer) 更新标注从类继承的方法 io.github.imfangs.dify.client.impl.DifyBaseClientImpl
close, getAppInfo, getAppParameters, getAppWebAppSettings, previewFile, previewFile, uploadFile, uploadFile, uploadFile从类继承的方法 io.github.imfangs.dify.client.impl.AbstractDifyClient
addIfNotEmpty, addIfNotNull, buildUrlWithMultiValueParams, buildUrlWithParams, createApiException, createDeleteRequest, createGetRequest, createJsonRequestBody, createPatchRequest, createPostRequest, createPutRequest, executeDelete, executeGet, executePatch, executePost, executePut, executeRequest, executeRequestForBytes, handleResponse从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.github.imfangs.dify.client.DifyBaseClient
close, getAppInfo, getAppParameters, getAppWebAppSettings, previewFile, previewFile, uploadFile, uploadFile, uploadFile
-
构造器详细资料
-
DefaultDifyClient
构造函数- 参数:
baseUrl- API基础URLapiKey- API密钥
-
DefaultDifyClient
构造函数- 参数:
baseUrl- API基础URLapiKey- API密钥httpClient- HTTP客户端
-
-
方法详细资料
-
sendChatMessage
public ChatMessageResponse sendChatMessage(ChatMessage message) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient发送对话消息(阻塞模式)- 指定者:
sendChatMessage在接口中DifyChatClient- 参数:
message- 消息- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
sendChatMessageStream
public void sendChatMessageStream(ChatMessage message, ChatStreamCallback callback) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient发送对话消息(流式模式) 注:Agent模式下不允许blocking- 指定者:
sendChatMessageStream在接口中DifyChatClient- 参数:
message- 消息callback- 回调- 抛出:
IOException- IO异常DifyApiException- API异常
-
sendChatMessageStream
public void sendChatMessageStream(ChatMessage message, ChatflowStreamCallback callback) throws IOException, DifyApiException 从接口复制的说明:DifyChatflowClient发送对话消息(流式模式,支持工作流) 注:Agent模式下不允许blocking- 指定者:
sendChatMessageStream在接口中DifyChatflowClient- 参数:
message- 消息callback- 工作流编排对话回调- 抛出:
IOException- IO异常DifyApiException- API异常
-
stopChatMessage
public SimpleResponse stopChatMessage(String taskId, String user) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient停止对话消息- 指定者:
stopChatMessage在接口中DifyChatClient- 参数:
taskId- 任务 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
feedbackMessage
public SimpleResponse feedbackMessage(String messageId, String rating, String user, String content) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient消息反馈(点赞)- 指定者:
feedbackMessage在接口中DifyChatClient- 参数:
messageId- 消息 IDrating- 评分user- 用户标识content- 内容- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getSuggestedQuestions
public SuggestedQuestionsResponse getSuggestedQuestions(String messageId, String user) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient获取下一轮建议问题列表- 指定者:
getSuggestedQuestions在接口中DifyChatClient- 参数:
messageId- 消息 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getMessages
public MessageListResponse getMessages(String conversationId, String user, String firstId, Integer limit) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient获取会话历史消息- 指定者:
getMessages在接口中DifyChatClient- 参数:
conversationId- 会话 IDuser- 用户标识firstId- 当前页第一条聊天记录的 IDlimit- 一次请求返回多少条聊天记录- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getConversations
public ConversationListResponse getConversations(String user, String lastId, Integer limit, String sortBy) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient获取会话列表- 指定者:
getConversations在接口中DifyChatClient- 参数:
user- 用户标识lastId- 当前页最后面一条记录的 IDlimit- 一次请求返回多少条记录sortBy- 排序字段- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
deleteConversation
public SimpleResponse deleteConversation(String conversationId, String user) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient删除会话- 指定者:
deleteConversation在接口中DifyChatClient- 参数:
conversationId- 会话 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
renameConversation
public Conversation renameConversation(String conversationId, String name, Boolean autoGenerate, String user) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient会话重命名- 指定者:
renameConversation在接口中DifyChatClient- 参数:
conversationId- 会话 IDname- 名称autoGenerate- 自动生成标题user- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
audioToText
从接口复制的说明:DifyChatClient语音转文字- 指定者:
audioToText在接口中DifyChatClient- 参数:
file- 文件user- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
audioToText
public AudioToTextResponse audioToText(InputStream inputStream, String fileName, String user) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient语音转文字- 指定者:
audioToText在接口中DifyChatClient- 参数:
inputStream- 输入流fileName- 文件名user- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
textToAudio
public byte[] textToAudio(String messageId, String text, String user) throws IOException, DifyApiException 从接口复制的说明:DifyChatClient文字转语音- 指定者:
textToAudio在接口中DifyChatClient- 指定者:
textToAudio在接口中DifyCompletionClient- 参数:
messageId- 消息 IDtext- 文本user- 用户标识- 返回:
- 音频数据
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getAppMeta
从接口复制的说明:DifyChatClient获取应用元数据- 指定者:
getAppMeta在接口中DifyChatClient- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
sendCompletionMessage
public CompletionResponse sendCompletionMessage(CompletionRequest request) throws IOException, DifyApiException 从接口复制的说明:DifyCompletionClient发送文本生成请求(阻塞模式)- 指定者:
sendCompletionMessage在接口中DifyCompletionClient- 参数:
request- 请求- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
sendCompletionMessageStream
public void sendCompletionMessageStream(CompletionRequest request, CompletionStreamCallback callback) throws IOException, DifyApiException 从接口复制的说明:DifyCompletionClient发送文本生成请求(流式模式)- 指定者:
sendCompletionMessageStream在接口中DifyCompletionClient- 参数:
request- 请求callback- 回调- 抛出:
IOException- IO异常DifyApiException- API异常
-
stopCompletion
public SimpleResponse stopCompletion(String taskId, String user) throws IOException, DifyApiException 从接口复制的说明:DifyCompletionClient停止文本生成- 指定者:
stopCompletion在接口中DifyCompletionClient- 参数:
taskId- 任务 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
runWorkflow
public WorkflowRunResponse runWorkflow(WorkflowRunRequest request) throws IOException, DifyApiException 从接口复制的说明:DifyWorkflowClient执行工作流(阻塞模式)- 指定者:
runWorkflow在接口中DifyWorkflowClient- 参数:
request- 请求- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
runWorkflowStream
public void runWorkflowStream(WorkflowRunRequest request, WorkflowStreamCallback callback) throws IOException, DifyApiException 从接口复制的说明:DifyWorkflowClient执行工作流(流式模式)- 指定者:
runWorkflowStream在接口中DifyWorkflowClient- 参数:
request- 请求callback- 回调- 抛出:
IOException- IO异常DifyApiException- API异常
-
stopWorkflow
public WorkflowStopResponse stopWorkflow(String taskId, String user) throws IOException, DifyApiException 从接口复制的说明:DifyWorkflowClient停止工作流- 指定者:
stopWorkflow在接口中DifyWorkflowClient- 参数:
taskId- 任务 IDuser- 用户标识- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getWorkflowRun
public WorkflowRunStatusResponse getWorkflowRun(String workflowRunId) throws IOException, DifyApiException 获取工作流运行状态- 指定者:
getWorkflowRun在接口中DifyWorkflowClient- 参数:
workflowRunId- 工作流运行实例 ID(从工作流执行响应中获得的运行实例标识)- 返回:
- 工作流执行状态响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getWorkflowLogs
public WorkflowLogsResponse getWorkflowLogs(String keyword, String status, Integer page, Integer limit) throws IOException, DifyApiException 从接口复制的说明:DifyWorkflowClient获取工作流日志- 指定者:
getWorkflowLogs在接口中DifyWorkflowClient- 参数:
keyword- 关键字status- 状态page- 页码limit- 每页条数- 返回:
- 日志列表
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getAnnotations
public AnnotationListResponse getAnnotations(Integer page, Integer limit) throws IOException, DifyApiException 获取标注列表- 指定者:
getAnnotations在接口中DifyChatClient- 参数:
page- 页码limit- 每页数量- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
saveAnnotation
public Annotation saveAnnotation(String question, String answer) throws IOException, DifyApiException 创建标注- 指定者:
saveAnnotation在接口中DifyChatClient- 参数:
question- 问题answer- 答案内容- 返回:
- 标注
- 抛出:
IOException- IO异常DifyApiException- API异常
-
updateAnnotation
public Annotation updateAnnotation(String annotationId, String question, String answer) throws IOException, DifyApiException 更新标注- 指定者:
updateAnnotation在接口中DifyChatClient- 参数:
annotationId- 标注 IDquestion- 问题answer- 答案内容- 返回:
- 标注
- 抛出:
IOException- IO异常DifyApiException- API异常
-
deleteAnnotation
删除标注- 指定者:
deleteAnnotation在接口中DifyChatClient- 参数:
annotationId- 标注 ID- 返回:
- 响应
- 抛出:
IOException- IO异常DifyApiException- API异常
-
annotationReply
public AnnotationReply annotationReply(String action, String embeddingProviderName, String embeddingModelName, Integer scoreThreshold) throws IOException, DifyApiException 标注回复初始设置- 指定者:
annotationReply在接口中DifyChatClient- 参数:
action- 动作,只能是 'enable' 或 'disable'embeddingProviderName- 指定的嵌入模型提供商, 必须先在系统内设定好接入的模型,对应的是provider字段embeddingModelName- 指定的嵌入模型,对应的是model字段scoreThreshold- 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复- 返回:
- 标注回复
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getAnnotationReply
public AnnotationReply getAnnotationReply(String action, String jobId) throws IOException, DifyApiException 查询标注回复初始设置任务状态- 指定者:
getAnnotationReply在接口中DifyChatClient- 参数:
action- 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致jobId- 任务 ID,从标注回复初始设置接口返回的 jobId- 返回:
- 标注回复
- 抛出:
IOException- IO异常DifyApiException- API异常
-
getConversationVariables
public VariableResponse getConversationVariables(String conversationId, String user, String lastId, Integer limit, String variableName) throws DifyApiException, IOException 获取对话变量 从特定对话中检索变量。此端点对于提取对话过程中捕获的结构化数据非常有用。- 指定者:
getConversationVariables在接口中DifyChatClient- 参数:
conversationId- 会话 IDuser- 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。重要说明: Service API 不共享 WebApp 创建的对话。通过 API 创建的对话与 WebApp 界面中创建的对话是相互隔离的。lastId- (选填)当前页最后面一条记录的 ID,默认 null。limit- 一次请求返回多少条记录,默认 20 条,最大 100 条,最小 1 条。variableName- (选填)按变量名称筛选。- 返回:
- 抛出:
DifyApiExceptionIOException
-