header to route TT2 requests to new worker

This commit is contained in:
Brandon Thomas committed 2023-04-06 22:00:44 -07:00
1 parent 311299105b
commit 79ad78bdde
1 file changed
+23 -8
@@ -8,8 +8,10 @@ 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::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;
use crate::server_state::ServerState;
use enums::by_table::tts_models::tts_model_type::TtsModelType;
use enums::common::visibility::Visibility;
use enums::workers::generic_inference_type::GenericInferenceType;
use http_server_common::request::get_request_api_token::get_request_api_token;
@@ -27,21 +29,31 @@ use rand::seq::SliceRandom;
use redis_common::redis_keys::RedisKeys;
use std::fmt;
use std::sync::Arc;
use enums::by_table::tts_models::tts_model_type::TtsModelType;
use tokens::jobs::inference::InferenceJobToken;
use tokens::tokens::tts_models::TtsModelToken;
use tokens::users::user::UserToken;
use tts_common::priority::{FAKEYOU_INVESTOR_PRIORITY_LEVEL, FAKEYOU_DEFAULT_VALID_API_TOKEN_PRIORITY_LEVEL};
use user_input_common::check_for_slurs::contains_slurs;
use users_component::utils::user_session_extended::UserSessionExtended;
use crate::http_server::endpoints::tts::enqueue_infer_tts_handler::get_model_with_caching::get_model_with_caching;
// TODO: Temporary for investor demo
const STORYTELLER_DEMO_COOKIE_NAME : &'static str = "storyteller_demo";
/// Debug requests can get routed to special "debug-only" workers, which can
/// be used to trial new code, run debugging, etc.
const DEBUG_HEADER_NAME : &'static str = "enable_debug_mode";
/// Debug requests mean different things, depending on the type of worker (the legacy
/// tts-inference-job vs. the new inference-job):
///
/// * Legacy (tts): these requests get routed to special "debug-only" workers, which can
/// be used to trial new code, run debugging, etc.
///
/// * New (generic): the flag gets associated with the request which may be used for
/// anything in the code. (There's a new system for routing requests called
/// "routing tags" that is independent of this flag.)
///
const DEBUG_HEADER_NAME : &'static str = "enable-debug-mode";
/// Requests with this header can be forced onto the new jobs system.
/// It'll be used to help test TT2 on the new system before it is rolled out for everyone.
const NEW_JOB_SYSTEM_HEADER_NAME : &'static str = "new-job-system";
const USER_FAKEYOU_USER_TOKEN : &'static str = "U:N5J8JXPW9BTYX";
const USER_NEWS_STORY_USER_TOKEN : &'static str = "U:XAWRARC1N89X6";
@@ -205,11 +217,14 @@ pub async fn enqueue_infer_tts_handler(
priority_level = FAKEYOU_INVESTOR_PRIORITY_LEVEL;
}
// ==================== DEBUG MODE ==================== //
// ==================== ENGINEERING FLAGS / HEADERS: DEBUG MODE, ETC. ==================== //
let is_debug_request = get_request_header_optional(&http_request, DEBUG_HEADER_NAME)
.is_some();
let use_new_job_system_for_request = get_request_header_optional(&http_request, NEW_JOB_SYSTEM_HEADER_NAME)
.is_some();
// ==================== RATE LIMIT ==================== //
if !disable_rate_limiter {
@@ -333,8 +348,8 @@ pub async fn enqueue_infer_tts_handler(
// ==================== ENQUEUE APPROPRIATE TTS TYPE ==================== //
let use_new_job_system = match tts_model.tts_model_type {
TtsModelType::Tacotron2 => server_state.flags.enable_enqueue_generic_tts_job,
TtsModelType::Vits => true,
TtsModelType::Vits => true, // VITS is only on the new system.
TtsModelType::Tacotron2 => use_new_job_system_for_request || server_state.flags.enable_enqueue_generic_tts_job,
};
let job_token;