diff --git a/Cargo.lock b/Cargo.lock index be01e43f31..e394acc988 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4254,6 +4254,7 @@ dependencies = [ "file_to_base64_url", "filesys", "futures 0.3.31", + "serde", "testing", "tokio", "url", diff --git a/crates/lib/api_clients/fal_client/Cargo.toml b/crates/lib/api_clients/fal_client/Cargo.toml index da1581d083..902940c758 100644 --- a/crates/lib/api_clients/fal_client/Cargo.toml +++ b/crates/lib/api_clients/fal_client/Cargo.toml @@ -25,6 +25,7 @@ anyhow = { workspace = true } chrono = { workspace = true } fal = { version = "0.3.6", features = ["endpoints"] } futures = { workspace = true } +serde = { workspace = true } tokio = { workspace = true } url = { workspace = true } diff --git a/crates/lib/api_clients/fal_client/src/lib.rs b/crates/lib/api_clients/fal_client/src/lib.rs index 82d82db2bd..69d90419cb 100644 --- a/crates/lib/api_clients/fal_client/src/lib.rs +++ b/crates/lib/api_clients/fal_client/src/lib.rs @@ -1,7 +1,10 @@ //! A wrapper for the "fal" crate that bakes in a few extra recipes and utilities. +// Re-export extern crate fal; + pub mod creds; pub mod fal_error_plus; pub mod requests; +pub mod utils; diff --git a/crates/lib/api_clients/fal_client/src/requests/kling_16_image_to_video.rs b/crates/lib/api_clients/fal_client/src/requests/kling_16_image_to_video.rs index 182a1c5023..153286152f 100644 --- a/crates/lib/api_clients/fal_client/src/requests/kling_16_image_to_video.rs +++ b/crates/lib/api_clients/fal_client/src/requests/kling_16_image_to_video.rs @@ -7,6 +7,8 @@ use fal_client::file_to_base64_url::file_to_base64_url; use futures::StreamExt; use std::path::Path; use chrono::Utc; +use fal::endpoints::fal_ai::kling_video::v1::pro::effects::I2VOutput; +use fal::queue::Queue; use url::Url; pub struct Kling16Args<'a, P: AsRef> { @@ -28,7 +30,7 @@ pub enum Kling16Duration { pub async fn kling_16_image_to_video>(args: Kling16Args<'_, P>) -> Result { println!("Image to base64... {:?}", Utc::now().format("%Y-%m-%dT%H:%M:%S").to_string()); std::io::stdout().flush().unwrap(); - + let image_url = file_to_base64_url(args.image_path)?; /* @@ -36,7 +38,7 @@ pub async fn kling_16_image_to_video>(args: Kling16Args<'_, P>) - FalError(FalError(Other("{\"detail\": \"Invalid Key Authorization header format. Expected ':'.\"}"))) FalError(FalError(Other("{\"detail\": \"No user found for Key ID and Secret\"}"))) */ - + let duration = match args.duration{ Kling16Duration::Default => None, Kling16Duration::FiveSeconds => Some("5".to_string()), @@ -55,15 +57,24 @@ pub async fn kling_16_image_to_video>(args: Kling16Args<'_, P>) - println!("Sending request... {:?}", Utc::now().format("%Y-%m-%dT%H:%M:%S").to_string()); std::io::stdout().flush().unwrap(); - + let result = image_to_video(request) .with_api_key(&args.api_key.0) .queue() .await?; + + let payload = result.payload; + + let test : Queue = Queue::new(; + result.client().clone(), + result.endpoint(), + args.api_key.0.clone(), + result.payload().clone(), + ); println!("Result... {:?} - {:?}", result, Utc::now().format("%Y-%m-%dT%H:%M:%S").to_string()); std::io::stdout().flush().unwrap(); - + let mut stream = result.stream(true).await?; let mut i = 0; @@ -74,13 +85,13 @@ pub async fn kling_16_image_to_video>(args: Kling16Args<'_, P>) - if status.status == Status::Completed { break; } - + if i > 5 { return Err(FalErrorPlus::FalError( fal::prelude::FalError::Other("Timed out waiting for video to be created".to_string()), )); } - + i+= 1; } @@ -112,7 +123,7 @@ mod tests { let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?; let api_key = FalApiKey::from_str(&secret); - + let args = Kling16Args { image_path: image, api_key: &api_key, diff --git a/crates/lib/api_clients/fal_client/src/utils/clone_queue_payload.rs b/crates/lib/api_clients/fal_client/src/utils/clone_queue_payload.rs new file mode 100644 index 0000000000..f2b2da137d --- /dev/null +++ b/crates/lib/api_clients/fal_client/src/utils/clone_queue_payload.rs @@ -0,0 +1,6 @@ +use fal::queue::{Queue, QueueResponse}; +use serde::de::DeserializeOwned; + +pub fn clone_queue_payload(payload: &Queue) -> QueueResponse { + // TODO... +} \ No newline at end of file diff --git a/crates/lib/api_clients/fal_client/src/utils/clone_queue_response.rs b/crates/lib/api_clients/fal_client/src/utils/clone_queue_response.rs new file mode 100644 index 0000000000..8caee7302e --- /dev/null +++ b/crates/lib/api_clients/fal_client/src/utils/clone_queue_response.rs @@ -0,0 +1,10 @@ +use fal::queue::QueueResponse; + +pub fn clone_queue_response(response: &QueueResponse) -> QueueResponse { + QueueResponse { + request_id: response.request_id.clone(), + response_url: response.response_url.clone(), + status_url: response.status_url.clone(), + cancel_url: response.cancel_url.clone(), + } +} diff --git a/crates/lib/api_clients/fal_client/src/utils/mod.rs b/crates/lib/api_clients/fal_client/src/utils/mod.rs new file mode 100644 index 0000000000..5a429ca78e --- /dev/null +++ b/crates/lib/api_clients/fal_client/src/utils/mod.rs @@ -0,0 +1,2 @@ +pub mod clone_queue_payload; +mod clone_queue_response; \ No newline at end of file