Spaces:
Build error
Build error
Update src/app/api/prompt-engineer/route.ts
Browse files
src/app/api/prompt-engineer/route.ts
CHANGED
|
@@ -7,46 +7,75 @@ export async function POST(request: NextRequest) {
|
|
| 7 |
const { prompt, type, platform } = body;
|
| 8 |
|
| 9 |
if (!prompt) {
|
| 10 |
-
return NextResponse.json(
|
|
|
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
const zai = await ZAI.create();
|
| 14 |
|
|
|
|
| 15 |
const platformGuides: Record<string, string> = {
|
| 16 |
instagram: "Formato cuadrado o vertical, colores vibrantes, lifestyle",
|
| 17 |
tiktok: "Video corto, dinamico, trending sounds",
|
| 18 |
youtube: "Thumbnail llamativo, titulo optimizado, larga duracion",
|
| 19 |
onlyfans: "Contenido exclusivo, conexion personal",
|
| 20 |
-
general: "Contenido universal, apto para todas las plataformas"
|
| 21 |
};
|
| 22 |
|
|
|
|
| 23 |
const typeGuides: Record<string, string> = {
|
| 24 |
image: "Prompt para generacion de imagen detallado",
|
| 25 |
video: "Prompt para video con movimiento y escenas",
|
| 26 |
reel: "Prompt para reel corto y dinamico",
|
| 27 |
-
carousel: "Prompt para serie de imagenes coherentes"
|
| 28 |
};
|
| 29 |
|
| 30 |
-
const guide =
|
| 31 |
-
|
|
|
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
const completion = await zai.chat.completions.create({
|
| 34 |
messages: [
|
| 35 |
-
{
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
});
|
| 39 |
|
| 40 |
-
const optimizedPrompt =
|
|
|
|
| 41 |
|
| 42 |
return NextResponse.json({
|
| 43 |
success: true,
|
| 44 |
originalPrompt: prompt,
|
| 45 |
optimizedPrompt,
|
| 46 |
type: type || "image",
|
| 47 |
-
platform: platform || "general"
|
| 48 |
});
|
| 49 |
-
} catch {
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
-
}
|
|
|
|
| 7 |
const { prompt, type, platform } = body;
|
| 8 |
|
| 9 |
if (!prompt) {
|
| 10 |
+
return NextResponse.json(
|
| 11 |
+
{ success: false, error: "Prompt requerido" },
|
| 12 |
+
{ status: 400 }
|
| 13 |
+
);
|
| 14 |
}
|
| 15 |
|
| 16 |
const zai = await ZAI.create();
|
| 17 |
|
| 18 |
+
// Guías por plataforma
|
| 19 |
const platformGuides: Record<string, string> = {
|
| 20 |
instagram: "Formato cuadrado o vertical, colores vibrantes, lifestyle",
|
| 21 |
tiktok: "Video corto, dinamico, trending sounds",
|
| 22 |
youtube: "Thumbnail llamativo, titulo optimizado, larga duracion",
|
| 23 |
onlyfans: "Contenido exclusivo, conexion personal",
|
| 24 |
+
general: "Contenido universal, apto para todas las plataformas",
|
| 25 |
};
|
| 26 |
|
| 27 |
+
// Guías por tipo
|
| 28 |
const typeGuides: Record<string, string> = {
|
| 29 |
image: "Prompt para generacion de imagen detallado",
|
| 30 |
video: "Prompt para video con movimiento y escenas",
|
| 31 |
reel: "Prompt para reel corto y dinamico",
|
| 32 |
+
carousel: "Prompt para serie de imagenes coherentes",
|
| 33 |
};
|
| 34 |
|
| 35 |
+
const guide =
|
| 36 |
+
platformGuides[platform || "general"] ||
|
| 37 |
+
platformGuides.general;
|
| 38 |
|
| 39 |
+
const typeGuide =
|
| 40 |
+
typeGuides[type || "image"] ||
|
| 41 |
+
typeGuides.image;
|
| 42 |
+
|
| 43 |
+
// ✅ PROMPT BIEN FORMADO
|
| 44 |
const completion = await zai.chat.completions.create({
|
| 45 |
messages: [
|
| 46 |
+
{
|
| 47 |
+
role: "system",
|
| 48 |
+
content:
|
| 49 |
+
"Eres un ingeniero de prompts experto. Optimiza el prompt del usuario para generar mejor contenido. Responde SOLO con el prompt optimizado, sin explicaciones.",
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
role: "user",
|
| 53 |
+
content: `Optimiza este prompt para ${platform || "general"}:
|
| 54 |
+
|
| 55 |
+
Guia: ${guide}
|
| 56 |
+
Tipo: ${typeGuide}
|
| 57 |
+
|
| 58 |
+
Prompt original:
|
| 59 |
+
${prompt}`,
|
| 60 |
+
},
|
| 61 |
+
],
|
| 62 |
});
|
| 63 |
|
| 64 |
+
const optimizedPrompt =
|
| 65 |
+
completion.choices?.[0]?.message?.content || prompt;
|
| 66 |
|
| 67 |
return NextResponse.json({
|
| 68 |
success: true,
|
| 69 |
originalPrompt: prompt,
|
| 70 |
optimizedPrompt,
|
| 71 |
type: type || "image",
|
| 72 |
+
platform: platform || "general",
|
| 73 |
});
|
| 74 |
+
} catch (error) {
|
| 75 |
+
console.error("Prompt engineer error:", error);
|
| 76 |
+
return NextResponse.json(
|
| 77 |
+
{ success: false, error: "Error" },
|
| 78 |
+
{ status: 500 }
|
| 79 |
+
);
|
| 80 |
}
|
| 81 |
+
}
|