Module api

Source
Expand description

This module provides a client for interacting with the Dify API.

The Api struct in this module allows you to send requests to the Dify API and handle the responses. It provides methods for various API endpoints such as sending chat messages, uploading files, and executing workflows. The module also defines several request and response structs that are used for interacting with the API.

§Example

use dify_client::api::Api;
use dify_client::request::ChatMessagesRequest;

#[tokio::main]
async fn main() {
    // Create a client for interacting with the Dify API
    let client = dify_client::Client::new("https://api.dify.ai", "API_KEY");

    // Create an API instance using the client
    let api = Api::new(&client);

    // Create a chat message request
    let request = ChatMessagesRequest {
        query: "What is the weather today?".to_string(),
        user: "user123".to_string(),
        ..Default::default()  
    };

    // Send the chat message request and get the response
    let response = api.chat_messages(request).await;

    // Handle the response
    match response {
        Ok(response) => {
            // Do something with the response
            println!("Chat message sent successfully: {:?}", response);
        }
        Err(error) => {
            // Handle the error
            eprintln!("Failed to send chat message: {}", error);
        }
    }
}

This module provides a client for interacting with the Dify API.

Structs§

Api
Dify API

Enums§

ApiPath
API 路径