mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-18 07:35:19 +00:00
grok video aspect ratio
This commit is contained in:
1 parent
0f0bd4c907
commit
b4f8a54e75
8 files changed
+141
-3
No files matched your search
@@ -0,0 +1,13 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Clone, Copy, Debug)]
|
||||
pub enum AspectRatio {
|
||||
#[serde(rename = "2:3")]
|
||||
TallTwoByThree,
|
||||
|
||||
#[serde(rename = "3:2")]
|
||||
WideThreeByTwo,
|
||||
|
||||
#[serde(rename = "1:1")]
|
||||
Square,
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod aspect_ratio;
|
||||
pub mod baggage;
|
||||
pub mod file_id;
|
||||
pub mod post_id;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::credentials::grok_full_credentials::GrokFullCredentials;
|
||||
use crate::datatypes::api::aspect_ratio::AspectRatio;
|
||||
use crate::datatypes::api::file_id::FileId;
|
||||
use crate::datatypes::api::post_id::PostId;
|
||||
use crate::datatypes::file_upload_spec::FileUploadSpec;
|
||||
@@ -23,6 +24,9 @@ pub struct UploadImageAndGenerateVideo<'a, P: AsRef<Path>> {
|
||||
/// Video generation prompt
|
||||
pub prompt: Option<&'a str>,
|
||||
|
||||
/// Aspect ratio for the video.
|
||||
pub aspect_ratio: Option<AspectRatio>,
|
||||
|
||||
/// Wait for the full video to be generated before returning
|
||||
/// By default, the endpoint stays open for 30-ish seconds while
|
||||
/// the video generates and streams back JSON progress updates.
|
||||
@@ -109,6 +113,7 @@ pub async fn upload_image_and_generate_video<P: AsRef<Path>>(args: UploadImageAn
|
||||
media_type: VideoMediaPostType::UserUploadedImage,
|
||||
cookie: args.full_credentials.cookies.as_str(),
|
||||
prompt: args.prompt,
|
||||
aspect_ratio: args.aspect_ratio,
|
||||
request_timeout: args.individual_request_timeout,
|
||||
baggage: &args.full_credentials.client_secrets.baggage,
|
||||
sentry_trace: &args.full_credentials.client_secrets.sentry_trace,
|
||||
@@ -177,7 +182,7 @@ mod tests {
|
||||
use crate::test_utils::setup_test_logging::setup_test_logging;
|
||||
use errors::AnyhowResult;
|
||||
use log::LevelFilter;
|
||||
|
||||
use crate::datatypes::api::aspect_ratio::AspectRatio;
|
||||
// Result: GrokUploadFileResponse { file_metadata_id:
|
||||
// Some("acdee48f-9d6f-4bc6-9d06-fcc97dd4418a"), file_uri:
|
||||
// Some("users/85980643-ffab-4984-a3de-59a608c47d7f/acdee48f-9d6f-4bc6-9d06-fcc97dd4418a/content") }
|
||||
@@ -211,6 +216,7 @@ mod tests {
|
||||
full_credentials: &credentials,
|
||||
file: FileUploadSpec::Path(image_path),
|
||||
prompt: maybe_prompt,
|
||||
aspect_ratio: Some(AspectRatio::Square),
|
||||
individual_request_timeout: None,
|
||||
wait_for_generation: false,
|
||||
}).await?;
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
curl 'https://grok.com/rest/app-chat/conversations/new' \
|
||||
-H 'accept: */*' \
|
||||
-H 'accept-language: en-US,en;q=0.9' \
|
||||
-H 'baggage: sentry-environment=production,sentry-public_key=b311e0f2690c81f25e2c4cf6d4f7ce1c,sentry-trace_id=a0dfe5fb521c4aff81dc8e4c29ddf512,sentry-org_id=4508179396558848,sentry-transaction=%2F%3Aslug*%3F,sentry-sampled=false,sentry-sample_rand=0.2766847188981013,sentry-sample_rate=0' \
|
||||
-H 'cache-control: no-cache' \
|
||||
-H 'content-type: application/json' \
|
||||
-b '_ga=GA1.1.1232202746.1760710013; i18nextLng=en; sso=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uX2lkIjoiOGU3MDFiNzctOTdkNC00ZjM0LWExOTctOWFmMDU1MzY3NDAwIn0.-a6x0InxbGzfTVfUlrdzxskxCnvMDI8lC90z4wHeGIk; sso-rw=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uX2lkIjoiOGU3MDFiNzctOTdkNC00ZjM0LWExOTctOWFmMDU1MzY3NDAwIn0.-a6x0InxbGzfTVfUlrdzxskxCnvMDI8lC90z4wHeGIk; stblid=b3331fc1-45d7-466b-83df-67427c0b2367; x-userid=85980643-ffab-4984-a3de-59a608c47d7f; cf_clearance=_kkd42wRt_Q2aVTB3qvDnUe8BZj7wJA5tYQ.SruABFE-1764222553-1.2.1.1-2U5UwW9vy4CXMEktGjlRBBtDSPkect5mmH5T98k7blNsLt_Mkxum6WZrSkwvTrujXz54E3k46_0elKO.37jq_sU2C.CoCmQ8FxU85JIPG05ybIx26PQkS54vvnnKDtvc7Jcat56FTRzKO8x._p4umwZZWsSSuthdvP9ogWyODnacVg7jyEnJ_KtZInJeLJOwUyL7qxLDTze0yIs9lfXuDzvCQrak4vl2P3FF9q0P1dA; mp_ea93da913ddb66b6372b89d97b1029ac_mixpanel=%7B%22distinct_id%22%3A%2285980643-ffab-4984-a3de-59a608c47d7f%22%2C%22%24device_id%22%3A%2279ce237a-a0f3-4913-bf4b-519ac8a98263%22%2C%22%24initial_referrer%22%3A%22%24direct%22%2C%22%24initial_referring_domain%22%3A%22%24direct%22%2C%22__mps%22%3A%7B%7D%2C%22__mpso%22%3A%7B%7D%2C%22__mpus%22%3A%7B%7D%2C%22__mpa%22%3A%7B%7D%2C%22__mpu%22%3A%7B%7D%2C%22__mpr%22%3A%5B%5D%2C%22__mpap%22%3A%5B%5D%2C%22%24user_id%22%3A%2285980643-ffab-4984-a3de-59a608c47d7f%22%7D; _ga_8FEWB057YH=GS2.1.s1764228571$o20$g1$t1764228595$j36$l0$h0' \
|
||||
-H 'origin: https://grok.com' \
|
||||
-H 'pragma: no-cache' \
|
||||
-H 'priority: u=1, i' \
|
||||
-H 'referer: https://grok.com/imagine/post/51bc87b7-d985-486b-87f9-2345f9329675' \
|
||||
-H 'sec-ch-ua: "Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"' \
|
||||
-H 'sec-ch-ua-mobile: ?0' \
|
||||
-H 'sec-ch-ua-platform: "macOS"' \
|
||||
-H 'sec-fetch-dest: empty' \
|
||||
-H 'sec-fetch-mode: cors' \
|
||||
-H 'sec-fetch-site: same-origin' \
|
||||
-H 'sentry-trace: a0dfe5fb521c4aff81dc8e4c29ddf512-9498b36577293fef-0' \
|
||||
-H 'traceparent: 00-88e6010c9ecea790a91d0b27c38fd0e1-fac74f63c226ad4f-00' \
|
||||
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36' \
|
||||
-H 'x-statsig-id: F6uioputjm5qWZ97AsfHQy+xxfuYSos+nBN7lvk1K0RxkSYiOP3iuyRLttV62pbJK5ONzxM3lf1JMZXxkVl8vNszvMiIFA' \
|
||||
-H 'x-xai-request-id: 1e445b21-9e73-4cb3-af6d-7918900fab62' \
|
||||
--data-raw '{"temporary":true,"modelName":"grok-3","message":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/51bc87b7-d985-486b-87f9-2345f9329675/content --mode=normal","fileAttachments":["51bc87b7-d985-486b-87f9-2345f9329675"],"toolOverrides":{"videoGen":true},"responseMetadata":{"modelConfigOverride":{"modelMap":{"videoGenModelConfig":{"parentPostId":"51bc87b7-d985-486b-87f9-2345f9329675","aspectRatio":"1:1","videoLength":6}}}}}'
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
curl 'https://grok.com/rest/app-chat/conversations/new' \
|
||||
-H 'accept: */*' \
|
||||
-H 'accept-language: en-US,en;q=0.9' \
|
||||
-H 'baggage: sentry-environment=production,sentry-public_key=b311e0f2690c81f25e2c4cf6d4f7ce1c,sentry-trace_id=a0dfe5fb521c4aff81dc8e4c29ddf512,sentry-org_id=4508179396558848,sentry-transaction=%2F%3Aslug*%3F,sentry-sampled=false,sentry-sample_rand=0.2766847188981013,sentry-sample_rate=0' \
|
||||
-H 'cache-control: no-cache' \
|
||||
-H 'content-type: application/json' \
|
||||
-b '_ga=GA1.1.1232202746.1760710013; i18nextLng=en; sso=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uX2lkIjoiOGU3MDFiNzctOTdkNC00ZjM0LWExOTctOWFmMDU1MzY3NDAwIn0.-a6x0InxbGzfTVfUlrdzxskxCnvMDI8lC90z4wHeGIk; sso-rw=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uX2lkIjoiOGU3MDFiNzctOTdkNC00ZjM0LWExOTctOWFmMDU1MzY3NDAwIn0.-a6x0InxbGzfTVfUlrdzxskxCnvMDI8lC90z4wHeGIk; stblid=b3331fc1-45d7-466b-83df-67427c0b2367; x-userid=85980643-ffab-4984-a3de-59a608c47d7f; cf_clearance=_kkd42wRt_Q2aVTB3qvDnUe8BZj7wJA5tYQ.SruABFE-1764222553-1.2.1.1-2U5UwW9vy4CXMEktGjlRBBtDSPkect5mmH5T98k7blNsLt_Mkxum6WZrSkwvTrujXz54E3k46_0elKO.37jq_sU2C.CoCmQ8FxU85JIPG05ybIx26PQkS54vvnnKDtvc7Jcat56FTRzKO8x._p4umwZZWsSSuthdvP9ogWyODnacVg7jyEnJ_KtZInJeLJOwUyL7qxLDTze0yIs9lfXuDzvCQrak4vl2P3FF9q0P1dA; mp_ea93da913ddb66b6372b89d97b1029ac_mixpanel=%7B%22distinct_id%22%3A%2285980643-ffab-4984-a3de-59a608c47d7f%22%2C%22%24device_id%22%3A%2279ce237a-a0f3-4913-bf4b-519ac8a98263%22%2C%22%24initial_referrer%22%3A%22%24direct%22%2C%22%24initial_referring_domain%22%3A%22%24direct%22%2C%22__mps%22%3A%7B%7D%2C%22__mpso%22%3A%7B%7D%2C%22__mpus%22%3A%7B%7D%2C%22__mpa%22%3A%7B%7D%2C%22__mpu%22%3A%7B%7D%2C%22__mpr%22%3A%5B%5D%2C%22__mpap%22%3A%5B%5D%2C%22%24user_id%22%3A%2285980643-ffab-4984-a3de-59a608c47d7f%22%7D; _ga_8FEWB057YH=GS2.1.s1764228571$o20$g1$t1764228668$j60$l0$h0' \
|
||||
-H 'origin: https://grok.com' \
|
||||
-H 'pragma: no-cache' \
|
||||
-H 'priority: u=1, i' \
|
||||
-H 'referer: https://grok.com/imagine/post/b0b88b45-9724-49bd-a82c-c83ddcd2937f' \
|
||||
-H 'sec-ch-ua: "Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"' \
|
||||
-H 'sec-ch-ua-mobile: ?0' \
|
||||
-H 'sec-ch-ua-platform: "macOS"' \
|
||||
-H 'sec-fetch-dest: empty' \
|
||||
-H 'sec-fetch-mode: cors' \
|
||||
-H 'sec-fetch-site: same-origin' \
|
||||
-H 'sentry-trace: a0dfe5fb521c4aff81dc8e4c29ddf512-8d3208b7533c8446-0' \
|
||||
-H 'traceparent: 00-46471c2129f7b3cac9db10d504ba132a-7851e787db05c657-00' \
|
||||
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36' \
|
||||
-H 'x-statsig-id: T/P6+sP11jYyAccjWp+fG3fpnaPAEtNmxEsjzqFtcxwpyX56YKW643wT7o0igs6Rc6TVl0smbLBKnHfKsZhcEQxzyvdlTA' \
|
||||
-H 'x-xai-request-id: 9c853e9c-ce87-403b-a2c9-d073523b34f6' \
|
||||
--data-raw '{"temporary":true,"modelName":"grok-3","message":"A waterspout wrecks an oil tanker, misty, huge waves --mode=custom","toolOverrides":{"videoGen":true},"responseMetadata":{"modelConfigOverride":{"modelMap":{"videoGenModelConfig":{"parentPostId":"b0b88b45-9724-49bd-a82c-c83ddcd2937f","aspectRatio":"2:3","videoLength":6}}}}}'
|
||||
+14
-1
@@ -1,4 +1,5 @@
|
||||
use crate::client::browser_user_agents::FIREFOX_143_MAC_USER_AGENT;
|
||||
use crate::datatypes::api::aspect_ratio::AspectRatio;
|
||||
use crate::datatypes::api::baggage::Baggage;
|
||||
use crate::datatypes::api::file_id::FileId;
|
||||
use crate::datatypes::api::sentry_trace::SentryTrace;
|
||||
@@ -14,7 +15,7 @@ use crate::requests::index_page::signature::generate_xsid::{generate_xsid, Gener
|
||||
use crate::requests::upload_file::grok_upload_file::{GrokUploadFile, GrokUploadFileResponse};
|
||||
use crate::requests::video_chat::parse_video_id::parse_video_id;
|
||||
use crate::requests::video_chat::parse_video_id_from_partial_byte_stream_buffer::parse_video_id_from_partial_byte_stream_buffer;
|
||||
use crate::requests::video_chat::request::{CreateChatConversationWireRequest, ModelConfigOverride, ModelMap, ResponseMetadata, ToolOverrides, VideoGenModelConfig};
|
||||
use crate::requests::video_chat::request::{CreateChatConversationWireRequest, ModelConfigOverride, ModelMap, ResponseMetadata, ToolOverrides, VideoGenAspectRatio, VideoGenModelConfig};
|
||||
use crate::utils::user_and_file_id_to_image_url::user_and_file_id_to_image_url;
|
||||
use futures::StreamExt;
|
||||
use log::{debug, error, info, warn};
|
||||
@@ -32,6 +33,7 @@ pub struct GrokVideoGenChatConversationBuilder<'a> {
|
||||
pub file_id: &'a FileId,
|
||||
pub media_type: VideoMediaPostType,
|
||||
pub prompt: Option<&'a str>,
|
||||
pub aspect_ratio: Option<AspectRatio>,
|
||||
|
||||
pub cookie: &'a str,
|
||||
pub user_id: &'a UserId,
|
||||
@@ -236,6 +238,13 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> {
|
||||
prompt = format!("{media_url} {user_prompt} --mode=custom");
|
||||
}
|
||||
|
||||
let aspect_ratio = match self.aspect_ratio {
|
||||
Some(AspectRatio::Square) => VideoGenAspectRatio::Square,
|
||||
Some(AspectRatio::WideThreeByTwo) => VideoGenAspectRatio::WideThreeByTwo,
|
||||
Some(AspectRatio::TallTwoByThree) => VideoGenAspectRatio::TallTwoByThree,
|
||||
None => VideoGenAspectRatio::WideThreeByTwo,
|
||||
};
|
||||
|
||||
let request_body = CreateChatConversationWireRequest {
|
||||
temporary: true,
|
||||
model_name: "grok-3".to_string(),
|
||||
@@ -251,6 +260,8 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> {
|
||||
model_map: ModelMap {
|
||||
video_gen_model_config: VideoGenModelConfig {
|
||||
parent_post_id: self.file_id.0.to_string(),
|
||||
video_length: 6, // NB: API defaults to "6"
|
||||
aspect_ratio,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -340,6 +351,7 @@ mod tests {
|
||||
file_id: &file_id,
|
||||
media_type: VideoMediaPostType::UserUploadedImage,
|
||||
prompt: maybe_prompt,
|
||||
aspect_ratio: Some(AspectRatio::TallTwoByThree),
|
||||
|
||||
cookie: cookies.as_str(),
|
||||
user_id: &secrets.user_id,
|
||||
@@ -402,6 +414,7 @@ mod tests {
|
||||
file_id: &file_id,
|
||||
media_type: VideoMediaPostType::UserUploadedImage,
|
||||
prompt: maybe_prompt,
|
||||
aspect_ratio: Some(AspectRatio::Square),
|
||||
|
||||
cookie: cookies.as_str(),
|
||||
user_id: &secrets.user_id,
|
||||
|
||||
@@ -51,10 +51,55 @@ pub (super) struct ModelMap {
|
||||
pub (super) struct VideoGenModelConfig {
|
||||
#[serde(rename = "parentPostId")]
|
||||
pub (super) parent_post_id: String,
|
||||
|
||||
/// Newer field as of November
|
||||
/// values: "1:1", "2:3" (tall),
|
||||
#[serde(rename = "aspectRatio")]
|
||||
pub (super) aspect_ratio: VideoGenAspectRatio,
|
||||
|
||||
/// Newer field as of November
|
||||
/// default seems to be "6"
|
||||
#[serde(rename = "videoLength")]
|
||||
pub (super) video_length: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Copy, Debug)]
|
||||
pub (super) enum VideoGenAspectRatio {
|
||||
#[serde(rename = "2:3")]
|
||||
TallTwoByThree,
|
||||
|
||||
#[serde(rename = "3:2")]
|
||||
WideThreeByTwo,
|
||||
|
||||
#[serde(rename = "1:1")]
|
||||
Square,
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
November 27 no image (text only) square aspect ratio -
|
||||
|
||||
--data-raw
|
||||
{
|
||||
"temporary":true,
|
||||
"modelName":"grok-3",
|
||||
"message":"A waterspout wrecks an oil tanker, misty, huge waves --mode=custom",
|
||||
"toolOverrides": {
|
||||
"videoGen":true
|
||||
},
|
||||
"responseMetadata": {
|
||||
"modelConfigOverride": {
|
||||
"modelMap": {
|
||||
"videoGenModelConfig": {
|
||||
"parentPostId":"b0b88b45-9724-49bd-a82c-c83ddcd2937f",
|
||||
"aspectRatio":"2:3",
|
||||
"videoLength":6
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
October 29 request struct -
|
||||
|
||||
--data-raw
|
||||
@@ -113,4 +158,6 @@ October 22 request struct -
|
||||
"videoGen":true
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,18 @@ export const VIDEO_MODELS: VideoModel[] = [
|
||||
endFrame: false,
|
||||
requiresImage: true,
|
||||
progressBarTime: 50000,
|
||||
sizeOptions: [
|
||||
{
|
||||
tauriValue: "landscape",
|
||||
textLabel: "Landscape",
|
||||
icon: SizeIconOption.Landscape,
|
||||
},
|
||||
{
|
||||
tauriValue: "portrait",
|
||||
textLabel: "Portrait",
|
||||
icon: SizeIconOption.Portrait,
|
||||
},
|
||||
],
|
||||
}),
|
||||
new VideoModel({
|
||||
id: "kling_1_6_pro",
|
||||
|
||||
Reference in new issue
Block a user