dify_client/lib.rs
1//! Dify client library.
2//!
3//! # Examples
4//!
5//! ## Client with single api key
6//!
7//! ```no_run
8//! use dify_client::{request, Config, Client};
9//! use std::time::Duration;
10//!
11//! #[tokio::main]
12//! async fn main() {
13//! let config = Config {
14//! base_url: "https://api.dify.ai".into(),
15//! api_key: "API_KEY".into(),
16//! timeout: Duration::from_secs(60),
17//! };
18//! let client = Client::new_with_config(config);
19//!
20//! // Use the client
21//! let data = request::ChatMessagesRequest {
22//! query: "What are the specs of the iPhone 13 Pro Max?".into(),
23//! user: "afa".into(),
24//! ..Default::default()
25//! };
26//! let result = client.api().chat_messages(data).await;
27//! println!("{:?}", result);
28//! }
29//! ```
30//!
31//! ## Client with multiple api keys
32//!
33//! ```no_run
34//! use dify_client::{http::header, request, Config, Client};
35//! use std::time::Duration;
36//!
37//! #[tokio::main]
38//! async fn main() {
39//! let config = Config {
40//! base_url: "https://api.dify.ai".into(),
41//! api_key: "API_KEY_DEFAULT".into(),
42//! timeout: Duration::from_secs(100),
43//! };
44//! // The client can be safely shared across multiple threads
45//! let client = Client::new_with_config(config);
46//!
47//! // Use the client
48//! let data = request::ChatMessagesRequest {
49//! query: "What are the specs of the iPhone 13 Pro Max?".into(),
50//! user: "afa".into(),
51//! ..Default::default()
52//! };
53//! // Reuse the client with a new api key
54//! let mut api = client.api();
55//! let result = api.chat_messages(data.clone()).await;
56//! println!("{:?}", result);
57//! // Override the api key
58//! api.before_send(|mut req| {
59//! // rewrite the authorization header
60//! let mut auth = header::HeaderValue::from_static("Bearer API_KEY_OVERRIDE");
61//! auth.set_sensitive(true);
62//! req.headers_mut().insert(header::AUTHORIZATION, auth);
63//! req
64//! });
65//! let result = api.chat_messages(data).await;
66//! println!("{:?}", result);
67//! }
68//! ```
69//! For more API methods, refer to the [`Api`](api/struct.Api.html) struct.
70
71pub mod api;
72pub mod client;
73pub mod http;
74pub mod request;
75pub mod response;
76
77pub use client::*;