mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
image gen
This commit is contained in:
1 parent
e64c3dcdb6
commit
b8bec541e7
20 files changed
+244
-5
No files matched your search
+1
@@ -1 +1,2 @@
|
||||
pub mod omni_gen_image_cost_and_generate_request;
|
||||
pub mod omni_gen_video_cost_and_generate_request;
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use enums::common::generation::common_aspect_ratio::CommonAspectRatio;
|
||||
use enums::common::generation::common_image_model::CommonImageModel;
|
||||
use enums::common::generation::common_quality::CommonQuality;
|
||||
use enums::common::generation::common_resolution::CommonResolution;
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
/// Shared request body for both the image cost estimate and image generation endpoints.
|
||||
#[derive(Serialize, Deserialize, ToSchema, Debug)]
|
||||
pub struct OmniGenImageCostAndGenerateRequest {
|
||||
/// REQUIRED (even if marked optional)
|
||||
/// Idempotency token to prevent duplicate requests.
|
||||
/// If not supplied, we'll generate one for the required providers.
|
||||
pub idempotency_token: Option<String>,
|
||||
|
||||
/// REQUIRED (even if marked optional)
|
||||
/// Which model to use.
|
||||
pub model: Option<CommonImageModel>,
|
||||
|
||||
/// The prompt for the image generation.
|
||||
pub prompt: Option<String>,
|
||||
|
||||
/// Input images for image editing.
|
||||
/// If present, we're doing image editing (image-to-image).
|
||||
/// If absent, we're doing text-to-image.
|
||||
pub image_media_tokens: Option<Vec<MediaFileToken>>,
|
||||
|
||||
/// The resolution to use.
|
||||
pub resolution: Option<CommonResolution>,
|
||||
|
||||
/// The aspect ratio to use.
|
||||
pub aspect_ratio: Option<CommonAspectRatio>,
|
||||
|
||||
/// The quality to use.
|
||||
pub quality: Option<CommonQuality>,
|
||||
|
||||
/// How many images to generate.
|
||||
pub image_batch_count: Option<u16>,
|
||||
|
||||
/// Only for angle manipulation models.
|
||||
pub horizontal_angle: Option<f64>,
|
||||
|
||||
/// Only for angle manipulation models.
|
||||
pub vertical_angle: Option<f64>,
|
||||
|
||||
/// Only for angle manipulation models.
|
||||
pub zoom: Option<f64>,
|
||||
}
|
||||
+4
-2
@@ -10,11 +10,13 @@ use tokens::tokens::media_files::MediaFileToken;
|
||||
/// Shared request body for both the video cost estimate and video generation endpoints.
|
||||
#[derive(Serialize, Deserialize, ToSchema, Debug)]
|
||||
pub struct OmniGenVideoCostAndGenerateRequest {
|
||||
/// REQUIRED (even if marked optional)
|
||||
/// Idempotency token to prevent duplicate requests.
|
||||
pub idempotency_token: String,
|
||||
pub idempotency_token: Option<String>,
|
||||
|
||||
/// REQUIRED (even if marked optional)
|
||||
/// Which model to use.
|
||||
pub model: CommonVideoModel,
|
||||
pub model: Option<CommonVideoModel>,
|
||||
|
||||
/// The text prompt for the video generation.
|
||||
pub prompt: Option<String>,
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod omni_gen_image_cost_response;
|
||||
pub mod omni_gen_video_cost_response;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Response body for the omni-gen image cost estimate endpoint.
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
pub struct OmniGenImageCostResponse {
|
||||
pub success: bool,
|
||||
|
||||
/// Estimated cost in credits.
|
||||
pub cost_in_credits: Option<u64>,
|
||||
|
||||
/// Estimated cost in USD cents.
|
||||
pub cost_in_usd_cents: Option<u64>,
|
||||
|
||||
/// Whether the generation is free for this user/plan.
|
||||
pub is_free: bool,
|
||||
|
||||
/// Whether the user has unlimited generations.
|
||||
pub is_unlimited: bool,
|
||||
|
||||
/// Whether the user is rate limited.
|
||||
pub is_rate_limited: bool,
|
||||
|
||||
/// Whether the output will have a watermark.
|
||||
pub has_watermark: bool,
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod omni_gen_image_generate_response;
|
||||
pub mod omni_gen_video_generate_response;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use tokens::tokens::generic_inference_jobs::InferenceJobToken;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Response body for the omni-gen image generation endpoint.
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
pub struct OmniGenImageGenerateResponse {
|
||||
pub success: bool,
|
||||
pub inference_job_token: InferenceJobToken,
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod omni_gen_image_models;
|
||||
pub mod omni_gen_video_models;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use utoipa::{IntoParams, ToSchema};
|
||||
|
||||
/// Query string parameters for the image models endpoint.
|
||||
#[derive(Deserialize, IntoParams)]
|
||||
pub struct OmniGenImageModelsQuery {
|
||||
/// Which provider's models to list. Defaults to "artcraft" if absent.
|
||||
pub provider: Option<OmniGenImageModelsProvider>,
|
||||
}
|
||||
|
||||
/// The provider filter for the models endpoint.
|
||||
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum OmniGenImageModelsProvider {
|
||||
/// Only models available through ArtCraft.
|
||||
Artcraft,
|
||||
/// All known models across all providers.
|
||||
All,
|
||||
}
|
||||
|
||||
impl Default for OmniGenImageModelsProvider {
|
||||
fn default() -> Self {
|
||||
Self::Artcraft
|
||||
}
|
||||
}
|
||||
|
||||
/// Response body for the image models endpoint.
|
||||
/// TBD — fields will be added later.
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct OmniGenImageModelsResponse {
|
||||
pub success: bool,
|
||||
}
|
||||
+3
-3
@@ -5,20 +5,20 @@ use utoipa::{IntoParams, ToSchema};
|
||||
#[derive(Deserialize, IntoParams)]
|
||||
pub struct OmniGenVideoModelsQuery {
|
||||
/// Which provider's models to list. Defaults to "artcraft" if absent.
|
||||
pub provider: Option<OmniGenModelsProvider>,
|
||||
pub provider: Option<OmniGenVideoModelsProvider>,
|
||||
}
|
||||
|
||||
/// The provider filter for the models endpoint.
|
||||
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum OmniGenModelsProvider {
|
||||
pub enum OmniGenVideoModelsProvider {
|
||||
/// Only models available through ArtCraft.
|
||||
Artcraft,
|
||||
/// All known models across all providers.
|
||||
All,
|
||||
}
|
||||
|
||||
impl Default for OmniGenModelsProvider {
|
||||
impl Default for OmniGenVideoModelsProvider {
|
||||
fn default() -> Self {
|
||||
Self::Artcraft
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
pub mod omni_gen_image_cost_handler;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest};
|
||||
|
||||
use artcraft_api_defs::omni_gen::cost_and_generate_requests::omni_gen_image_cost_and_generate_request::OmniGenImageCostAndGenerateRequest;
|
||||
use artcraft_api_defs::omni_gen::cost_response::omni_gen_image_cost_response::OmniGenImageCostResponse;
|
||||
|
||||
use crate::http_server::common_responses::common_web_error::CommonWebError;
|
||||
use crate::state::server_state::ServerState;
|
||||
|
||||
/// Estimate the cost of an image generation.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
tag = "Omni Gen",
|
||||
path = "/v1/omni_gen/cost/image",
|
||||
request_body = OmniGenImageCostAndGenerateRequest,
|
||||
responses(
|
||||
(status = 200, description = "Success", body = OmniGenImageCostResponse),
|
||||
(status = 400, description = "Bad input"),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 500, description = "Server error"),
|
||||
),
|
||||
)]
|
||||
pub async fn omni_gen_image_cost_handler(
|
||||
_http_request: HttpRequest,
|
||||
_request: Json<OmniGenImageCostAndGenerateRequest>,
|
||||
_server_state: web::Data<Arc<ServerState>>,
|
||||
) -> Result<Json<OmniGenImageCostResponse>, CommonWebError> {
|
||||
todo!()
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod image;
|
||||
pub mod video;
|
||||
+1
@@ -0,0 +1 @@
|
||||
pub mod omni_gen_image_generate_handler;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest};
|
||||
|
||||
use artcraft_api_defs::omni_gen::cost_and_generate_requests::omni_gen_image_cost_and_generate_request::OmniGenImageCostAndGenerateRequest;
|
||||
use artcraft_api_defs::omni_gen::generate_response::omni_gen_image_generate_response::OmniGenImageGenerateResponse;
|
||||
|
||||
use crate::http_server::common_responses::common_web_error::CommonWebError;
|
||||
use crate::state::server_state::ServerState;
|
||||
|
||||
/// Generate an image using the omni-gen unified endpoint.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
tag = "Omni Gen",
|
||||
path = "/v1/omni_gen/generate/image",
|
||||
request_body = OmniGenImageCostAndGenerateRequest,
|
||||
responses(
|
||||
(status = 200, description = "Success", body = OmniGenImageGenerateResponse),
|
||||
(status = 400, description = "Bad input"),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 402, description = "Payment required"),
|
||||
(status = 500, description = "Server error"),
|
||||
),
|
||||
)]
|
||||
pub async fn omni_gen_image_generate_handler(
|
||||
_http_request: HttpRequest,
|
||||
_request: Json<OmniGenImageCostAndGenerateRequest>,
|
||||
_server_state: web::Data<Arc<ServerState>>,
|
||||
) -> Result<Json<OmniGenImageGenerateResponse>, CommonWebError> {
|
||||
todo!()
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod image;
|
||||
pub mod video;
|
||||
+1
@@ -0,0 +1 @@
|
||||
pub mod omni_gen_image_models_handler;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web::{Json, Query};
|
||||
use actix_web::{web, HttpRequest};
|
||||
|
||||
use artcraft_api_defs::omni_gen::models::omni_gen_image_models::{
|
||||
OmniGenImageModelsQuery,
|
||||
OmniGenImageModelsResponse,
|
||||
};
|
||||
|
||||
use crate::http_server::common_responses::common_web_error::CommonWebError;
|
||||
use crate::state::server_state::ServerState;
|
||||
|
||||
/// List available image models.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
tag = "Omni Gen",
|
||||
path = "/v1/omni_gen/models/image",
|
||||
params(OmniGenImageModelsQuery),
|
||||
responses(
|
||||
(status = 200, description = "Success", body = OmniGenImageModelsResponse),
|
||||
(status = 500, description = "Server error"),
|
||||
),
|
||||
)]
|
||||
pub async fn omni_gen_image_models_handler(
|
||||
_http_request: HttpRequest,
|
||||
_query: Query<OmniGenImageModelsQuery>,
|
||||
_server_state: web::Data<Arc<ServerState>>,
|
||||
) -> Result<Json<OmniGenImageModelsResponse>, CommonWebError> {
|
||||
todo!()
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod image;
|
||||
pub mod video;
|
||||
+15
@@ -3,8 +3,11 @@ use actix_service::ServiceFactory;
|
||||
use actix_web::dev::{ServiceRequest, ServiceResponse};
|
||||
use actix_web::{web, App, Error, HttpResponse};
|
||||
|
||||
use crate::http_server::endpoints::omni_gen::cost::image::omni_gen_image_cost_handler::omni_gen_image_cost_handler;
|
||||
use crate::http_server::endpoints::omni_gen::cost::video::omni_gen_video_cost_handler::omni_gen_video_cost_handler;
|
||||
use crate::http_server::endpoints::omni_gen::generate::image::omni_gen_image_generate_handler::omni_gen_image_generate_handler;
|
||||
use crate::http_server::endpoints::omni_gen::generate::video::omni_gen_video_generate_handler::omni_gen_video_generate_handler;
|
||||
use crate::http_server::endpoints::omni_gen::models::image::omni_gen_image_models_handler::omni_gen_image_models_handler;
|
||||
use crate::http_server::endpoints::omni_gen::models::video::omni_gen_video_models_handler::omni_gen_video_models_handler;
|
||||
|
||||
pub fn add_omni_gen_routes<T, B>(app: App<T>) -> App<T>
|
||||
@@ -24,18 +27,30 @@ where
|
||||
.route(web::post().to(omni_gen_video_cost_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
.service(web::resource("/image")
|
||||
.route(web::post().to(omni_gen_image_cost_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
)
|
||||
.service(web::scope("/generate")
|
||||
.service(web::resource("/video")
|
||||
.route(web::post().to(omni_gen_video_generate_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
.service(web::resource("/image")
|
||||
.route(web::post().to(omni_gen_image_generate_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
)
|
||||
.service(web::scope("/models")
|
||||
.service(web::resource("/video")
|
||||
.route(web::get().to(omni_gen_video_models_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
.service(web::resource("/image")
|
||||
.route(web::get().to(omni_gen_image_models_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user