Working on enqueue_tts_request assuming the prompt is around.

This commit is contained in:
Michael Chung committed 2023-10-02 16:15:25 -04:00
1 parent 1a75d5b7b3
commit 0b3ea3af2a
2 files changed
+71 -6

No files matched your search

@@ -1,15 +1,80 @@
#![forbid(unused_imports)]
#![forbid(unused_mut)]
#![forbid(unused_variables)]
use std::sync::Arc;
use actix_web::{HttpRequest, HttpResponse, web};
use actix_web::error::ResponseError;
use actix_web::http::StatusCode;
use log::{info, warn};
use enums::by_table::generic_inference_jobs::inference_category::InferenceCategory;
use enums::by_table::generic_inference_jobs::inference_model_type::InferenceModelType;
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
use tokens::jobs::inference::InferenceJobToken;
use crate::server_state::ServerState;
#[derive(Deserialize)]
pub struct EnqueueTTSRequest {
uuid_idempotency_token: String,
text: String
}
pub async fn enqueue_tts_request() -> HttpResponse {
#[derive(Serialize)]
pub struct EnqueueTTSRequestSuccessResponse {
pub success: bool,
pub inference_job_token: InferenceJobToken,
}
#[derive(Debug)]
pub enum EnqueueTTSRequestError {
BadInput(String),
NotAuthorized,
ServerError,
RateLimited,
}
impl ResponseError for EnqueueTTSRequestError {
fn status_code(&self) -> StatusCode {
match *self {
EnqueueTTSRequestError::BadInput(_) => StatusCode::BAD_REQUEST,
EnqueueTTSRequestError::NotAuthorized => StatusCode::UNAUTHORIZED,
EnqueueTTSRequestError::ServerError => StatusCode::INTERNAL_SERVER_ERROR,
EnqueueTTSRequestError::RateLimited => StatusCode::TOO_MANY_REQUESTS,
}
}
fn error_response(&self) -> HttpResponse {
let error_reason = match self {
EnqueueTTSRequestError::BadInput(reason) => reason.to_string(),
EnqueueTTSRequestError::NotAuthorized => "unauthorized".to_string(),
EnqueueTTSRequestError::ServerError => "server error".to_string(),
EnqueueTTSRequestError::RateLimited => "rate limited".to_string(),
};
to_simple_json_error(&error_reason, self.status_code())
}
}
impl std::fmt::Display for EnqueueTTSRequestError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub async fn enqueue_tts_request(http_request: HttpRequest,
request: web::Json<EnqueueTTSRequest>,
server_state: web::Data<Arc<ServerState>>) -> Result<HttpResponse,EnqueueTTSRequestError>
{
// Implementation for enqueuing a TTS request
HttpResponse::Ok().json("TTS request enqueued successfully")
let mut mysql_connection = server_state.mysql_pool
.acquire()
.await
.map_err(|err| {
warn!("MySql pool error: {:?}", err);
EnqueueTTSRequestError::ServerError
})?;
HttpResponse::Ok().json("TTS request enqueued successfully");
}
@@ -174,7 +174,7 @@ pub fn add_routes<T, B> (app: App<T>) -> App<T>
app = add_subscription_routes(app); /* /v1/subscriptions/... */
// TODO find a long term feature flag solution, since this code is likely deployed into production we don't want the route found.
let enable_voice_designer_route = false;
let enable_voice_designer_route = true;
if (enable_voice_designer_route) {
app = add_voice_designer_routes(app); /* /v1/voice_designer */
}