Module response

Source
Expand description

This module contains the response structures used in the Dify SDK.

It includes error responses, result responses, chat message responses, and more. These structures are used to deserialize JSON responses from the Dify API.

§Examples

Deserialize an error response:

use dify_client::response::ErrorResponse;

let json = r#"
    {
        "code": "unknown_error",
        "message": "An unknown error occurred",
        "status": 503
    }
"#;

let error_response: ErrorResponse = serde_json::from_str(json).unwrap();

assert_eq!(error_response.code, "unknown_error");
assert_eq!(error_response.message, "An unknown error occurred");
assert_eq!(error_response.status, 503);

Deserialize a chat message response:

use dify_client::response::{ChatMessagesResponse, AppMode};
use serde_json::json;
use std::collections::HashMap;

let json = r#"
    {
        "base": {
            "message_id": "12345",
            "conversation_id": "67890",
            "created_at": 1705395332
        },
        "event": "message",
        "mode": "chat",
        "answer": "Hello, how can I help you?",
        "metadata": {
            "key1": "value1",
            "key2": "value2"
        }
    }
"#;

let mut metadata = HashMap::new();
metadata.insert("key1".to_string(), json!("value1"));
metadata.insert("key2".to_string(), json!("value2"));

let chat_response: ChatMessagesResponse = serde_json::from_str(json).unwrap();

assert_eq!(chat_response.base.message_id, "12345");
assert_eq!(chat_response.base.conversation_id.unwrap(), "67890");
assert_eq!(chat_response.base.created_at, 1705395332);
assert_eq!(chat_response.event, "message");
assert_eq!(chat_response.mode, AppMode::Chat);
assert_eq!(chat_response.answer, "Hello, how can I help you?");
assert_eq!(chat_response.metadata, metadata);

Structs§

AudioToTextResponse
语音转文字响应
ChatMessagesResponse
发送对话消息的响应
CompletionMessagesResponse
文本生成的响应
ConversationData
会话数据
ConversationsResponse
获取会话列表的响应
ErrorResponse
错误响应
ExecutionMetadata
执行节点元数据
FilesUploadResponse
上传文件响应
MessageBase
对话基础信息
MessageData
历史消息数据
MessageFeedback
历史消息数据中的反馈信息
MessageFile
历史消息数据中的文件信息
MessagesResponse
获取会话历史消息的响应
MessagesSuggestedResponse
获取下一轮建议问题列表的响应
MetaResponse
获取应用Meta信息的响应
NodeFinishedData
node 执行结束详细内容
NodeStartedData
node 详细内容
ParameterAnnotationReply
标记回复
ParameterRetrieverResource
引用和归属
ParameterSpeechToText
语音转文本
ParameterSuggestedQuestionsAfterAnswer
启用回答后给出推荐问题。
ParametersResponse
获取应用配置信息的响应
ResultResponse
通用结果响应
SseMessageEventStream
A Stream of SSE message events.
SystemParameters
系统参数
WorkflowFinishedData
workflow 执行结束详细内容
WorkflowStartedData
workflow 详细内容
WorkflowsRunResponse
执行 workflow 响应

Enums§

AppMode
应用类型
BelongsTo
文件归属方
FinishedStatus
执行结束状态
ParameterFileUploadItem
文件上传配置
ParameterUserInputFormItem
用户输入表单配置
SseMessageEvent
流式模式分块数据事件
ToolIcon
工具图标
TransferMethod
文件传递方式