import { invokeLLM } from "./_core/llm"; export type ContentType = "sales_copy" | "product_description" | "ad_text" | "email_template"; interface ContentGenerationRequest { contentType: ContentType; productName: string; productDescription?: string; targetAudience?: string; tone?: string; keyFeatures?: string; } interface ContentGenerationResponse { content: string; prompt: string; } /** * Generate marketing content using LangChain with Hugging Face LLM */ export async function generateMarketingContent( request: ContentGenerationRequest ): Promise { const { contentType, productName, productDescription, targetAudience, tone, keyFeatures } = request; let systemPrompt = ""; let userPrompt = ""; switch (contentType) { case "sales_copy": systemPrompt = `You are an expert copywriter specializing in creating compelling sales copy that converts readers into customers. Your copy should be persuasive, benefit-focused, and action-oriented.`; userPrompt = `Create compelling sales copy for the following product: Product Name: ${productName} ${productDescription ? `Product Description: ${productDescription}` : ""} ${targetAudience ? `Target Audience: ${targetAudience}` : ""} ${tone ? `Tone: ${tone}` : ""} ${keyFeatures ? `Key Features: ${keyFeatures}` : ""} Generate engaging sales copy that highlights the benefits and creates urgency to purchase.`; break; case "product_description": systemPrompt = `You are an expert product description writer. Create clear, compelling product descriptions that highlight benefits, features, and value propositions.`; userPrompt = `Write a detailed product description for: Product Name: ${productName} ${productDescription ? `Current Description: ${productDescription}` : ""} ${targetAudience ? `Target Audience: ${targetAudience}` : ""} ${keyFeatures ? `Key Features: ${keyFeatures}` : ""} Create a professional product description that sells the benefits and appeals to the target audience.`; break; case "ad_text": systemPrompt = `You are an expert digital advertising copywriter. Create concise, attention-grabbing ad copy optimized for social media and search engines.`; userPrompt = `Create ad copy for: Product Name: ${productName} ${productDescription ? `Product Description: ${productDescription}` : ""} ${targetAudience ? `Target Audience: ${targetAudience}` : ""} ${tone ? `Tone: ${tone}` : ""} ${keyFeatures ? `Key Features: ${keyFeatures}` : ""} Generate multiple variations of ad copy (headline + body) that are concise, compelling, and optimized for conversions.`; break; case "email_template": systemPrompt = `You are an expert email marketing specialist. Create engaging email templates that drive conversions and build relationships.`; userPrompt = `Create a sales email template for: Product Name: ${productName} ${productDescription ? `Product Description: ${productDescription}` : ""} ${targetAudience ? `Target Audience: ${targetAudience}` : ""} ${tone ? `Tone: ${tone}` : "Professional"} ${keyFeatures ? `Key Features: ${keyFeatures}` : ""} Generate a complete email template with subject line, greeting, body, and call-to-action that matches the specified tone.`; break; } try { const response = await invokeLLM({ messages: [ { role: "system", content: systemPrompt }, { role: "user", content: userPrompt }, ], }); const messageContent = response.choices?.[0]?.message?.content; const generatedText = typeof messageContent === "string" ? messageContent : "Failed to generate content"; return { content: generatedText as string, prompt: userPrompt, }; } catch (error) { console.error("Error generating content:", error); throw new Error("Failed to generate marketing content"); } }