mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
query works
This commit is contained in:
1 parent
3b9f150e18
commit
d392d1e1ab
4 files changed
+21
-18
No files matched your search
@@ -7,15 +7,18 @@ use enums::common::generation::common_model_class::CommonModelClass;
|
||||
use enums::common::generation::common_model_type::CommonModelType;
|
||||
use enums::common::generation::common_resolution::CommonResolution;
|
||||
use enums::common::generation_provider::GenerationProvider;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use tokens::tokens::prompts::PromptToken;
|
||||
use utoipa::ToSchema;
|
||||
use utoipa::{IntoParams, ToSchema};
|
||||
|
||||
pub const BATCH_GET_PROMPTS_PATH: &str = "/v1/prompt/batch";
|
||||
|
||||
#[derive(Deserialize, ToSchema)]
|
||||
pub struct BatchGetPromptsRequest {
|
||||
pub tokens: Vec<PromptToken>,
|
||||
#[derive(Deserialize, ToSchema, IntoParams)]
|
||||
pub struct BatchGetPromptsQuery {
|
||||
/// Prompt tokens to look up.
|
||||
pub tokens: HashSet<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema)]
|
||||
|
||||
@@ -625,7 +625,7 @@ use crate::http_server::endpoints::media_files::list::list_batch_generated_redux
|
||||
BatchGetInferenceJobStatusQueryParams,
|
||||
BatchGetInferenceJobStatusSuccessResponse,
|
||||
BatchGetMediaFilesModelInfo,
|
||||
BatchGetPromptsRequest,
|
||||
BatchGetPromptsQuery,
|
||||
BatchGetPromptsResponse,
|
||||
BatchPromptInfo,
|
||||
CreatePromptRequest,
|
||||
|
||||
+12
-12
@@ -3,8 +3,9 @@ use std::sync::Arc;
|
||||
|
||||
use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest};
|
||||
use actix_web_lab::extract::Query;
|
||||
use artcraft_api_defs::prompts::batch_get_prompts::{
|
||||
BatchGetPromptsRequest, BatchGetPromptsResponse, BatchPromptInfo,
|
||||
BatchGetPromptsQuery, BatchGetPromptsResponse, BatchPromptInfo,
|
||||
};
|
||||
use artcraft_api_defs::prompts::get_prompt::GetPromptImageContextItem;
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
@@ -22,11 +23,13 @@ use crate::state::server_state::ServerState;
|
||||
const MAX_BATCH_SIZE: usize = 100;
|
||||
|
||||
/// Batch get details on multiple prompts.
|
||||
///
|
||||
/// Called, eg. {{api_host}}/v1/prompt/batch?tokens={val}&tokens={val}&tokens=...
|
||||
#[utoipa::path(
|
||||
post,
|
||||
get,
|
||||
tag = "Prompts",
|
||||
path = "/v1/prompt/batch",
|
||||
request_body = BatchGetPromptsRequest,
|
||||
params(BatchGetPromptsQuery),
|
||||
responses(
|
||||
(status = 200, description = "Found", body = BatchGetPromptsResponse),
|
||||
(status = 400, description = "Bad request"),
|
||||
@@ -35,22 +38,19 @@ const MAX_BATCH_SIZE: usize = 100;
|
||||
)]
|
||||
pub async fn batch_get_prompts_handler(
|
||||
http_request: HttpRequest,
|
||||
body: Json<BatchGetPromptsRequest>,
|
||||
query: Query<BatchGetPromptsQuery>,
|
||||
server_state: web::Data<Arc<ServerState>>,
|
||||
) -> Result<Json<BatchGetPromptsResponse>, AdvancedCommonWebError> {
|
||||
let request = body.into_inner();
|
||||
|
||||
if request.tokens.len() > MAX_BATCH_SIZE {
|
||||
if query.tokens.len() > MAX_BATCH_SIZE {
|
||||
return Err(AdvancedCommonWebError::BadInputWithSimpleMessage(
|
||||
format!("tokens must contain between 0 and {} items", MAX_BATCH_SIZE),
|
||||
format!("tokens must contain at most {} items", MAX_BATCH_SIZE),
|
||||
));
|
||||
}
|
||||
|
||||
// Deduplicate and trim whitespace
|
||||
let unique_tokens: Vec<PromptToken> = request
|
||||
.tokens
|
||||
.into_iter()
|
||||
.map(|t| PromptToken::new_from_str(t.as_str().trim()))
|
||||
let unique_tokens: Vec<PromptToken> = query.tokens
|
||||
.iter()
|
||||
.map(|t| PromptToken::new_from_str(t.trim()))
|
||||
.filter(|t| !t.as_str().is_empty())
|
||||
.collect::<HashSet<_>>()
|
||||
.into_iter()
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ where
|
||||
RouteBuilder::from_app(app)
|
||||
// NB: This poor RouteBuilder utility requires that POST comes first, otherwise the GET glob
|
||||
// will capture it and force 504 Method Not Allowed for all POSTs.
|
||||
.add_post("/v1/prompt/batch", batch_get_prompts_handler)
|
||||
.add_get("/v1/prompt/batch", batch_get_prompts_handler)
|
||||
.add_post("/v1/prompts/create", create_prompt_handler)
|
||||
.add_get("/v1/prompts/{token}", get_prompt_handler)
|
||||
.into_app()
|
||||
|
||||
Reference in new issue
Block a user