File size: 3,888 Bytes
453b50d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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<ContentGenerationResponse> {
  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");
  }
}