mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
imgref
This commit is contained in:
1 parent
1e000e8163
commit
9949178a4b
7 files changed
+40
-47
No files matched your search
@@ -0,0 +1,6 @@
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
pub enum ImageListRef<'a> {
|
||||
MediaFileTokens(&'a Vec<MediaFileToken>),
|
||||
Urls(&'a Vec<String>),
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
pub enum ImageRef<'a> {
|
||||
MediaFileToken(&'a MediaFileToken),
|
||||
Url(&'a str),
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
pub mod common_aspect_ratio;
|
||||
pub mod common_resolution;
|
||||
pub mod common_video_model;
|
||||
pub mod image_list_ref;
|
||||
pub mod image_ref;
|
||||
pub mod provider;
|
||||
@@ -18,10 +18,6 @@ impl Display for ClientType {
|
||||
pub enum ClientError {
|
||||
/// The requested client is not configured on the RouterClient.
|
||||
ClientNotConfigured(ClientType),
|
||||
|
||||
/// Both a URL and a media token were supplied for the same field.
|
||||
/// The field name is included for debugging.
|
||||
UrlAndMediaTokenSupplied(String),
|
||||
}
|
||||
|
||||
impl Error for ClientError {}
|
||||
@@ -32,9 +28,6 @@ impl Display for ClientError {
|
||||
Self::ClientNotConfigured(client_type) => {
|
||||
write!(f, "{} client is not configured on the RouterClient", client_type)
|
||||
}
|
||||
Self::UrlAndMediaTokenSupplied(field) => {
|
||||
write!(f, "Both a URL and a media token were supplied for '{}'; supply only one", field)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-3
@@ -1,4 +1,6 @@
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::image_ref::ImageRef;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::client::router_artcraft_client::RouterArtcraftClient;
|
||||
use crate::errors::artcraft_router_error::ArtcraftRouterError;
|
||||
use crate::errors::provider_error::ProviderError;
|
||||
@@ -40,12 +42,25 @@ pub async fn generate_video_artcraft_seedance2p0(
|
||||
_ => Seedance2p0BatchCount::One,
|
||||
};
|
||||
|
||||
let start_frame_media_token = match &request.start_frame {
|
||||
Some(ImageRef::MediaFileToken(t)) => Some((*t).to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
let end_frame_media_token = match &request.end_frame {
|
||||
Some(ImageRef::MediaFileToken(t)) => Some((*t).to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
let reference_image_media_tokens = match &request.reference_images {
|
||||
Some(ImageListRef::MediaFileTokens(tokens)) => Some((*tokens).to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let request = Seedance2p0MultiFunctionVideoGenRequest {
|
||||
uuid_idempotency_token,
|
||||
prompt,
|
||||
start_frame_media_token: request.start_frame_media_token.map(|t| t.to_owned()),
|
||||
end_frame_media_token: request.end_frame_media_token.map(|t| t.to_owned()),
|
||||
reference_image_media_tokens: request.reference_image_media_tokens.map(|tokens| tokens.to_owned()),
|
||||
start_frame_media_token,
|
||||
end_frame_media_token,
|
||||
reference_image_media_tokens,
|
||||
aspect_ratio,
|
||||
duration_seconds: None,
|
||||
batch_count: Some(batch_count),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::api::common_video_model::CommonVideoModel;
|
||||
use crate::api::provider::Provider;
|
||||
use crate::errors::artcraft_router_error::ArtcraftRouterError;
|
||||
use crate::errors::client_error::ClientError;
|
||||
use crate::generate::generate_video::execute::artcraft::generate_video_artcraft_seedance2p0::generate_video_artcraft_seedance2p0;
|
||||
use crate::generate::generate_video::generate_video_request::GenerateVideoRequest;
|
||||
use tokens::tokens::generic_inference_jobs::InferenceJobToken;
|
||||
@@ -14,23 +13,9 @@ pub struct GenerateVideoResponse {
|
||||
pub all_inference_job_tokens: Vec<InferenceJobToken>,
|
||||
}
|
||||
|
||||
fn validate_request(args: &GenerateVideoRequest<'_>) -> Result<(), ClientError> {
|
||||
if args.start_frame_url.is_some() && args.start_frame_media_token.is_some() {
|
||||
return Err(ClientError::UrlAndMediaTokenSupplied("start_frame".to_string()));
|
||||
}
|
||||
if args.end_frame_url.is_some() && args.end_frame_media_token.is_some() {
|
||||
return Err(ClientError::UrlAndMediaTokenSupplied("end_frame".to_string()));
|
||||
}
|
||||
if args.reference_image_urls.is_some() && args.reference_image_media_tokens.is_some() {
|
||||
return Err(ClientError::UrlAndMediaTokenSupplied("reference_images".to_string()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn generate_video(
|
||||
args: &GenerateVideoRequest<'_>,
|
||||
) -> Result<GenerateVideoResponse, ArtcraftRouterError> {
|
||||
validate_request(args)?;
|
||||
|
||||
match args.provider {
|
||||
Provider::Artcraft => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_video_model::CommonVideoModel;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::api::image_ref::ImageRef;
|
||||
use crate::api::provider::Provider;
|
||||
use crate::client::router_client::RouterClient;
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use crate::client::request_mismatch_mitigation_strategy::RequestMismatchMitigationStrategy;
|
||||
|
||||
pub struct GenerateVideoRequest<'a> {
|
||||
@@ -19,29 +20,14 @@ pub struct GenerateVideoRequest<'a> {
|
||||
// /// Some models support negative prompts
|
||||
// pub negative_prompt: Option<String>,
|
||||
|
||||
/// Starting keyframe (optional). Must be a URL.
|
||||
/// Mutually exclusive with `start_frame_media_token`.
|
||||
pub start_frame_url: Option<&'a str>,
|
||||
/// Starting keyframe (optional).
|
||||
pub start_frame: Option<ImageRef<'a>>,
|
||||
|
||||
/// Starting keyframe as a media token (optional).
|
||||
/// Mutually exclusive with `start_frame_url`.
|
||||
pub start_frame_media_token: Option<&'a MediaFileToken>,
|
||||
/// Ending keyframe (optional).
|
||||
pub end_frame: Option<ImageRef<'a>>,
|
||||
|
||||
/// Ending keyframe (optional). Must be a URL.
|
||||
/// Mutually exclusive with `end_frame_media_token`.
|
||||
pub end_frame_url: Option<&'a str>,
|
||||
|
||||
/// Ending keyframe as a media token (optional).
|
||||
/// Mutually exclusive with `end_frame_url`.
|
||||
pub end_frame_media_token: Option<&'a MediaFileToken>,
|
||||
|
||||
/// Reference image URLs (optional).
|
||||
/// Mutually exclusive with `reference_image_media_tokens`.
|
||||
pub reference_image_urls: Option<&'a Vec<String>>,
|
||||
|
||||
/// Reference image media tokens (optional).
|
||||
/// Mutually exclusive with `reference_image_urls`.
|
||||
pub reference_image_media_tokens: Option<&'a Vec<MediaFileToken>>,
|
||||
/// Reference images (optional).
|
||||
pub reference_images: Option<ImageListRef<'a>>,
|
||||
|
||||
/// The resolution to use
|
||||
pub resolution: Option<CommonVideoResolution>,
|
||||
|
||||
Reference in new issue
Block a user