mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-14 05:42:32 +00:00
refactor enum
This commit is contained in:
1 parent
de6a9a25cd
commit
cb7c854d9e
8 files changed
+29
-29
No files matched your search
@@ -5,7 +5,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
/// In the case a model doesn't support the resolution, gracefully pick the nearest option.
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CommonVideoResolution {
|
||||
pub enum CommonResolution {
|
||||
/// Models: Nano Banana Pro
|
||||
OneK,
|
||||
/// Models: Nano Banana Pro
|
||||
|
||||
+10
-10
@@ -37,12 +37,12 @@ pub(crate) fn estimate_image_cost_artcraft_nano_banana_pro(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::api::common_image_model::CommonImageModel;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_resolution::CommonResolution;
|
||||
use crate::api::provider::Provider;
|
||||
use crate::client::request_mismatch_mitigation_strategy::RequestMismatchMitigationStrategy;
|
||||
use crate::generate::generate_image::generate_image_request::GenerateImageRequest;
|
||||
|
||||
fn estimate_usd_cents(resolution: Option<CommonVideoResolution>, image_batch_count: u16) -> u64 {
|
||||
fn estimate_usd_cents(resolution: Option<CommonResolution>, image_batch_count: u16) -> u64 {
|
||||
let request = GenerateImageRequest {
|
||||
model: CommonImageModel::NanaBananaPro,
|
||||
provider: Provider::Artcraft,
|
||||
@@ -65,15 +65,15 @@ mod tests {
|
||||
fn test_estimate_cost_usd_cents() {
|
||||
// 1K/2K: $0.15/image = 15 cents
|
||||
assert_eq!(estimate_usd_cents(None, 1), 15);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::OneK), 1), 15);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::TwoK), 1), 15);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::OneK), 2), 30);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::OneK), 3), 45);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::OneK), 4), 60);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::OneK), 1), 15);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::TwoK), 1), 15);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::OneK), 2), 30);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::OneK), 3), 45);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::OneK), 4), 60);
|
||||
|
||||
// 4K: $0.30/image = 30 cents
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::FourK), 1), 30);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::FourK), 2), 60);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonVideoResolution::FourK), 4), 120);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::FourK), 1), 30);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::FourK), 2), 60);
|
||||
assert_eq!(estimate_usd_cents(Some(CommonResolution::FourK), 4), 120);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -35,7 +35,7 @@ pub async fn execute_artcraft_nano_banana_pro(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_resolution::CommonResolution;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::generate::generate_image::generate_image_request::GenerateImageRequest;
|
||||
use crate::generate::generate_image::image_generation_plan::ImageGenerationPlan;
|
||||
@@ -48,7 +48,7 @@ mod tests {
|
||||
let client = get_artcraft_client();
|
||||
let request = GenerateImageRequest {
|
||||
aspect_ratio: Some(CommonAspectRatio::WideSixteenByNine),
|
||||
resolution: Some(CommonVideoResolution::OneK),
|
||||
resolution: Some(CommonResolution::OneK),
|
||||
image_batch_count: Some(1),
|
||||
prompt: Some("a cat walking through a cyberpunk city at night"),
|
||||
..base_image_request()
|
||||
@@ -70,7 +70,7 @@ mod tests {
|
||||
let client = get_artcraft_client();
|
||||
let request = GenerateImageRequest {
|
||||
aspect_ratio: Some(CommonAspectRatio::Square),
|
||||
resolution: Some(CommonVideoResolution::OneK),
|
||||
resolution: Some(CommonResolution::OneK),
|
||||
image_batch_count: Some(4),
|
||||
prompt: Some("a dog surfing a wave, cinematic"),
|
||||
..base_image_request()
|
||||
@@ -101,7 +101,7 @@ mod tests {
|
||||
prompt: Some("Add the man in the first image into the fantasy scene in the second image. Keep his hoodie and attire, but match the vibe of the fantasy scene."),
|
||||
image_inputs: Some(ImageListRef::MediaFileTokens(&image_tokens)),
|
||||
aspect_ratio: Some(CommonAspectRatio::Auto), // edit mode: preserve source dimensions
|
||||
resolution: Some(CommonVideoResolution::OneK),
|
||||
resolution: Some(CommonResolution::OneK),
|
||||
image_batch_count: Some(1),
|
||||
..base_image_request()
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::common_image_model::CommonImageModel;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_resolution::CommonResolution;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::api::provider::Provider;
|
||||
use crate::client::request_mismatch_mitigation_strategy::RequestMismatchMitigationStrategy;
|
||||
@@ -24,7 +24,7 @@ pub struct GenerateImageRequest<'a> {
|
||||
pub image_inputs: Option<ImageListRef<'a>>,
|
||||
|
||||
/// The resolution to use.
|
||||
pub resolution: Option<CommonVideoResolution>,
|
||||
pub resolution: Option<CommonResolution>,
|
||||
|
||||
/// The aspect ratio to use.
|
||||
pub aspect_ratio: Option<CommonAspectRatio>,
|
||||
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_resolution::CommonResolution;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::client::request_mismatch_mitigation_strategy::RequestMismatchMitigationStrategy;
|
||||
use crate::errors::artcraft_router_error::ArtcraftRouterError;
|
||||
@@ -120,10 +120,10 @@ fn nearest_aspect_ratio(aspect_ratio: CommonAspectRatio) -> NanoBananaProMultiFu
|
||||
}
|
||||
|
||||
fn plan_resolution(
|
||||
resolution: Option<CommonVideoResolution>,
|
||||
resolution: Option<CommonResolution>,
|
||||
_strategy: RequestMismatchMitigationStrategy,
|
||||
) -> Result<Option<NanoBananaProMultiFunctionImageGenImageResolution>, ArtcraftRouterError> {
|
||||
use CommonVideoResolution as R;
|
||||
use CommonResolution as R;
|
||||
use NanoBananaProMultiFunctionImageGenImageResolution as NbpRes;
|
||||
match resolution {
|
||||
None => Ok(None),
|
||||
@@ -168,7 +168,7 @@ fn plan_num_images(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_resolution::CommonResolution;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::errors::artcraft_router_error::ArtcraftRouterError;
|
||||
use crate::errors::client_error::ClientError;
|
||||
@@ -318,9 +318,9 @@ mod tests {
|
||||
#[test]
|
||||
fn resolution_direct_mappings() {
|
||||
let cases = [
|
||||
(CommonVideoResolution::OneK, NbpRes::OneK),
|
||||
(CommonVideoResolution::TwoK, NbpRes::TwoK),
|
||||
(CommonVideoResolution::FourK, NbpRes::FourK),
|
||||
(CommonResolution::OneK, NbpRes::OneK),
|
||||
(CommonResolution::TwoK, NbpRes::TwoK),
|
||||
(CommonResolution::FourK, NbpRes::FourK),
|
||||
];
|
||||
for (common, expected) in cases {
|
||||
let request = GenerateImageRequest { resolution: Some(common), ..base_image_request() };
|
||||
@@ -335,7 +335,7 @@ mod tests {
|
||||
#[test]
|
||||
fn resolution_three_k_falls_back_to_two_k() {
|
||||
let request = GenerateImageRequest {
|
||||
resolution: Some(CommonVideoResolution::ThreeK),
|
||||
resolution: Some(CommonResolution::ThreeK),
|
||||
..base_image_request()
|
||||
};
|
||||
let ImageGenerationPlan::ArtcraftNanaBananaPro(plan) = request.build().unwrap();
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
use crate::api::common_aspect_ratio::CommonAspectRatio;
|
||||
use crate::api::common_resolution::CommonVideoResolution;
|
||||
use crate::api::common_resolution::CommonResolution;
|
||||
use crate::api::common_video_model::CommonVideoModel;
|
||||
use crate::api::image_list_ref::ImageListRef;
|
||||
use crate::api::image_ref::ImageRef;
|
||||
@@ -32,7 +32,7 @@ pub struct GenerateVideoRequest<'a> {
|
||||
pub reference_images: Option<ImageListRef<'a>>,
|
||||
|
||||
/// The resolution to use
|
||||
pub resolution: Option<CommonVideoResolution>,
|
||||
pub resolution: Option<CommonResolution>,
|
||||
|
||||
/// The aspect ratio to use
|
||||
pub aspect_ratio: Option<CommonAspectRatio>,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Common video resolutions.
|
||||
/// Mirrors artcraft_router::api::common_resolution::CommonVideoResolution.
|
||||
/// Mirrors artcraft_router::api::common_resolution::CommonResolution.
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CommonVideoResolution {
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ use artcraft_api_defs::generate::cost_estimate::estimate_video_cost::{
|
||||
EstimateVideoCostResponse,
|
||||
};
|
||||
use artcraft_router::api::common_aspect_ratio::CommonAspectRatio as RouterAspectRatio;
|
||||
use artcraft_router::api::common_resolution::CommonVideoResolution as RouterResolution;
|
||||
use artcraft_router::api::common_resolution::CommonResolution as RouterResolution;
|
||||
use artcraft_router::api::common_video_model::CommonVideoModel as RouterVideoModel;
|
||||
use artcraft_router::api::provider::Provider as RouterProvider;
|
||||
use artcraft_router::client::request_mismatch_mitigation_strategy::RequestMismatchMitigationStrategy;
|
||||
|
||||
Reference in new issue
Block a user