31 lines
1,006 B
TypeScript
31 lines
1,006 B
TypeScript
|
|
import { NextRequest, NextResponse } from 'next/server';
|
||
|
|
import { generateAdCopy } from '@/lib/ai/copywriter';
|
||
|
|
|
||
|
|
export async function POST(request: NextRequest) {
|
||
|
|
try {
|
||
|
|
const body = await request.json();
|
||
|
|
const { context, copy_rules, objective, tone, count, category } = body;
|
||
|
|
|
||
|
|
if (!context || !objective) {
|
||
|
|
return NextResponse.json(
|
||
|
|
{ success: false, error: 'context and objective are required' },
|
||
|
|
{ status: 400 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
const variations = await generateAdCopy({ context, copy_rules, objective, tone, count, category });
|
||
|
|
|
||
|
|
return NextResponse.json({ success: true, data: variations });
|
||
|
|
} catch (error) {
|
||
|
|
console.error('[AI] Error generating copy:', error);
|
||
|
|
return NextResponse.json(
|
||
|
|
{
|
||
|
|
success: false,
|
||
|
|
error: error instanceof Error ? error.message : 'AI error',
|
||
|
|
details: 'Verifique se a OPENAI_API_KEY no .env.local é uma chave válida da OpenAI (começa com sk-...)'
|
||
|
|
},
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|