From 1fff0e232e26ca27e513b7d2473dc884af81538d Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 4 Jun 2025 21:38:27 -0400 Subject: [PATCH] more fal endpoints wip --- .../fal_client/src/requests/webhook/mod.rs | 3 +- .../enqueue_hunyuan2_image_to_3d_webhook.rs | 83 +++++++++++++++++++ .../src/requests/webhook/object/mod.rs | 1 + 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 crates/lib/api_clients/fal_client/src/requests/webhook/object/enqueue_hunyuan2_image_to_3d_webhook.rs create mode 100644 crates/lib/api_clients/fal_client/src/requests/webhook/object/mod.rs diff --git a/crates/lib/api_clients/fal_client/src/requests/webhook/mod.rs b/crates/lib/api_clients/fal_client/src/requests/webhook/mod.rs index 82a9d3c9e0..bdff0ae763 100644 --- a/crates/lib/api_clients/fal_client/src/requests/webhook/mod.rs +++ b/crates/lib/api_clients/fal_client/src/requests/webhook/mod.rs @@ -1,2 +1,3 @@ pub mod image; -pub mod video; \ No newline at end of file +pub mod video; +mod object; \ No newline at end of file diff --git a/crates/lib/api_clients/fal_client/src/requests/webhook/object/enqueue_hunyuan2_image_to_3d_webhook.rs b/crates/lib/api_clients/fal_client/src/requests/webhook/object/enqueue_hunyuan2_image_to_3d_webhook.rs new file mode 100644 index 0000000000..345c12c5da --- /dev/null +++ b/crates/lib/api_clients/fal_client/src/requests/webhook/object/enqueue_hunyuan2_image_to_3d_webhook.rs @@ -0,0 +1,83 @@ +use crate::creds::fal_api_key::FalApiKey; +use crate::error::classify_fal_error::classify_fal_error; +use crate::error::fal_error_plus::FalErrorPlus; +use fal::endpoints::fal_ai::kling_video::v1_6::pro::image_to_video::{image_to_video, ProImageToVideoRequest}; +use fal::webhook::WebhookResponse; +use reqwest::IntoUrl; + +pub struct Kling16Args<'a, U: IntoUrl, V: IntoUrl> { + pub image_url: U, + pub webhook_url: V, + pub prompt: &'a str, + pub api_key: &'a FalApiKey, + pub duration: Kling16Duration, +} + +#[derive(Copy, Clone, Debug)] +pub enum Kling16Duration { + Default, + FiveSeconds, + TenSeconds, +} + +pub async fn enqueue_kling_16_image_to_video_webhook( + args: Kling16Args<'_, U, V> +) -> Result { + let duration = match args.duration { + Kling16Duration::Default => None, + Kling16Duration::FiveSeconds => Some("5".to_string()), // Gross... + Kling16Duration::TenSeconds => Some("10".to_string()), + }; + + let image_url = args.image_url.as_str().to_string(); + + let request = ProImageToVideoRequest { + image_url, + prompt: args.prompt.to_string(), + aspect_ratio: None, + cfg_scale: None, + duration, + negative_prompt: None, + tail_image_url: None, + }; + + let result = image_to_video(request) + .with_api_key(&args.api_key.0) + .queue_webhook(args.webhook_url) + .await; + + result.map_err(|err| classify_fal_error(err)) +} + +/* +#[cfg(test)] +mod tests { + use crate::creds::fal_api_key::FalApiKey; + use crate::requests::webhook::video::enqueue_kling_16_image_to_video_webhook::{enqueue_kling_16_image_to_video_webhook, Kling16Args, Kling16Duration}; + use errors::AnyhowResult; + use std::fs::read_to_string; + use testing::test_file_path::test_file_path; + + #[tokio::test] + #[ignore] + async fn test_kling16_video() -> AnyhowResult<()> { + let image = test_file_path("test_data/image/juno.jpg")?; + + // XXX: Don't commit secrets! + 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, + prompt: "a corgi looks out over the water", + api_key: &api_key, + duration: Kling16Duration::Default, + }; + + let result = enqueue_kling_16_image_to_video_webhook(args).await?; + + Ok(()) + } +} +*/ \ No newline at end of file diff --git a/crates/lib/api_clients/fal_client/src/requests/webhook/object/mod.rs b/crates/lib/api_clients/fal_client/src/requests/webhook/object/mod.rs new file mode 100644 index 0000000000..ca65e4d859 --- /dev/null +++ b/crates/lib/api_clients/fal_client/src/requests/webhook/object/mod.rs @@ -0,0 +1 @@ +pub mod enqueue_hunyuan2_image_to_3d_webhook; \ No newline at end of file