mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-07 18:42:10 +00:00
type juggle
This commit is contained in:
1 parent
3ab65db8b2
commit
2d8e7ed1fa
43 files changed
+385
-485
No files matched your search
Generated
+12
-1
@@ -679,6 +679,7 @@ dependencies = [
|
||||
"discord-rich-presence",
|
||||
"enums",
|
||||
"enums_api",
|
||||
"enums_convert",
|
||||
"enums_db",
|
||||
"errors",
|
||||
"filesys",
|
||||
@@ -3802,7 +3803,6 @@ dependencies = [
|
||||
name = "enums_api"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"enums_db",
|
||||
"enums_shared",
|
||||
"log",
|
||||
"serde",
|
||||
@@ -3814,6 +3814,16 @@ dependencies = [
|
||||
"workspace-build-acceleration",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enums_convert"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"enums_api",
|
||||
"enums_db",
|
||||
"serde_json",
|
||||
"workspace-build-acceleration",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enums_db"
|
||||
version = "0.0.1"
|
||||
@@ -11263,6 +11273,7 @@ dependencies = [
|
||||
"elasticsearch_schema",
|
||||
"enums",
|
||||
"enums_api",
|
||||
"enums_convert",
|
||||
"enums_db",
|
||||
"enums_public",
|
||||
"errors",
|
||||
|
||||
@@ -112,6 +112,7 @@ members = [
|
||||
"crates/schema/public/composite_identifiers",
|
||||
"crates/schema/public/enums",
|
||||
"crates/schema/public/enums_api",
|
||||
"crates/schema/public/enums_convert",
|
||||
"crates/schema/public/enums_db",
|
||||
"crates/schema/public/enums_shared",
|
||||
"crates/schema/public/enums_public",
|
||||
@@ -236,6 +237,7 @@ crockford = { path = "crates/lib/data/crockford" }
|
||||
easyenv = { path = "crates/lib/easyenv" }
|
||||
enums = { path = "crates/schema/public/enums" }
|
||||
enums_api = { path = "crates/schema/public/enums_api" }
|
||||
enums_convert = { path = "crates/schema/public/enums_convert" }
|
||||
enums_db = { path = "crates/schema/public/enums_db" }
|
||||
enums_shared = { path = "crates/schema/public/enums_shared" }
|
||||
enums_public = { path = "crates/schema/public/enums_public" }
|
||||
|
||||
@@ -33,6 +33,7 @@ build_metadata.workspace = true
|
||||
cookie_store.workspace = true
|
||||
enums.workspace = true
|
||||
enums_api.workspace = true
|
||||
enums_convert.workspace = true
|
||||
enums_db.workspace = true
|
||||
errors.workspace = true
|
||||
filesys.workspace = true
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::core::events::generation_events::common::{GenerationAction, GenerationModel, GenerationServiceProvider};
|
||||
use crate::core::state::task_database::TaskDatabase;
|
||||
use enums_api::common::generation::generation_provider::GenerationProvider;
|
||||
use enums_convert::common::generation::generation_provider::generation_provider_to_db;
|
||||
use enums_db::common::generation::generation_provider::GenerationProvider as DbGenerationProvider;
|
||||
use enums::tauri::tasks::task_model_type::TaskModelType;
|
||||
use enums::tauri::tasks::task_status::TaskStatus;
|
||||
@@ -117,7 +118,7 @@ impl TaskEnqueueSuccess{
|
||||
status: TaskStatus::Pending,
|
||||
task_type: self.task_type,
|
||||
model_type,
|
||||
provider: DbGenerationProvider::from_api(self.provider),
|
||||
provider: generation_provider_to_db(self.provider),
|
||||
provider_job_id: self.provider_job_id.as_deref(),
|
||||
frontend_caller,
|
||||
frontend_subscriber_id,
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::services::sora::state::sora_task_queue::SoraTaskQueue;
|
||||
use crate::services::storyteller::state::storyteller_credential_manager::StorytellerCredentialManager;
|
||||
use chrono::{DateTime, Utc};
|
||||
use enums_api::common::generation::generation_provider::GenerationProvider;
|
||||
use enums_convert::common::generation::generation_provider::generation_provider_to_api;
|
||||
use enums::tauri::tasks::task_model_type::TaskModelType;
|
||||
use enums::tauri::tasks::task_status::TaskStatus;
|
||||
use enums::tauri::tasks::task_type::TaskType;
|
||||
@@ -159,7 +160,7 @@ pub async fn handle_request(
|
||||
task_status: task.status,
|
||||
task_type: task.task_type,
|
||||
model_type: task.model_type,
|
||||
provider: task.provider.map(|p| p.to_api()),
|
||||
provider: task.provider.map(generation_provider_to_api),
|
||||
provider_job_id: task.provider_job_id,
|
||||
created_at: task.created_at,
|
||||
updated_at: task.updated_at,
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@ use crate::core::events::generation_events::generation_failed_event::GenerationF
|
||||
use crate::core::state::task_database::TaskDatabase;
|
||||
use crate::core::utils::enum_conversion::generation_provider::to_generation_service_provider;
|
||||
use crate::core::utils::enum_conversion::task_type::to_generation_action;
|
||||
use enums_convert::common::generation::generation_provider::generation_provider_to_api;
|
||||
use artcraft_api_defs::jobs::list_session_jobs::ListSessionJobsItem;
|
||||
use enums::tauri::tasks::task_status::TaskStatus;
|
||||
use errors::AnyhowResult;
|
||||
@@ -36,7 +37,7 @@ pub async fn handle_failed_job(
|
||||
maybe_failure_message,
|
||||
}).await?;
|
||||
|
||||
let service = to_generation_service_provider(task.provider.to_api());
|
||||
let service = to_generation_service_provider(generation_provider_to_api(task.provider));
|
||||
let action = to_generation_action(task.task_type);
|
||||
|
||||
let event = GenerationFailedEvent {
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ use crate::core::state::app_env_configs::app_env_configs::AppEnvConfigs;
|
||||
use crate::core::state::task_database::TaskDatabase;
|
||||
use crate::core::utils::enum_conversion::generation_provider::to_generation_service_provider;
|
||||
use crate::core::utils::enum_conversion::task_type::to_generation_action;
|
||||
use enums_convert::common::generation::generation_provider::generation_provider_to_api;
|
||||
use super::events::maybe_handle_frontend_caller_notification::maybe_handle_frontend_caller_notification;
|
||||
use artcraft_api_defs::jobs::list_session_jobs::ListSessionJobsItem;
|
||||
use artcraft_api_defs::utils::media_links_to_thumbnail_template::media_links_to_thumbnail_template;
|
||||
@@ -53,7 +54,7 @@ pub async fn handle_successful_job(
|
||||
|
||||
send_additional_success_events(app_handle, app_env_configs, creds, job, task).await;
|
||||
|
||||
let service = to_generation_service_provider(task.provider.to_api());
|
||||
let service = to_generation_service_provider(generation_provider_to_api(task.provider));
|
||||
let action = to_generation_action(task.task_type);
|
||||
|
||||
let event = GenerationCompleteEvent {
|
||||
|
||||
@@ -20,7 +20,6 @@ path = "src/lib.rs"
|
||||
workspace-build-acceleration.workspace = true
|
||||
|
||||
# Internal
|
||||
enums_db.workspace = true
|
||||
enums_shared.workspace = true
|
||||
|
||||
# Serialization
|
||||
|
||||
-145
@@ -1,7 +1,3 @@
|
||||
#[cfg(test)]
|
||||
use strum::EnumCount;
|
||||
#[cfg(test)]
|
||||
use strum::EnumIter;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Report certain jobs publicly as different from what we actually run.
|
||||
@@ -9,7 +5,6 @@ use utoipa::ToSchema;
|
||||
/// the same models or workflows.
|
||||
///
|
||||
/// Previously named `PublicInferenceJobType` in the `enums_public` crate.
|
||||
#[cfg_attr(test, derive(EnumIter, EnumCount))]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize, Default, ToSchema, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InferenceJobType {
|
||||
@@ -82,143 +77,3 @@ pub enum InferenceJobType {
|
||||
WorldlabsQueue,
|
||||
}
|
||||
|
||||
impl InferenceJobType {
|
||||
pub fn from_db(db_value: enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType) -> Self {
|
||||
use enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Db;
|
||||
match db_value {
|
||||
// Renamed variants
|
||||
Db::LivePortrait => Self::ActingFace,
|
||||
Db::FaceFusion => Self::Lipsync,
|
||||
// Conserved variants
|
||||
Db::FalQueue => Self::FalQueue,
|
||||
Db::VideoRender => Self::VideoRender,
|
||||
Db::GptSovits => Self::GptSovits,
|
||||
Db::F5TTS => Self::F5TTS,
|
||||
Db::ComfyUi => Self::ComfyUi,
|
||||
Db::StudioGen2 => Self::StudioGen2,
|
||||
Db::ConvertFbxToGltf => Self::ConvertFbxToGltf,
|
||||
Db::MocapNet => Self::MocapNet,
|
||||
Db::RvcV2 => Self::RvcV2,
|
||||
Db::SadTalker => Self::SadTalker,
|
||||
Db::SeedVc => Self::SeedVc,
|
||||
Db::SoVitsSvc => Self::SoVitsSvc,
|
||||
Db::StableDiffusion => Self::StableDiffusion,
|
||||
Db::StyleTTS2 => Self::StyleTTS2,
|
||||
Db::Tacotron2 => Self::Tacotron2,
|
||||
Db::Unknown => Self::Unknown,
|
||||
Db::BevyToWorkflow => Self::BevyToWorkflow,
|
||||
Db::RerenderAVideo => Self::RerenderAVideo,
|
||||
Db::ImageGenApi => Self::ImageGenApi,
|
||||
Db::Seedance2ProQueue => Self::Seedance2ProQueue,
|
||||
Db::WorldlabsQueue => Self::WorldlabsQueue,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_db(&self) -> enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType {
|
||||
use enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Db;
|
||||
match self {
|
||||
// Renamed variants
|
||||
Self::ActingFace => Db::LivePortrait,
|
||||
Self::Lipsync => Db::FaceFusion,
|
||||
// Conserved variants
|
||||
Self::FalQueue => Db::FalQueue,
|
||||
Self::VideoRender => Db::VideoRender,
|
||||
Self::GptSovits => Db::GptSovits,
|
||||
Self::F5TTS => Db::F5TTS,
|
||||
Self::ComfyUi => Db::ComfyUi,
|
||||
Self::StudioGen2 => Db::StudioGen2,
|
||||
Self::ConvertFbxToGltf => Db::ConvertFbxToGltf,
|
||||
Self::MocapNet => Db::MocapNet,
|
||||
Self::RvcV2 => Db::RvcV2,
|
||||
Self::SadTalker => Db::SadTalker,
|
||||
Self::SeedVc => Db::SeedVc,
|
||||
Self::SoVitsSvc => Db::SoVitsSvc,
|
||||
Self::StableDiffusion => Db::StableDiffusion,
|
||||
Self::ImageGenApi => Db::ImageGenApi,
|
||||
Self::Seedance2ProQueue => Db::Seedance2ProQueue,
|
||||
Self::WorldlabsQueue => Db::WorldlabsQueue,
|
||||
Self::StyleTTS2 => Db::StyleTTS2,
|
||||
Self::Tacotron2 => Db::Tacotron2,
|
||||
Self::Unknown => Db::Unknown,
|
||||
Self::BevyToWorkflow => Db::BevyToWorkflow,
|
||||
Self::RerenderAVideo => Db::RerenderAVideo,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
use enums_shared::test_helpers::to_json;
|
||||
use super::*;
|
||||
|
||||
fn override_enums() -> &'static [InferenceJobType; 2] {
|
||||
&[
|
||||
InferenceJobType::ActingFace,
|
||||
InferenceJobType::Lipsync,
|
||||
]
|
||||
}
|
||||
|
||||
mod override_values {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn acting_face() {
|
||||
use enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Db;
|
||||
assert_eq!(InferenceJobType::ActingFace.to_db(), Db::LivePortrait);
|
||||
assert_eq!(to_json(&InferenceJobType::ActingFace.to_db()), "live_portrait");
|
||||
assert_eq!(InferenceJobType::from_db(Db::LivePortrait), InferenceJobType::ActingFace);
|
||||
assert_eq!(to_json(&InferenceJobType::from_db(Db::LivePortrait)), "acting_face");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lipsync() {
|
||||
use enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Db;
|
||||
assert_eq!(InferenceJobType::Lipsync.to_db(), Db::FaceFusion);
|
||||
assert_eq!(to_json(&InferenceJobType::Lipsync.to_db()), "face_fusion");
|
||||
assert_eq!(InferenceJobType::from_db(Db::FaceFusion), InferenceJobType::Lipsync);
|
||||
assert_eq!(to_json(&InferenceJobType::from_db(Db::FaceFusion)), "lipsync");
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Db;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn public_to_internal() {
|
||||
let mut tested_count = 0;
|
||||
for public_variant in InferenceJobType::iter() {
|
||||
match public_variant {
|
||||
InferenceJobType::ActingFace | InferenceJobType::Lipsync => continue,
|
||||
_ => {}
|
||||
}
|
||||
assert_eq!(public_variant, InferenceJobType::from_db(public_variant.to_db()));
|
||||
let internal_enum_string = to_json(&public_variant.to_db());
|
||||
let public_enum_string = to_json(&public_variant);
|
||||
assert_eq!(internal_enum_string, public_enum_string);
|
||||
tested_count += 1;
|
||||
}
|
||||
assert!(tested_count > 1);
|
||||
assert_eq!(tested_count, InferenceJobType::iter().len() - override_enums().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_to_public() {
|
||||
let mut tested_count = 0;
|
||||
for internal_variant in Db::all_variants() {
|
||||
match internal_variant {
|
||||
Db::LivePortrait | Db::FaceFusion => continue,
|
||||
_ => {}
|
||||
}
|
||||
assert_eq!(internal_variant, InferenceJobType::from_db(internal_variant).to_db());
|
||||
let public_enum_string = to_json(&InferenceJobType::from_db(internal_variant));
|
||||
let internal_enum_string = to_json(&internal_variant);
|
||||
assert_eq!(internal_enum_string, public_enum_string);
|
||||
tested_count += 1;
|
||||
}
|
||||
assert!(tested_count > 1);
|
||||
assert_eq!(tested_count, Db::all_variants().len() - override_enums().len());
|
||||
}
|
||||
}
|
||||
}
|
||||
-159
@@ -1,9 +1,5 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
#[cfg(test)]
|
||||
use strum::EnumCount;
|
||||
#[cfg(test)]
|
||||
use strum::EnumIter;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Report certain models publicly as different from what we actually use.
|
||||
@@ -11,7 +7,6 @@ use utoipa::ToSchema;
|
||||
/// the same models. This won't always make sense, but in some cases it will.
|
||||
///
|
||||
/// This was previously named `PublicMediaFileModelType` in the `enums_public` crate.
|
||||
#[cfg_attr(test, derive(EnumIter, EnumCount))]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize, ToSchema, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MediaFileOriginModelType {
|
||||
@@ -84,157 +79,3 @@ pub enum MediaFileOriginModelType {
|
||||
Rerender,
|
||||
}
|
||||
|
||||
/// Convert between the API (public-facing) type and the DB (internal) type.
|
||||
impl MediaFileOriginModelType {
|
||||
pub fn from_db(db_value: enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType) -> Self {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
match db_value {
|
||||
// Renamed variants
|
||||
Db::FaceFusion => Self::Lipsync,
|
||||
Db::LivePortrait => Self::FaceMirror,
|
||||
Db::SadTalker => Self::FaceAnimator,
|
||||
Db::StyleTTS2 => Self::VoiceDesigner,
|
||||
Db::StorytellerStudioImageGen => Self::StorytellerStudioImageGen,
|
||||
// Conserved variants
|
||||
Db::RvcV2 => Self::RvcV2,
|
||||
Db::SoVitsSvc => Self::SoVitsSvc,
|
||||
Db::SeedVc => Self::SeedVc,
|
||||
Db::Tacotron2 => Self::Tacotron2,
|
||||
Db::MocapNet => Self::MocapNet,
|
||||
Db::StableDiffusion15 => Self::StableDiffusion15,
|
||||
Db::GptSovits => Self::GptSovits,
|
||||
Db::F5TTS => Self::F5TTS,
|
||||
Db::StorytellerStudio => Self::StorytellerStudio,
|
||||
Db::VideoStyleTransfer => Self::VideoStyleTransfer,
|
||||
Db::ComfyUi => Self::ComfyUi,
|
||||
Db::VallEX => Self::VallEX,
|
||||
Db::Rerender => Self::Rerender,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_db(&self) -> enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
match self {
|
||||
// Renamed variants
|
||||
Self::FaceMirror => Db::LivePortrait,
|
||||
Self::FaceAnimator => Db::SadTalker,
|
||||
Self::Lipsync => Db::FaceFusion,
|
||||
Self::VoiceDesigner => Db::StyleTTS2,
|
||||
Self::StorytellerStudioImageGen => Db::StorytellerStudioImageGen,
|
||||
// Conserved variants
|
||||
Self::RvcV2 => Db::RvcV2,
|
||||
Self::SoVitsSvc => Db::SoVitsSvc,
|
||||
Self::SeedVc => Db::SeedVc,
|
||||
Self::Tacotron2 => Db::Tacotron2,
|
||||
Self::MocapNet => Db::MocapNet,
|
||||
Self::StableDiffusion15 => Db::StableDiffusion15,
|
||||
Self::GptSovits => Db::GptSovits,
|
||||
Self::F5TTS => Db::F5TTS,
|
||||
Self::StorytellerStudio => Db::StorytellerStudio,
|
||||
Self::VideoStyleTransfer => Db::VideoStyleTransfer,
|
||||
Self::ComfyUi => Db::ComfyUi,
|
||||
Self::VallEX => Db::VallEX,
|
||||
Self::Rerender => Db::Rerender,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
use enums_shared::test_helpers::to_json;
|
||||
use super::*;
|
||||
|
||||
fn override_enums() -> &'static [MediaFileOriginModelType; 4] {
|
||||
&[
|
||||
MediaFileOriginModelType::FaceMirror,
|
||||
MediaFileOriginModelType::FaceAnimator,
|
||||
MediaFileOriginModelType::Lipsync,
|
||||
MediaFileOriginModelType::VoiceDesigner,
|
||||
]
|
||||
}
|
||||
|
||||
mod override_values {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn face_fusion() {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
assert_eq!(MediaFileOriginModelType::Lipsync.to_db(), Db::FaceFusion);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::Lipsync.to_db()), "face_fusion");
|
||||
assert_eq!(MediaFileOriginModelType::from_db(Db::FaceFusion), MediaFileOriginModelType::Lipsync);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::from_db(Db::FaceFusion)), "lipsync");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_portrait() {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
assert_eq!(MediaFileOriginModelType::FaceMirror.to_db(), Db::LivePortrait);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::FaceMirror.to_db()), "live_portrait");
|
||||
assert_eq!(MediaFileOriginModelType::from_db(Db::LivePortrait), MediaFileOriginModelType::FaceMirror);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::from_db(Db::LivePortrait)), "face_mirror");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sad_talker() {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
assert_eq!(MediaFileOriginModelType::FaceAnimator.to_db(), Db::SadTalker);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::FaceAnimator.to_db()), "sad_talker");
|
||||
assert_eq!(MediaFileOriginModelType::from_db(Db::SadTalker), MediaFileOriginModelType::FaceAnimator);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::from_db(Db::SadTalker)), "face_animator");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn styletts2() {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
assert_eq!(MediaFileOriginModelType::VoiceDesigner.to_db(), Db::StyleTTS2);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::VoiceDesigner.to_db()), "styletts2");
|
||||
assert_eq!(MediaFileOriginModelType::from_db(Db::StyleTTS2), MediaFileOriginModelType::VoiceDesigner);
|
||||
assert_eq!(to_json(&MediaFileOriginModelType::from_db(Db::StyleTTS2)), "voice_designer");
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn public_to_internal() {
|
||||
let mut tested_count = 0;
|
||||
for public_variant in MediaFileOriginModelType::iter() {
|
||||
match public_variant {
|
||||
MediaFileOriginModelType::FaceMirror |
|
||||
MediaFileOriginModelType::FaceAnimator |
|
||||
MediaFileOriginModelType::Lipsync |
|
||||
MediaFileOriginModelType::VoiceDesigner => continue,
|
||||
_ => {}
|
||||
}
|
||||
assert_eq!(public_variant, MediaFileOriginModelType::from_db(public_variant.to_db()));
|
||||
let internal_enum_string = to_json(&public_variant.to_db());
|
||||
let public_enum_string = to_json(&public_variant);
|
||||
assert_eq!(internal_enum_string, public_enum_string);
|
||||
tested_count += 1;
|
||||
}
|
||||
assert!(tested_count > 1);
|
||||
assert_eq!(tested_count, MediaFileOriginModelType::iter().len() - override_enums().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_to_public() {
|
||||
let mut tested_count = 0;
|
||||
for internal_variant in Db::all_variants() {
|
||||
match internal_variant {
|
||||
Db::FaceFusion | Db::LivePortrait | Db::SadTalker | Db::StyleTTS2 => continue,
|
||||
_ => {}
|
||||
}
|
||||
assert_eq!(internal_variant, MediaFileOriginModelType::from_db(internal_variant).to_db());
|
||||
let public_enum_string = to_json(&MediaFileOriginModelType::from_db(internal_variant));
|
||||
let internal_enum_string = to_json(&internal_variant);
|
||||
assert_eq!(internal_enum_string, public_enum_string);
|
||||
tested_count += 1;
|
||||
}
|
||||
assert!(tested_count > 1);
|
||||
assert_eq!(tested_count, Db::all_variants().len() - override_enums().len());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
#[cfg(test)]
|
||||
use strum::EnumCount;
|
||||
#[cfg(test)]
|
||||
use strum::EnumIter;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Report certain models publicly as different from what we actually use.
|
||||
///
|
||||
/// Previously named `PublicWeightsType` in the `enums_public` crate.
|
||||
#[cfg_attr(test, derive(EnumIter, EnumCount))]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize, ToSchema, Debug)]
|
||||
pub enum WeightsType {
|
||||
// Renamed enum variants
|
||||
@@ -70,106 +65,5 @@ impl WeightsType {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_db(db_value: enums_db::by_table::model_weights::weights_types::WeightsType) -> Self {
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as Db;
|
||||
match db_value {
|
||||
Db::GptSoVits => Self::Tacotron2_5,
|
||||
Db::HifiganTacotron2 => Self::HifiganTacotron2,
|
||||
Db::RvcV2 => Self::RvcV2,
|
||||
Db::StableDiffusion15 => Self::StableDiffusion15,
|
||||
Db::StableDiffusionXL => Self::StableDiffusionXL,
|
||||
Db::SoVitsSvc => Self::SoVitsSvc,
|
||||
Db::Tacotron2 => Self::Tacotron2,
|
||||
Db::LoRA => Self::LoRA,
|
||||
Db::VallE => Self::VallE,
|
||||
Db::ComfyUi => Self::ComfyUi,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_db(&self) -> enums_db::by_table::model_weights::weights_types::WeightsType {
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as Db;
|
||||
match self {
|
||||
Self::Tacotron2_5 => Db::GptSoVits,
|
||||
Self::HifiganTacotron2 => Db::HifiganTacotron2,
|
||||
Self::RvcV2 => Db::RvcV2,
|
||||
Self::StableDiffusion15 => Db::StableDiffusion15,
|
||||
Self::StableDiffusionXL => Db::StableDiffusionXL,
|
||||
Self::SoVitsSvc => Db::SoVitsSvc,
|
||||
Self::Tacotron2 => Db::Tacotron2,
|
||||
Self::LoRA => Db::LoRA,
|
||||
Self::VallE => Db::VallE,
|
||||
Self::ComfyUi => Db::ComfyUi,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
use enums_shared::test_helpers::to_json;
|
||||
use super::*;
|
||||
|
||||
fn override_enums() -> &'static [WeightsType; 1] {
|
||||
&[WeightsType::Tacotron2_5]
|
||||
}
|
||||
|
||||
mod override_values {
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as Db;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn gpt_so_vits() {
|
||||
assert_eq!(WeightsType::Tacotron2_5.to_db(), Db::GptSoVits);
|
||||
assert_eq!(to_json(&WeightsType::Tacotron2_5.to_db()), "gpt_so_vits");
|
||||
assert_eq!(WeightsType::from_db(Db::GptSoVits), WeightsType::Tacotron2_5);
|
||||
assert_eq!(to_json(&WeightsType::from_db(Db::GptSoVits)), "tacotron2.5");
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as Db;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn public_to_internal() {
|
||||
let mut tested_count = 0;
|
||||
for public_variant in WeightsType::iter() {
|
||||
if public_variant == WeightsType::Tacotron2_5 {
|
||||
continue;
|
||||
}
|
||||
assert_eq!(public_variant, WeightsType::from_db(public_variant.to_db()));
|
||||
let internal_enum_string = to_json(&public_variant.to_db());
|
||||
let public_enum_string = to_json(&public_variant);
|
||||
assert_eq!(internal_enum_string, public_enum_string);
|
||||
tested_count += 1;
|
||||
}
|
||||
assert!(tested_count > 1);
|
||||
assert_eq!(tested_count, WeightsType::iter().len() - override_enums().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_to_public() {
|
||||
let mut tested_count = 0;
|
||||
for internal_variant in Db::all_variants() {
|
||||
if internal_variant == Db::GptSoVits {
|
||||
continue;
|
||||
}
|
||||
assert_eq!(internal_variant, WeightsType::from_db(internal_variant).to_db());
|
||||
let public_enum_string = to_json(&WeightsType::from_db(internal_variant));
|
||||
let internal_enum_string = to_json(&internal_variant);
|
||||
assert_eq!(internal_enum_string, public_enum_string);
|
||||
tested_count += 1;
|
||||
}
|
||||
assert!(tested_count > 1);
|
||||
assert_eq!(tested_count, Db::all_variants().len() - override_enums().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_round_trip() {
|
||||
for variant in Db::all_variants() {
|
||||
let variant = WeightsType::from_db(variant);
|
||||
assert_eq!(variant, WeightsType::from_str(variant.to_str()).unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,31 +64,6 @@ impl GenerationProvider {
|
||||
])
|
||||
}
|
||||
|
||||
/// Convert from the DB type.
|
||||
pub fn from_db(db_value: enums_db::common::generation::generation_provider::GenerationProvider) -> Self {
|
||||
use enums_db::common::generation::generation_provider::GenerationProvider as Db;
|
||||
match db_value {
|
||||
Db::Artcraft => Self::Artcraft,
|
||||
Db::Fal => Self::Fal,
|
||||
Db::Grok => Self::Grok,
|
||||
Db::Midjourney => Self::Midjourney,
|
||||
Db::Sora => Self::Sora,
|
||||
Db::WorldLabs => Self::WorldLabs,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert to the DB type.
|
||||
pub fn to_db(&self) -> enums_db::common::generation::generation_provider::GenerationProvider {
|
||||
use enums_db::common::generation::generation_provider::GenerationProvider as Db;
|
||||
match self {
|
||||
Self::Artcraft => Db::Artcraft,
|
||||
Self::Fal => Db::Fal,
|
||||
Self::Grok => Db::Grok,
|
||||
Self::Midjourney => Db::Midjourney,
|
||||
Self::Sora => Db::Sora,
|
||||
Self::WorldLabs => Db::WorldLabs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -184,26 +159,4 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod conversion_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn round_trip_from_db() {
|
||||
use enums_db::common::generation::generation_provider::GenerationProvider as Db;
|
||||
for variant in Db::all_variants() {
|
||||
let api = GenerationProvider::from_db(variant);
|
||||
let back = api.to_db();
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_from_api() {
|
||||
for variant in GenerationProvider::all_variants() {
|
||||
let db = variant.to_db();
|
||||
let back = GenerationProvider::from_db(db);
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "enums_convert"
|
||||
edition = "2021"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
"Brandon Thomas <bt@brand.io>",
|
||||
"Brandon Thomas <echelon@gmail.com>",
|
||||
]
|
||||
publish = false
|
||||
|
||||
[package.metadata.cargo-udeps.ignore]
|
||||
normal = ["workspace-build-acceleration"]
|
||||
|
||||
[lib]
|
||||
name = "enums_convert"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
# Workspace hack (faster compile times)
|
||||
workspace-build-acceleration.workspace = true
|
||||
|
||||
# Internal
|
||||
enums_api.workspace = true
|
||||
enums_db.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json.workspace = true
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
use enums_api::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Api;
|
||||
use enums_db::by_table::generic_inference_jobs::inference_job_type::InferenceJobType as Db;
|
||||
|
||||
pub fn inference_job_type_to_db(api_value: Api) -> Db {
|
||||
match api_value {
|
||||
Api::ActingFace => Db::LivePortrait,
|
||||
Api::Lipsync => Db::FaceFusion,
|
||||
Api::FalQueue => Db::FalQueue,
|
||||
Api::VideoRender => Db::VideoRender,
|
||||
Api::GptSovits => Db::GptSovits,
|
||||
Api::F5TTS => Db::F5TTS,
|
||||
Api::ComfyUi => Db::ComfyUi,
|
||||
Api::StudioGen2 => Db::StudioGen2,
|
||||
Api::ConvertFbxToGltf => Db::ConvertFbxToGltf,
|
||||
Api::MocapNet => Db::MocapNet,
|
||||
Api::RvcV2 => Db::RvcV2,
|
||||
Api::SadTalker => Db::SadTalker,
|
||||
Api::SeedVc => Db::SeedVc,
|
||||
Api::SoVitsSvc => Db::SoVitsSvc,
|
||||
Api::StableDiffusion => Db::StableDiffusion,
|
||||
Api::ImageGenApi => Db::ImageGenApi,
|
||||
Api::Seedance2ProQueue => Db::Seedance2ProQueue,
|
||||
Api::WorldlabsQueue => Db::WorldlabsQueue,
|
||||
Api::StyleTTS2 => Db::StyleTTS2,
|
||||
Api::Tacotron2 => Db::Tacotron2,
|
||||
Api::Unknown => Db::Unknown,
|
||||
Api::BevyToWorkflow => Db::BevyToWorkflow,
|
||||
Api::RerenderAVideo => Db::RerenderAVideo,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inference_job_type_to_api(db_value: Db) -> Api {
|
||||
match db_value {
|
||||
Db::LivePortrait => Api::ActingFace,
|
||||
Db::FaceFusion => Api::Lipsync,
|
||||
Db::FalQueue => Api::FalQueue,
|
||||
Db::VideoRender => Api::VideoRender,
|
||||
Db::GptSovits => Api::GptSovits,
|
||||
Db::F5TTS => Api::F5TTS,
|
||||
Db::ComfyUi => Api::ComfyUi,
|
||||
Db::StudioGen2 => Api::StudioGen2,
|
||||
Db::ConvertFbxToGltf => Api::ConvertFbxToGltf,
|
||||
Db::MocapNet => Api::MocapNet,
|
||||
Db::RvcV2 => Api::RvcV2,
|
||||
Db::SadTalker => Api::SadTalker,
|
||||
Db::SeedVc => Api::SeedVc,
|
||||
Db::SoVitsSvc => Api::SoVitsSvc,
|
||||
Db::StableDiffusion => Api::StableDiffusion,
|
||||
Db::StyleTTS2 => Api::StyleTTS2,
|
||||
Db::Tacotron2 => Api::Tacotron2,
|
||||
Db::Unknown => Api::Unknown,
|
||||
Db::BevyToWorkflow => Api::BevyToWorkflow,
|
||||
Db::RerenderAVideo => Api::RerenderAVideo,
|
||||
Db::ImageGenApi => Api::ImageGenApi,
|
||||
Db::Seedance2ProQueue => Api::Seedance2ProQueue,
|
||||
Db::WorldlabsQueue => Api::WorldlabsQueue,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn round_trip_api_to_db() {
|
||||
for db_variant in Db::all_variants() {
|
||||
let api = inference_job_type_to_api(db_variant);
|
||||
let db = inference_job_type_to_db(api);
|
||||
let back = inference_job_type_to_api(db);
|
||||
assert_eq!(api, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_db_to_api() {
|
||||
for variant in Db::all_variants() {
|
||||
let api = inference_job_type_to_api(variant);
|
||||
let back = inference_job_type_to_db(api);
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renamed_variants() {
|
||||
assert_eq!(inference_job_type_to_db(Api::ActingFace), Db::LivePortrait);
|
||||
assert_eq!(inference_job_type_to_db(Api::Lipsync), Db::FaceFusion);
|
||||
assert_eq!(inference_job_type_to_api(Db::LivePortrait), Api::ActingFace);
|
||||
assert_eq!(inference_job_type_to_api(Db::FaceFusion), Api::Lipsync);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod inference_job_type;
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Api;
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as Db;
|
||||
|
||||
pub fn media_file_origin_model_type_to_db(api_value: Api) -> Db {
|
||||
match api_value {
|
||||
Api::FaceMirror => Db::LivePortrait,
|
||||
Api::FaceAnimator => Db::SadTalker,
|
||||
Api::Lipsync => Db::FaceFusion,
|
||||
Api::VoiceDesigner => Db::StyleTTS2,
|
||||
Api::StorytellerStudioImageGen => Db::StorytellerStudioImageGen,
|
||||
Api::RvcV2 => Db::RvcV2,
|
||||
Api::SoVitsSvc => Db::SoVitsSvc,
|
||||
Api::SeedVc => Db::SeedVc,
|
||||
Api::Tacotron2 => Db::Tacotron2,
|
||||
Api::MocapNet => Db::MocapNet,
|
||||
Api::StableDiffusion15 => Db::StableDiffusion15,
|
||||
Api::GptSovits => Db::GptSovits,
|
||||
Api::F5TTS => Db::F5TTS,
|
||||
Api::StorytellerStudio => Db::StorytellerStudio,
|
||||
Api::VideoStyleTransfer => Db::VideoStyleTransfer,
|
||||
Api::ComfyUi => Db::ComfyUi,
|
||||
Api::VallEX => Db::VallEX,
|
||||
Api::Rerender => Db::Rerender,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn media_file_origin_model_type_to_api(db_value: Db) -> Api {
|
||||
match db_value {
|
||||
Db::FaceFusion => Api::Lipsync,
|
||||
Db::LivePortrait => Api::FaceMirror,
|
||||
Db::SadTalker => Api::FaceAnimator,
|
||||
Db::StyleTTS2 => Api::VoiceDesigner,
|
||||
Db::StorytellerStudioImageGen => Api::StorytellerStudioImageGen,
|
||||
Db::RvcV2 => Api::RvcV2,
|
||||
Db::SoVitsSvc => Api::SoVitsSvc,
|
||||
Db::SeedVc => Api::SeedVc,
|
||||
Db::Tacotron2 => Api::Tacotron2,
|
||||
Db::MocapNet => Api::MocapNet,
|
||||
Db::StableDiffusion15 => Api::StableDiffusion15,
|
||||
Db::GptSovits => Api::GptSovits,
|
||||
Db::F5TTS => Api::F5TTS,
|
||||
Db::StorytellerStudio => Api::StorytellerStudio,
|
||||
Db::VideoStyleTransfer => Api::VideoStyleTransfer,
|
||||
Db::ComfyUi => Api::ComfyUi,
|
||||
Db::VallEX => Api::VallEX,
|
||||
Db::Rerender => Api::Rerender,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn round_trip_api_to_db() {
|
||||
for db_variant in Db::all_variants() {
|
||||
let api = media_file_origin_model_type_to_api(db_variant);
|
||||
let db = media_file_origin_model_type_to_db(api);
|
||||
let back = media_file_origin_model_type_to_api(db);
|
||||
assert_eq!(api, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_db_to_api() {
|
||||
for variant in Db::all_variants() {
|
||||
let api = media_file_origin_model_type_to_api(variant);
|
||||
let back = media_file_origin_model_type_to_db(api);
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renamed_variants() {
|
||||
assert_eq!(media_file_origin_model_type_to_db(Api::FaceMirror), Db::LivePortrait);
|
||||
assert_eq!(media_file_origin_model_type_to_db(Api::FaceAnimator), Db::SadTalker);
|
||||
assert_eq!(media_file_origin_model_type_to_db(Api::Lipsync), Db::FaceFusion);
|
||||
assert_eq!(media_file_origin_model_type_to_db(Api::VoiceDesigner), Db::StyleTTS2);
|
||||
assert_eq!(media_file_origin_model_type_to_api(Db::LivePortrait), Api::FaceMirror);
|
||||
assert_eq!(media_file_origin_model_type_to_api(Db::SadTalker), Api::FaceAnimator);
|
||||
assert_eq!(media_file_origin_model_type_to_api(Db::FaceFusion), Api::Lipsync);
|
||||
assert_eq!(media_file_origin_model_type_to_api(Db::StyleTTS2), Api::VoiceDesigner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod media_file_origin_model_type;
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod generic_inference_jobs;
|
||||
pub mod media_files;
|
||||
pub mod model_weights;
|
||||
@@ -0,0 +1 @@
|
||||
pub mod weights_types;
|
||||
@@ -0,0 +1,62 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType as Api;
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as Db;
|
||||
|
||||
pub fn weights_type_to_db(api_value: Api) -> Db {
|
||||
match api_value {
|
||||
Api::Tacotron2_5 => Db::GptSoVits,
|
||||
Api::HifiganTacotron2 => Db::HifiganTacotron2,
|
||||
Api::RvcV2 => Db::RvcV2,
|
||||
Api::StableDiffusion15 => Db::StableDiffusion15,
|
||||
Api::StableDiffusionXL => Db::StableDiffusionXL,
|
||||
Api::SoVitsSvc => Db::SoVitsSvc,
|
||||
Api::Tacotron2 => Db::Tacotron2,
|
||||
Api::LoRA => Db::LoRA,
|
||||
Api::VallE => Db::VallE,
|
||||
Api::ComfyUi => Db::ComfyUi,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn weights_type_to_api(db_value: Db) -> Api {
|
||||
match db_value {
|
||||
Db::GptSoVits => Api::Tacotron2_5,
|
||||
Db::HifiganTacotron2 => Api::HifiganTacotron2,
|
||||
Db::RvcV2 => Api::RvcV2,
|
||||
Db::StableDiffusion15 => Api::StableDiffusion15,
|
||||
Db::StableDiffusionXL => Api::StableDiffusionXL,
|
||||
Db::SoVitsSvc => Api::SoVitsSvc,
|
||||
Db::Tacotron2 => Api::Tacotron2,
|
||||
Db::LoRA => Api::LoRA,
|
||||
Db::VallE => Api::VallE,
|
||||
Db::ComfyUi => Api::ComfyUi,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn round_trip_api_to_db() {
|
||||
for db_variant in Db::all_variants() {
|
||||
let api = weights_type_to_api(db_variant);
|
||||
let db = weights_type_to_db(api);
|
||||
let back = weights_type_to_api(db);
|
||||
assert_eq!(api, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_db_to_api() {
|
||||
for variant in Db::all_variants() {
|
||||
let api = weights_type_to_api(variant);
|
||||
let back = weights_type_to_db(api);
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renamed_variants() {
|
||||
assert_eq!(weights_type_to_db(Api::Tacotron2_5), Db::GptSoVits);
|
||||
assert_eq!(weights_type_to_api(Db::GptSoVits), Api::Tacotron2_5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
use enums_api::common::generation::generation_provider::GenerationProvider as Api;
|
||||
use enums_db::common::generation::generation_provider::GenerationProvider as Db;
|
||||
|
||||
pub fn generation_provider_to_db(api_value: Api) -> Db {
|
||||
match api_value {
|
||||
Api::Artcraft => Db::Artcraft,
|
||||
Api::Fal => Db::Fal,
|
||||
Api::Grok => Db::Grok,
|
||||
Api::Midjourney => Db::Midjourney,
|
||||
Api::Sora => Db::Sora,
|
||||
Api::WorldLabs => Db::WorldLabs,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generation_provider_to_api(db_value: Db) -> Api {
|
||||
match db_value {
|
||||
Db::Artcraft => Api::Artcraft,
|
||||
Db::Fal => Api::Fal,
|
||||
Db::Grok => Api::Grok,
|
||||
Db::Midjourney => Api::Midjourney,
|
||||
Db::Sora => Api::Sora,
|
||||
Db::WorldLabs => Api::WorldLabs,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn round_trip_api_to_db() {
|
||||
for variant in Api::all_variants() {
|
||||
let db = generation_provider_to_db(variant);
|
||||
let back = generation_provider_to_api(db);
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_db_to_api() {
|
||||
for variant in Db::all_variants() {
|
||||
let api = generation_provider_to_api(variant);
|
||||
let back = generation_provider_to_db(api);
|
||||
assert_eq!(variant, back);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod generation_provider;
|
||||
@@ -0,0 +1 @@
|
||||
pub mod generation;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod by_table;
|
||||
pub mod common;
|
||||
@@ -51,6 +51,7 @@ easyenv.workspace = true
|
||||
elasticsearch_schema = { path = "../../../schema/database/elasticsearch_schema" }
|
||||
enums.workspace = true
|
||||
enums_api.workspace = true
|
||||
enums_convert.workspace = true
|
||||
enums_db.workspace = true
|
||||
enums_public.workspace = true
|
||||
errors.workspace = true
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use enums::by_table::media_files::media_file_origin_category::MediaFileOriginCategory;
|
||||
use enums_convert::by_table::media_files::media_file_origin_model_type::media_file_origin_model_type_to_api;
|
||||
use enums_db::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType as DbMediaFileOriginModelType;
|
||||
use enums::by_table::media_files::media_file_origin_product_category::MediaFileOriginProductCategory;
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType;
|
||||
@@ -53,14 +54,14 @@ impl MediaFileOriginDetails {
|
||||
let maybe_model = match (maybe_model_type, maybe_model_token, maybe_model_title) {
|
||||
(Some(model_type), Some(model_token), Some(model_title)) => {
|
||||
Some(MediaFileModelDetails::ModelWeight {
|
||||
model_type: MediaFileOriginModelType::from_db(model_type),
|
||||
model_type: media_file_origin_model_type_to_api(model_type),
|
||||
token: model_token,
|
||||
title: model_title,
|
||||
})
|
||||
},
|
||||
(Some(model_type), None, None) => {
|
||||
Some(MediaFileModelDetails::SystemModel {
|
||||
model_type: MediaFileOriginModelType::from_db(model_type),
|
||||
model_type: media_file_origin_model_type_to_api(model_type),
|
||||
})
|
||||
},
|
||||
_ => None,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_api;
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as DbWeightsType;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
@@ -366,7 +367,7 @@ pub async fn batch_get_media_files_handler(
|
||||
weight_token,
|
||||
// TODO(bt,2023-12-28): Instead of giving bogus defaults on None, make these optional or return
|
||||
// None for *everything* on any field being absent.
|
||||
weight_type: WeightsType::from_db(result.maybe_model_weights_type.unwrap_or(DbWeightsType::Tacotron2)),
|
||||
weight_type: weights_type_to_api(result.maybe_model_weights_type.unwrap_or(DbWeightsType::Tacotron2)),
|
||||
weight_category: result.maybe_model_weights_category.unwrap_or(WeightsCategory::TextToSpeech),
|
||||
title: result.maybe_model_weights_title.unwrap_or_else(|| "model".to_string()),
|
||||
maybe_cover_image_public_bucket_path,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_api;
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as DbWeightsType;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
@@ -406,7 +407,7 @@ async fn modern_media_file_lookup(
|
||||
weight_token,
|
||||
// TODO(bt,2023-12-28): Instead of giving bogus defaults on None, make these optional or return
|
||||
// None for *everything* on any field being absent.
|
||||
weight_type: WeightsType::from_db(result.maybe_model_weights_type.unwrap_or(DbWeightsType::Tacotron2)),
|
||||
weight_type: weights_type_to_api(result.maybe_model_weights_type.unwrap_or(DbWeightsType::Tacotron2)),
|
||||
weight_category: result.maybe_model_weights_category.unwrap_or(WeightsCategory::TextToSpeech),
|
||||
title: result.maybe_model_weights_title.unwrap_or_else(|| "model".to_string()),
|
||||
maybe_cover_image_public_bucket_path,
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ use enums::by_table::media_files::media_file_type::MediaFileType;
|
||||
use enums::common::view_as::ViewAs;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType;
|
||||
use enums_convert::by_table::media_files::media_file_origin_model_type::media_file_origin_model_type_to_api;
|
||||
use log::{error, warn};
|
||||
use mysql_queries::queries::media_files::list::list_featured_media_files::{list_featured_media_files, FeaturedMediaFileListPage, ListFeaturedMediaFilesArgs};
|
||||
use std::sync::Arc;
|
||||
@@ -314,7 +315,7 @@ pub async fn list_featured_media_files_handler(
|
||||
origin_category: m.origin_category,
|
||||
origin_product_category: m.origin_product_category,
|
||||
maybe_origin_model_type: m.maybe_origin_model_type
|
||||
.map(|t| MediaFileOriginModelType::from_db(t)),
|
||||
.map(media_file_origin_model_type_to_api),
|
||||
maybe_origin_model_token: m.maybe_origin_model_token,
|
||||
maybe_creator: UserDetailsLight::from_optional_db_fields_owned(
|
||||
m.maybe_creator_user_token,
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ use enums::common::view_as::ViewAs;
|
||||
use enums::common::visibility::Visibility;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType;
|
||||
use enums_convert::by_table::media_files::media_file_origin_model_type::media_file_origin_model_type_to_api;
|
||||
use log::warn;
|
||||
use mysql_queries::queries::media_files::list::list_media_files_by_batch_token::{list_media_files_by_batch_token, ListMediaFileByBatchArgs};
|
||||
use tokens::tokens::batch_generations::BatchGenerationToken;
|
||||
@@ -275,7 +276,7 @@ pub async fn list_media_files_by_batch_token_handler(
|
||||
origin_category: record.origin_category,
|
||||
origin_product_category: record.origin_product_category,
|
||||
maybe_origin_model_type: record.maybe_origin_model_type
|
||||
.map(|t| MediaFileOriginModelType::from_db(t)),
|
||||
.map(media_file_origin_model_type_to_api),
|
||||
maybe_origin_model_token: record.maybe_origin_model_token,
|
||||
media_links: MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain,
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ use enums::common::view_as::ViewAs;
|
||||
use enums::common::visibility::Visibility;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType;
|
||||
use enums_convert::by_table::media_files::media_file_origin_model_type::media_file_origin_model_type_to_api;
|
||||
use log::{info, warn};
|
||||
use mysql_queries::queries::media_files::list::list_media_files_for_user::{list_media_files_for_user, ListMediaFileForUserArgs};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
@@ -337,7 +338,7 @@ pub async fn list_media_files_for_user_handler(
|
||||
origin_category: record.origin_category,
|
||||
origin_product_category: record.origin_product_category,
|
||||
maybe_origin_model_type: record.maybe_origin_model_type
|
||||
.map(|t| MediaFileOriginModelType::from_db(t)),
|
||||
.map(media_file_origin_model_type_to_api),
|
||||
maybe_origin_model_token: record.maybe_origin_model_token,
|
||||
media_links: MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain, server_state.server_environment, &public_bucket_path),
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ use enums::common::view_as::ViewAs;
|
||||
use enums::common::visibility::Visibility;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType;
|
||||
use enums_convert::by_table::media_files::media_file_origin_model_type::media_file_origin_model_type_to_api;
|
||||
use log::warn;
|
||||
use mysql_queries::queries::media_files::list::list_media_files::{list_media_files, ListMediaFilesArgs};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
@@ -343,7 +344,7 @@ pub async fn list_media_files_handler(
|
||||
origin_category: record.origin_category,
|
||||
origin_product_category: record.origin_product_category,
|
||||
maybe_origin_model_type: record.maybe_origin_model_type
|
||||
.map(|m| MediaFileOriginModelType::from_db(m)),
|
||||
.map(media_file_origin_model_type_to_api),
|
||||
maybe_origin_model_token: record.maybe_origin_model_token,
|
||||
media_links: MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain,
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ use enums::by_table::media_files::media_file_origin_product_category::MediaFileO
|
||||
use enums::by_table::media_files::media_file_type::MediaFileType;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use enums_api::by_table::media_files::media_file_origin_model_type::MediaFileOriginModelType;
|
||||
use enums_convert::by_table::media_files::media_file_origin_model_type::media_file_origin_model_type_to_api;
|
||||
use log::{debug, error, warn};
|
||||
use mysql_queries::queries::media_files::get::batch_get_media_files_by_tokens::batch_get_media_files_by_tokens;
|
||||
use redis::Commands;
|
||||
@@ -241,7 +242,7 @@ pub async fn list_pinned_media_files_handler(
|
||||
origin_category: m.origin_category,
|
||||
origin_product_category: m.origin_product_category,
|
||||
maybe_origin_model_type: m.maybe_origin_model_type
|
||||
.map(|m| MediaFileOriginModelType::from_db(m)),
|
||||
.map(media_file_origin_model_type_to_api),
|
||||
maybe_origin_model_token: m.maybe_origin_model_token,
|
||||
maybe_creator: UserDetailsLight::from_optional_db_fields_owned(
|
||||
m.maybe_creator_user_token,
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest};
|
||||
use artcraft_api_defs::prompts::create_prompt::{CreatePromptRequest, CreatePromptResponse};
|
||||
use enums::by_table::prompts::prompt_type::PromptType;
|
||||
use enums_convert::common::generation::generation_provider::generation_provider_to_db;
|
||||
use http_server_common::request::get_request_ip::get_request_ip;
|
||||
use log::{error, warn};
|
||||
use mysql_queries::queries::idepotency_tokens::insert_idempotency_token::insert_idempotency_token;
|
||||
@@ -76,7 +77,7 @@ pub async fn create_prompt_handler(
|
||||
.as_ref()
|
||||
.map(|s| &s.user_token),
|
||||
maybe_model_type: request.model_type,
|
||||
maybe_generation_provider: request.generation_provider.map(|p| p.to_db()),
|
||||
maybe_generation_provider: request.generation_provider.map(generation_provider_to_db),
|
||||
maybe_positive_prompt,
|
||||
maybe_negative_prompt,
|
||||
maybe_other_args: None,
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ use chrono::{DateTime, Utc};
|
||||
use enums::by_table::prompt_context_items::prompt_context_semantic_type::PromptContextSemanticType;
|
||||
use enums::by_table::prompts::prompt_type::PromptType;
|
||||
use enums_api::common::generation::generation_provider::GenerationProvider;
|
||||
use enums_convert::common::generation::generation_provider::generation_provider_to_api;
|
||||
use enums::common::model_type::ModelType;
|
||||
use enums::no_table::style_transfer::style_transfer_name::StyleTransferName;
|
||||
use log::{error, warn};
|
||||
@@ -331,7 +332,7 @@ pub async fn get_prompt_handler(
|
||||
token: result.token,
|
||||
maybe_strength,
|
||||
maybe_model_type: result.maybe_model_type,
|
||||
maybe_generation_provider: result.maybe_generation_provider.map(GenerationProvider::from_db),
|
||||
maybe_generation_provider: result.maybe_generation_provider.map(generation_provider_to_api),
|
||||
maybe_positive_prompt: result.maybe_positive_prompt,
|
||||
maybe_negative_prompt: result.maybe_negative_prompt,
|
||||
maybe_context_images,
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@
|
||||
#![forbid(unused_variables)]
|
||||
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::{weights_type_to_api, weights_type_to_db};
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as DbWeightsType;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
@@ -197,7 +198,7 @@ pub async fn list_user_bookmarks_for_user_handler(
|
||||
list_user_bookmarks_by_maybe_entity_type(ListUserBookmarksForUserArgs{
|
||||
username: path.username.as_ref(),
|
||||
maybe_filter_entity_type: query.maybe_scoped_entity_type,
|
||||
maybe_filter_weight_type: query.maybe_scoped_weight_type.map(|wt| wt.to_db()),
|
||||
maybe_filter_weight_type: query.maybe_scoped_weight_type.map(weights_type_to_db),
|
||||
maybe_filter_weight_category: query.maybe_scoped_weight_category,
|
||||
maybe_filter_media_file_type: query.maybe_scoped_media_file_type,
|
||||
sort_ascending,
|
||||
@@ -314,7 +315,7 @@ pub async fn list_user_bookmarks_for_user_handler(
|
||||
Some(cover) => Some(WeightsData {
|
||||
// TODO(bt,2023-12-28): Proper default, optional, or "unknown" values would be better.
|
||||
title: user_bookmark.maybe_entity_descriptive_text.clone().unwrap_or_else(|| "weight".to_string()),
|
||||
weight_type: WeightsType::from_db(user_bookmark.maybe_model_weight_type.unwrap_or(DbWeightsType::Tacotron2)),
|
||||
weight_type: weights_type_to_api(user_bookmark.maybe_model_weight_type.unwrap_or(DbWeightsType::Tacotron2)),
|
||||
weight_category: user_bookmark.maybe_model_weight_category.unwrap_or(WeightsCategory::TextToSpeech),
|
||||
cover,
|
||||
maybe_cover_image_public_bucket_path: maybe_model_weight_cover_image,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_api;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -214,7 +215,7 @@ pub async fn get_weight_handler(
|
||||
weight_token: weight.token,
|
||||
maybe_url_slug: title_to_url_slug(&weight.title),
|
||||
title: weight.title,
|
||||
weight_type: WeightsType::from_db(weight.weights_type),
|
||||
weight_type: weights_type_to_api(weight.weights_type),
|
||||
weight_category: weight.weights_category,
|
||||
// TODO(bt,2023-12-24): Migrated the column. We should return nullable fields, but I don't want to break the frontend
|
||||
description_markdown: weight.maybe_description_markdown.unwrap_or_else(|| "".to_string()),
|
||||
|
||||
+3
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType as ApiWeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_db;
|
||||
use enums_db::by_table::model_weights::weights_types::WeightsType as DbWeightsType;
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -11,7 +12,8 @@ pub fn get_scoped_weights_types(
|
||||
None => None,
|
||||
Some(weights_types) => {
|
||||
Some(weights_types.iter()
|
||||
.map(|ty| ty.to_db())
|
||||
.copied()
|
||||
.map(weights_type_to_db)
|
||||
.collect::<HashSet<_>>())
|
||||
},
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::{weights_type_to_api, weights_type_to_db};
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::error::ResponseError;
|
||||
@@ -180,7 +181,7 @@ pub async fn list_available_weights_handler(
|
||||
.sort_ascending(sort_ascending)
|
||||
.cursor_is_reversed(cursor_is_reversed)
|
||||
.weights_category(query.weight_category)
|
||||
.weights_type(query.weight_type.map(|wt| wt.to_db()))
|
||||
.weights_type(query.weight_type.map(weights_type_to_db))
|
||||
.scope_creator_username(None)
|
||||
.include_user_hidden(include_user_hidden)
|
||||
.include_user_deleted_results(false) // NB: Mods don't want to see deleted models. We'll improve this later.
|
||||
@@ -255,7 +256,7 @@ pub async fn list_available_weights_handler(
|
||||
weight_token: weight.token,
|
||||
maybe_url_slug: title_to_url_slug(&weight.title),
|
||||
title: weight.title,
|
||||
weight_type: WeightsType::from_db(weight.weights_type),
|
||||
weight_type: weights_type_to_api(weight.weights_type),
|
||||
weight_category: weight.weights_category,
|
||||
|
||||
maybe_ietf_language_tag: weight.maybe_ietf_language_tag,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_api;
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::error::ResponseError;
|
||||
@@ -259,7 +260,7 @@ pub async fn list_featured_weights_handler(
|
||||
title: w.title,
|
||||
maybe_ietf_language_tag: w.maybe_ietf_language_tag,
|
||||
maybe_ietf_primary_language_subtag: w.maybe_ietf_primary_language_subtag,
|
||||
weight_type: WeightsType::from_db(w.weights_type),
|
||||
weight_type: weights_type_to_api(w.weights_type),
|
||||
weight_category: w.weights_category,
|
||||
cover_image: cover_image_details,
|
||||
maybe_cover_image_public_bucket_path: maybe_cover_image,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_api;
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::error::ResponseError;
|
||||
@@ -180,7 +181,7 @@ pub async fn list_pinned_weights_handler(
|
||||
title: w.title,
|
||||
maybe_ietf_language_tag: w.maybe_ietf_language_tag,
|
||||
maybe_ietf_primary_language_subtag: w.maybe_ietf_primary_language_subtag,
|
||||
weight_type: WeightsType::from_db(w.weights_type),
|
||||
weight_type: weights_type_to_api(w.weights_type),
|
||||
weight_category: w.weights_category,
|
||||
cover_image: cover_image_details,
|
||||
maybe_cover_image_public_bucket_path: maybe_cover_image,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::weights_type_to_db;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -190,7 +191,7 @@ pub async fn list_weights_by_user_handler(
|
||||
sort_ascending,
|
||||
view_as,
|
||||
maybe_scoped_weight_category: query.maybe_scoped_weight_category,
|
||||
maybe_scoped_weight_type: query.maybe_scoped_weight_type.map(|w| w.to_db()),
|
||||
maybe_scoped_weight_type: query.maybe_scoped_weight_type.map(weights_type_to_db),
|
||||
mysql_pool: &server_state.mysql_pool,
|
||||
}
|
||||
).await.map_err(|e| {
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@
|
||||
#![forbid(unused_variables)]
|
||||
|
||||
use enums_api::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums_convert::by_table::model_weights::weights_types::{weights_type_to_api, weights_type_to_db};
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
@@ -158,7 +159,7 @@ pub async fn search_model_weights_impl(
|
||||
let maybe_weights_types = request.weight_type
|
||||
.map(|weight_type| {
|
||||
let mut set = HashSet::new();
|
||||
set.insert(weight_type.to_db());
|
||||
set.insert(weights_type_to_db(weight_type));
|
||||
set
|
||||
});
|
||||
|
||||
@@ -220,7 +221,7 @@ pub async fn search_model_weights_impl(
|
||||
|
||||
ModelWeightSearchResult {
|
||||
weight_token: result.token,
|
||||
weight_type: WeightsType::from_db(result.weights_type),
|
||||
weight_type: weights_type_to_api(result.weights_type),
|
||||
weight_category: result.weights_category,
|
||||
maybe_url_slug: title_to_url_slug(&result.title),
|
||||
title: result.title,
|
||||
|
||||
Reference in new issue
Block a user