fix: ensure Magic AI returns structured output

This commit is contained in:
2026-08-10 12:57:42 +03:00
parent 74f68815a7
commit 5046d00817
+3 -2
View File
@@ -5,7 +5,7 @@ export type CreativeAnalysis = { summary: string; insights: Array<{ title: strin
export async function analyzeCreatives(query: string | undefined, ads: AdSignal[]): Promise<CreativeAnalysis & { model: string }> { export async function analyzeCreatives(query: string | undefined, ads: AdSignal[]): Promise<CreativeAnalysis & { model: string }> {
const apiKey = process.env.OPENAI_API_KEY?.trim(); const apiKey = process.env.OPENAI_API_KEY?.trim();
if (!apiKey) throw new Error("OPENAI_NOT_CONFIGURED"); if (!apiKey) throw new Error("OPENAI_NOT_CONFIGURED");
const model = process.env.OPENAI_MODEL?.trim() || "gpt-5.6-luna"; const model = process.env.OPENAI_MODEL?.trim() || "gpt-5";
const controller = new AbortController(); const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 45_000); const timer = setTimeout(() => controller.abort(), 45_000);
try { try {
@@ -48,7 +48,8 @@ export async function analyzeCreatives(query: string | undefined, ads: AdSignal[
} }
} }
}, },
max_output_tokens: 1200 reasoning: { effort: "minimal" },
max_output_tokens: 2400
}), }),
signal: controller.signal, signal: controller.signal,
cache: "no-store" cache: "no-store"