mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-10 03:51:25 +00:00
model_weights/create_weight.rs being worked on
This commit is contained in:
1 parent
c36ca5e73c
commit
bffe8d39ae
2 files changed
+135
-4
No files matched your search
@@ -37,6 +37,9 @@ pub enum IdCategory {
|
||||
/// Zs voice which lives in the zs_voices table
|
||||
#[serde(rename = "zs_voice")]
|
||||
ZeroShotVoiceEmbedding,
|
||||
|
||||
#[serde(rename = "model_weights")]
|
||||
ModelWeights,
|
||||
}
|
||||
|
||||
// TODO(bt, 2022-12-21): This desperately needs MySQL integration tests!
|
||||
@@ -53,6 +56,7 @@ impl IdCategory {
|
||||
Self::ZeroShotVoiceDataset => "zs_dataset",
|
||||
Self::ZeroShotVoiceEmbedding => "zs_voice",
|
||||
Self::ZeroShotTtsResult => "zs_tts_result",
|
||||
Self::ModelWeights => "model_weights",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +68,7 @@ impl IdCategory {
|
||||
"zs_dataset" => Ok(Self::ZeroShotVoiceDataset),
|
||||
"zs_voice" => Ok(Self::ZeroShotVoiceEmbedding),
|
||||
"zs_tts_result" => Ok(Self::ZeroShotTtsResult),
|
||||
"model_weights" => Ok(Self::ModelWeights),
|
||||
_ => Err(format!("invalid value: {:?}", value)),
|
||||
}
|
||||
}
|
||||
@@ -78,6 +83,7 @@ impl IdCategory {
|
||||
Self::ZeroShotTtsResult,
|
||||
Self::ZeroShotVoiceDataset,
|
||||
Self::ZeroShotVoiceEmbedding,
|
||||
Self::ModelWeights,
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -98,6 +104,7 @@ mod tests {
|
||||
assert_serialization(IdCategory::ZeroShotVoiceDataset, "zs_dataset");
|
||||
assert_serialization(IdCategory::ZeroShotVoiceEmbedding, "zs_voice");
|
||||
assert_serialization(IdCategory::ZeroShotTtsResult, "zs_tts_result");
|
||||
assert_serialization(IdCategory::ModelWeights, "model_weights")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -108,6 +115,7 @@ mod tests {
|
||||
assert_eq!(IdCategory::ZeroShotVoiceDataset.to_str(), "zs_dataset");
|
||||
assert_eq!(IdCategory::ZeroShotVoiceEmbedding.to_str(), "zs_voice");
|
||||
assert_eq!(IdCategory::ZeroShotTtsResult.to_str(), "zs_tts_result");
|
||||
assert_eq!(IdCategory::ModelWeights.to_str(), "model_weights");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -118,6 +126,7 @@ mod tests {
|
||||
assert_eq!(IdCategory::from_str("zs_dataset").unwrap(), IdCategory::ZeroShotVoiceDataset);
|
||||
assert_eq!(IdCategory::from_str("zs_voice").unwrap(), IdCategory::ZeroShotVoiceEmbedding);
|
||||
assert_eq!(IdCategory::from_str("zs_tts_result").unwrap(), IdCategory::ZeroShotTtsResult);
|
||||
assert_eq!(IdCategory::from_str("model_weights").unwrap(), IdCategory::ModelWeights);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -131,6 +140,7 @@ mod tests {
|
||||
assert_eq!(variants.pop_first(), Some(IdCategory::ZeroShotTtsResult));
|
||||
assert_eq!(variants.pop_first(), Some(IdCategory::ZeroShotVoiceDataset));
|
||||
assert_eq!(variants.pop_first(), Some(IdCategory::ZeroShotVoiceEmbedding));
|
||||
assert_eq!(variants.pop_first(), Some(IdCategory::ModelWeights));
|
||||
assert_eq!(variants.pop_first(), None);
|
||||
|
||||
// Generated check
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
use container_common::anyhow_result::AnyhowResult;
|
||||
use sqlx::MySqlPool;
|
||||
use enums::by_table::{generic_synthetic_ids::id_category::IdCategory, model_weights::{weights_types::WeightsType, weights_category::WeightsCategory}};
|
||||
use enums::by_table::{
|
||||
generic_synthetic_ids::id_category::IdCategory,
|
||||
model_weights::{ weights_types::WeightsType, weights_category::WeightsCategory },
|
||||
};
|
||||
use enums::common::visibility::Visibility;
|
||||
use tokens::tokens::users::UserToken;
|
||||
use tokens::tokens::{ users::UserToken, model_weights::{ ModelWeightToken, self } };
|
||||
|
||||
pub struct CreateModelWeightsArgs<'a> {
|
||||
pub token: &'a str,
|
||||
pub token: &'a ModelWeightToken,
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
pub title: String,
|
||||
@@ -28,4 +32,121 @@ pub struct CreateModelWeightsArgs<'a> {
|
||||
pub maybe_cached_user_ratings_ratio: Option<f32>,
|
||||
pub version: i32,
|
||||
pub mysql_pool: &'a MySqlPool,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_weight(args: CreateModelWeightsArgs<'_>) -> AnyhowResult<ModelWeightToken> {
|
||||
let model_weights_token = ModelWeightToken::generate();
|
||||
|
||||
let mut transaction = args.mysql_pool.begin().await?;
|
||||
|
||||
if let Some(create_user_token) = args.creator_user_token.as_deref() {
|
||||
let next_model_weights_synthetic_id = transactional_increment_generic_synthetic_id(
|
||||
create_user_token,
|
||||
IdCategory::ModelWeights,
|
||||
&mut transaction
|
||||
).await?;
|
||||
|
||||
maybe_creator_synthetic_id = Some(next_model_weights_synthetic_id);
|
||||
}
|
||||
|
||||
let query_result = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO model_weights
|
||||
SET
|
||||
token = ?,
|
||||
weights_type = ?,
|
||||
weights_category = ?,
|
||||
title = ?,
|
||||
maybe_thumbnail_token = ?,
|
||||
description_markdown = ?,
|
||||
description_rendered_html = ?,
|
||||
creator_user_token = ?,
|
||||
creator_ip_address = ?,
|
||||
creator_set_visibility = ?,
|
||||
maybe_last_update_user_token = ?,
|
||||
original_download_url = ?,
|
||||
original_filename = ?,
|
||||
file_size_bytes = ?,
|
||||
file_checksum_sha2 = ?,
|
||||
private_bucket_hash = ?,
|
||||
maybe_private_bucket_prefix = ?,
|
||||
maybe_private_bucket_extension = ?,
|
||||
cached_user_ratings_total_count = ?,
|
||||
cached_user_ratings_positive_count = ?,
|
||||
cached_user_ratings_negative_count = ?,
|
||||
maybe_cached_user_ratings_ratio = ?,
|
||||
version = ?
|
||||
"#,
|
||||
args.token.as_str(),
|
||||
args.weights_type.to_str(),
|
||||
args.weights_category.to_str(),
|
||||
args.title,
|
||||
args.maybe_thumbnail_token,
|
||||
args.description_markdown,
|
||||
args.description_rendered_html,
|
||||
args.creator_user_token,
|
||||
args.creator_ip_address,
|
||||
args.creator_set_visibility.to_str(),
|
||||
args.maybe_last_update_user_token,
|
||||
args.original_download_url,
|
||||
args.original_filename,
|
||||
args.file_size_bytes,
|
||||
args.file_checksum_sha2,
|
||||
args.private_bucket_hash,
|
||||
args.maybe_private_bucket_prefix,
|
||||
args.maybe_private_bucket_extension,
|
||||
args.cached_user_ratings_total_count,
|
||||
args.cached_user_ratings_positive_count,
|
||||
args.cached_user_ratings_negative_count,
|
||||
args.maybe_cached_user_ratings_ratio,
|
||||
args.version
|
||||
).execute(args.mysql_pool).await;
|
||||
|
||||
match query_result {
|
||||
Ok(_) => {
|
||||
Ok(model_weights_token);
|
||||
}
|
||||
Err(err) => {
|
||||
transaction.rollback().await?;
|
||||
warn!("Transaction failure: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE TABLE model_weights (
|
||||
// id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
// token VARCHAR(32) NOT NULL,
|
||||
// weights_type VARCHAR(32) NOT NULL,
|
||||
// weights_category VARCHAR(32) NOT NULL,
|
||||
// title VARCHAR(255) NOT NULL,
|
||||
// maybe_thumbnail_token VARCHAR(32) DEFAULT NULL,
|
||||
// description_markdown TEXT NOT NULL,
|
||||
// description_rendered_html TEXT NOT NULL,
|
||||
// creator_user_token VARCHAR(32) NOT NULL,
|
||||
// creator_ip_address VARCHAR(40) NOT NULL,
|
||||
// creator_set_visibility ENUM(
|
||||
// 'public',
|
||||
// 'hidden',
|
||||
// 'private'
|
||||
// ) NOT NULL DEFAULT 'public',
|
||||
// maybe_last_update_user_token VARCHAR(32) DEFAULT NULL,
|
||||
// original_download_url VARCHAR(512) DEFAULT NULL,
|
||||
// original_filename VARCHAR(255) DEFAULT NULL,
|
||||
// file_size_bytes INT(10) NOT NULL DEFAULT 0,
|
||||
// file_checksum_sha2 CHAR(64) NOT NULL,
|
||||
// private_bucket_hash VARCHAR(32) NOT NULL,
|
||||
// maybe_private_bucket_prefix VARCHAR(16) DEFAULT NULL,
|
||||
// maybe_private_bucket_extension VARCHAR(16) DEFAULT NULL,
|
||||
// cached_user_ratings_total_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
// cached_user_ratings_positive_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
// cached_user_ratings_negative_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
// maybe_cached_user_ratings_ratio FLOAT,
|
||||
// cached_user_ratings_last_updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
// version INT NOT NULL DEFAULT 0,
|
||||
// created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
// updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
// user_deleted_at TIMESTAMP NULL,
|
||||
// mod_deleted_at TIMESTAMP NULL,
|
||||
// PRIMARY KEY (id),
|
||||
// UNIQUE KEY (token)
|
||||
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
Reference in new issue
Block a user