Skip to content

Commit 9726986

Browse files
author
Miriad
committed
feat: enableHorizontalInfographics config flag — vertical-only by default
Adds Sanity pipelineConfig toggle to control horizontal (16:9) generation. Default: false (vertical only). Halves Imagen API calls and generation time. - Schema: enableHorizontalInfographics boolean on pipelineConfig singleton - Type: enableHorizontalInfographics?: boolean on PipelineConfig - gemini-infographics.ts: skipHorizontal option on generateFromScenePrompts - check-research: reads config, passes to generator, adjusts total count
1 parent 18e15dc commit 9726986

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

app/api/cron/check-research/route.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,12 @@ async function stepResearchComplete(
256256
if (sceneImagePrompts.length > MAX_INFOGRAPHIC_PROMPTS) {
257257
sceneImagePrompts.length = MAX_INFOGRAPHIC_PROMPTS;
258258
}
259+
260+
const enableHorizontal = await getConfigValue('pipeline_config', 'enableHorizontalInfographics', false);
261+
const multiplier = enableHorizontal ? 2 : 1; // 2 orientations or vertical only
259262
const total = sceneImagePrompts.length > 0
260-
? sceneImagePrompts.length * 2 // both orientations
261-
: 10; // fallback: 5 topic-level x 2
263+
? sceneImagePrompts.length * multiplier
264+
: 5 * multiplier; // fallback: 5 topic-level
262265

263266
await sanity.patch(doc._id).set({
264267
status: 'infographics_generating',
@@ -365,8 +368,11 @@ async function stepInfographicsGenerating(
365368

366369
console.log(`[check-research] Generating batch: prompts ${completedPrompts + 1}-${completedPrompts + batchPrompts.length} of ${sceneImagePrompts.length} for "${doc.title}"`);
367370

371+
// Check if horizontal infographics are enabled
372+
const enableHorizontal = await getConfigValue('pipeline_config', 'enableHorizontalInfographics', false);
373+
368374
// Generate this batch using the existing function (but only for the batch)
369-
const batchResult = await generateFromScenePrompts(batchPrompts, doc.title);
375+
const batchResult = await generateFromScenePrompts(batchPrompts, doc.title, { skipHorizontal: !enableHorizontal });
370376

371377
// Accumulate refs from previous cycles
372378
const horizontalRefs = [...(progress.horizontalRefs || [])];

lib/services/gemini-infographics.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,14 @@ export async function generateInfographicsForTopic(
381381
export async function generateFromScenePrompts(
382382
prompts: string[],
383383
topic: string,
384+
options?: { skipHorizontal?: boolean },
384385
): Promise<DualOrientationResult> {
385386
const model = await getConfigValue(
386387
"pipeline_config", "infographicModel", "imagen-4.0-fast-generate-001"
387388
);
388389

390+
const skipHorizontal = options?.skipHorizontal ?? false;
391+
389392
const horizontal: InfographicResult[] = [];
390393
const vertical: InfographicResult[] = [];
391394
const errors: Array<{ prompt: string; error: string }> = [];
@@ -395,16 +398,18 @@ export async function generateFromScenePrompts(
395398
for (let i = 0; i < prompts.length; i++) {
396399
const prompt = prompts[i];
397400

398-
// Generate horizontal (16:9)
399-
try {
400-
const hResult = await generateInfographic(
401-
{ prompt, aspectRatio: "16:9" },
402-
model,
403-
);
404-
horizontal.push(hResult);
405-
} catch (err) {
406-
const message = err instanceof Error ? err.message : String(err);
407-
errors.push({ prompt: `[16:9] ${prompt}`, error: message });
401+
// Generate horizontal (16:9) — skip if vertical-only mode
402+
if (!skipHorizontal) {
403+
try {
404+
const hResult = await generateInfographic(
405+
{ prompt, aspectRatio: "16:9" },
406+
model,
407+
);
408+
horizontal.push(hResult);
409+
} catch (err) {
410+
const message = err instanceof Error ? err.message : String(err);
411+
errors.push({ prompt: `[16:9] ${prompt}`, error: message });
412+
}
408413
}
409414

410415
// Generate vertical (9:16)

lib/types/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface PipelineConfig {
1515
deepResearchAgent: string;
1616
deepResearchPromptTemplate: string;
1717
infographicModel: string;
18+
enableHorizontalInfographics?: boolean;
1819
qualityThreshold: number;
1920
stuckTimeoutMinutes: number;
2021
maxIdeasPerRun: number;

sanity/schemas/singletons/pipelineConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ export default defineType({
6565
description: "Template for Deep Research queries. Use {topic} as placeholder for the trend topic. Sent to the Deep Research agent for autonomous web research",
6666
initialValue: "Research comprehensively: \"{topic}\"\n\nFocus areas:\n- What is it and why does it matter?\n- How does it work technically?\n- Key features and capabilities\n- Comparison with alternatives\n- Getting started guide\n- Common pitfalls and best practices\n\nTarget audience: Web developers learning new tech.\nTone: Educational, accessible, engaging.",
6767
}),
68+
defineField({
69+
name: "enableHorizontalInfographics",
70+
title: "Enable Horizontal Infographics",
71+
type: "boolean",
72+
description: "Generate 16:9 horizontal infographics in addition to 9:16 vertical. Doubles Imagen API calls and generation time. Disable for vertical-only (Shorts/Reels)",
73+
initialValue: false,
74+
}),
6875
defineField({
6976
name: "infographicModel",
7077
title: "Infographic Model",

0 commit comments

Comments
 (0)