mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-19 08:05:20 +00:00
variable length tts inference text
This commit is contained in:
1 parent
6ec39b9c68
commit
7cd8099ab5
3 files changed
+39
-7
No files matched your search
@@ -46,6 +46,7 @@ pub struct Plan {
|
||||
|
||||
tts_base_priority_level: u8,
|
||||
tts_max_duration: Duration,
|
||||
tts_max_character_length: usize,
|
||||
tts_can_generate_mp3: bool, // TODO: This feature doesn't exist yet.
|
||||
tts_can_upload_private_models: bool,
|
||||
tts_can_share_private_models: bool,
|
||||
@@ -82,6 +83,7 @@ impl Plan {
|
||||
is_synthetic_plan: builder.is_synthetic_plan,
|
||||
tts_base_priority_level: builder.tts_base_priority_level,
|
||||
tts_max_duration: builder.tts_max_duration,
|
||||
tts_max_character_length: builder.tts_max_character_length,
|
||||
tts_can_generate_mp3: builder.tts_can_generate_mp3,
|
||||
tts_can_upload_private_models: builder.tts_can_upload_private_models,
|
||||
tts_can_share_private_models: builder.tts_can_share_private_models,
|
||||
@@ -140,6 +142,10 @@ impl Plan {
|
||||
self.tts_max_duration.num_seconds() as i32
|
||||
}
|
||||
|
||||
pub fn tts_max_character_length(&self) -> usize {
|
||||
self.tts_max_character_length
|
||||
}
|
||||
|
||||
pub fn web_vc_base_priority_level(&self) -> u8 {
|
||||
self.web_vc_base_priority_level
|
||||
}
|
||||
@@ -160,6 +166,7 @@ pub struct PlanBuilder {
|
||||
|
||||
tts_base_priority_level: u8,
|
||||
tts_max_duration: Duration,
|
||||
tts_max_character_length: usize,
|
||||
tts_can_generate_mp3: bool,
|
||||
tts_can_upload_private_models: bool,
|
||||
tts_can_share_private_models: bool,
|
||||
@@ -199,6 +206,8 @@ impl PlanBuilder {
|
||||
// TTS
|
||||
tts_base_priority_level : TTS_DEFAULT_PRIORITY_LEVEL,
|
||||
tts_max_duration: Duration::seconds(TTS_DEFAULT_DURATION_SECONDS),
|
||||
// NB: 1024 was the global (all plan) character limit until 2023-05-15 !
|
||||
tts_max_character_length: 1024,
|
||||
tts_can_generate_mp3 : false,
|
||||
tts_can_upload_private_models: false,
|
||||
tts_can_share_private_models : false,
|
||||
@@ -263,6 +272,11 @@ impl PlanBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tts_max_character_length(mut self, value: usize) -> Self {
|
||||
self.tts_max_character_length = value;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tts_can_generate_mp3(mut self, value: bool) -> Self {
|
||||
self.tts_can_generate_mp3 = value;
|
||||
self
|
||||
|
||||
@@ -12,6 +12,7 @@ pub static FREE_LOGGED_OUT_PLAN : Lazy<Plan> = Lazy::new(|| {
|
||||
.is_synthetic_plan(true)
|
||||
.plan_category(PlanCategory::Free)
|
||||
.tts_base_priority_level(FAKEYOU_ANONYMOUS_PRIORITY_LEVEL)
|
||||
.tts_max_character_length(1024)
|
||||
.web_vc_base_priority_level(FAKEYOU_ANONYMOUS_PRIORITY_LEVEL)
|
||||
.build()
|
||||
});
|
||||
@@ -23,6 +24,7 @@ pub static FREE_LOGGED_OUT_FIRST_TRY_PLAN : Lazy<Plan> = Lazy::new(|| {
|
||||
.is_synthetic_plan(true)
|
||||
.plan_category(PlanCategory::Free)
|
||||
.tts_base_priority_level(FAKEYOU_LOGGED_IN_PRIORITY_LEVEL) // NB: Same as logged-in free users.
|
||||
.tts_max_character_length(1024)
|
||||
.web_vc_base_priority_level(FAKEYOU_LOGGED_IN_PRIORITY_LEVEL) // NB: Same as logged-in free users.
|
||||
.build()
|
||||
});
|
||||
@@ -34,6 +36,7 @@ pub static FREE_LOGGED_IN_PLAN : Lazy<Plan> = Lazy::new(|| {
|
||||
.is_synthetic_plan(true)
|
||||
.plan_category(PlanCategory::Free)
|
||||
.tts_base_priority_level(FAKEYOU_LOGGED_IN_PRIORITY_LEVEL)
|
||||
.tts_max_character_length(1024)
|
||||
.web_vc_base_priority_level(FAKEYOU_LOGGED_IN_PRIORITY_LEVEL)
|
||||
.build()
|
||||
});
|
||||
@@ -46,8 +49,9 @@ pub static LOYALTY_PLANS : Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.is_synthetic_plan(true)
|
||||
.plan_category(PlanCategory::LoyaltyReward)
|
||||
.tts_base_priority_level(2)
|
||||
.web_vc_base_priority_level(2)
|
||||
.tts_max_character_length(2048)
|
||||
.tts_max_duration_seconds(30)
|
||||
.web_vc_base_priority_level(2)
|
||||
.build());
|
||||
|
||||
plans
|
||||
@@ -66,6 +70,7 @@ pub static DEVELOPMENT_PREMIUM_PLANS: Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.stripe_price_id("price_1LeDnKEU5se17MekVr1iYYNf")
|
||||
.cost_per_month_dollars(7)
|
||||
.tts_base_priority_level(20)
|
||||
.tts_max_character_length(2048)
|
||||
.tts_max_duration_seconds(30)
|
||||
.build());
|
||||
|
||||
@@ -76,6 +81,7 @@ pub static DEVELOPMENT_PREMIUM_PLANS: Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.stripe_price_id("price_1LjgwIEU5se17MekzQZUHl9W")
|
||||
.cost_per_month_dollars(15)
|
||||
.tts_base_priority_level(30)
|
||||
.tts_max_character_length(2048)
|
||||
.tts_max_duration_seconds(60 * 2)
|
||||
.build());
|
||||
|
||||
@@ -86,6 +92,7 @@ pub static DEVELOPMENT_PREMIUM_PLANS: Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.stripe_price_id("price_1M4dAbEU5se17MekEmwnee41")
|
||||
.cost_per_month_dollars(25)
|
||||
.tts_base_priority_level(40)
|
||||
.tts_max_character_length(2048)
|
||||
.tts_max_duration_seconds(60 * 5)
|
||||
.build());
|
||||
|
||||
@@ -104,8 +111,9 @@ pub static PRODUCTION_PREMIUM_PLANS: Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.stripe_price_id("price_1M4jDCEU5se17MekOaJ92HYX")
|
||||
.cost_per_month_dollars(7)
|
||||
.tts_base_priority_level(20)
|
||||
.web_vc_base_priority_level(20)
|
||||
.tts_max_character_length(2048)
|
||||
.tts_max_duration_seconds(30)
|
||||
.web_vc_base_priority_level(20)
|
||||
.build());
|
||||
|
||||
plans.insert(PlanBuilder::new("fakeyou_pro")
|
||||
@@ -114,8 +122,9 @@ pub static PRODUCTION_PREMIUM_PLANS: Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.stripe_price_id("price_1M4jEQEU5se17MeksNfA0EKm")
|
||||
.cost_per_month_dollars(15)
|
||||
.tts_base_priority_level(30)
|
||||
.web_vc_base_priority_level(30)
|
||||
.tts_max_character_length(3072)
|
||||
.tts_max_duration_seconds(60 * 2)
|
||||
.web_vc_base_priority_level(30)
|
||||
.build());
|
||||
|
||||
plans.insert(PlanBuilder::new("fakeyou_elite")
|
||||
@@ -124,8 +133,9 @@ pub static PRODUCTION_PREMIUM_PLANS: Lazy<HashSet<Plan>> = Lazy::new(|| {
|
||||
.stripe_price_id("price_1M4jFREU5se17Mekc8pQaSKB")
|
||||
.cost_per_month_dollars(25)
|
||||
.tts_base_priority_level(40)
|
||||
.web_vc_base_priority_level(40)
|
||||
.tts_max_character_length(4096)
|
||||
.tts_max_duration_seconds(60 * 5)
|
||||
.web_vc_base_priority_level(40)
|
||||
.build());
|
||||
|
||||
// ========== Spanish plans ==========
|
||||
|
||||
+11
-3
@@ -7,6 +7,7 @@ use actix_web::error::ResponseError;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::{web, HttpResponse, HttpRequest};
|
||||
use crate::configs::plans::get_correct_plan_for_session::get_correct_plan_for_session;
|
||||
use crate::configs::plans::plan::Plan;
|
||||
use crate::http_server::endpoints::investor_demo::demo_cookie::request_has_demo_cookie;
|
||||
use crate::http_server::endpoints::tts::enqueue_infer_tts_handler::get_model_with_caching::get_model_with_caching;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
@@ -62,6 +63,9 @@ const ROUTING_TAG_HEADER_NAME : &'static str = "routing-tag";
|
||||
const USER_FAKEYOU_USER_TOKEN : &'static str = "U:N5J8JXPW9BTYX";
|
||||
const USER_NEWS_STORY_USER_TOKEN : &'static str = "U:XAWRARC1N89X6";
|
||||
|
||||
/// Safety guard against plans supporting too lengthy TTS inference text.
|
||||
const MAX_TTS_LENGTH : usize = 10_000;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct InferTtsRequest {
|
||||
uuid_idempotency_token: String,
|
||||
@@ -298,7 +302,7 @@ pub async fn enqueue_infer_tts_handler(
|
||||
|
||||
let mut inference_text = request.inference_text.trim().to_string();
|
||||
|
||||
if let Err(reason) = validate_inference_text(&inference_text) {
|
||||
if let Err(reason) = validate_inference_text(&inference_text, &plan) {
|
||||
return Err(InferTtsError::BadInput(reason));
|
||||
}
|
||||
|
||||
@@ -466,12 +470,16 @@ pub async fn enqueue_infer_tts_handler(
|
||||
.body(body))
|
||||
}
|
||||
|
||||
pub fn validate_inference_text(text: &str) -> Result<(), String> {
|
||||
pub fn validate_inference_text(text: &str, plan: &Plan) -> Result<(), String> {
|
||||
if text.len() < 3 {
|
||||
return Err("text is too short".to_string());
|
||||
}
|
||||
|
||||
if text.len() > 1024 {
|
||||
if text.len() > plan.tts_max_character_length() {
|
||||
return Err("text is too long".to_string());
|
||||
}
|
||||
|
||||
if text.len() > MAX_TTS_LENGTH {
|
||||
return Err("text is too long".to_string());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user