File size: 5,886 Bytes
dfc4131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI

from load_model import call_palm
from calling_apis import google_api_key, openai_api_key

class linkedIn_content_gen:
    
    """
        A class for generating linkedIn Content.

    """
        

    def linkedIn_post_gen(self, topic: str, tone_of_voice:str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
        
        """
        Generate an engaging LinkedIn post based on the provided topic and tone of voice.

        Parmaeters:
            - self: The instance of the class containing this method.
            - topic (str): The topic for the LinkedIn post.
            - tone_of_voice (str): The desired tone of voice for the post.
            - language (str): the language of the generated content (optional, default value is 'EN').
            - creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
            - model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
            

        Returns:
        - linkedIn_post (str): The generated LinkedIn post.

        """
        temp = 0

        if creativity == 'Original':
            temp = 0
        elif creativity == 'Balanced':
            temp = 0.25
        elif creativity == 'Creative':
            temp = 0.5
        elif creativity == 'Spirited':
            temp = 0.75
        elif creativity == 'Visionary':
            temp = 1


        if model_name == 'Google Palm 2':
            llm = call_palm(google_api_key, temperature=temp)

        elif model_name == 'GPT-3.5':
            llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)

        elif model_name == 'GPT-4':
            llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)


        if language == 'En':
            
            linkedIn_post_prompt = f"Write an engagging LinkedIn Post on {topic}. The tone should be {tone_of_voice}."
            linkedIn_post_promptTemp = PromptTemplate(
            input_variables=["text_input"],
            template="You are a content creator and LinkedIn Posts writer :\n{text_input}\nLinkedIn Post:")
        
        elif language == 'Ar':
            
            linkedIn_post_prompt = f"اكتب منشورًا جذابًا على LinkedIn حول {topic}. يجب أن يكون النبرة {tone_of_voice}."
            linkedIn_post_promptTemp = PromptTemplate(
            input_variables=["text_input"],
            template="أنت مُنشئ محتوى وكاتب لمنشورات LinkedIn :\n{text_input}\nمنشور LinkedIn:")

            
        linkedIn_post_extraction_chain = LLMChain(llm=llm, prompt=linkedIn_post_promptTemp)
        linkedIn_post = linkedIn_post_extraction_chain.run(linkedIn_post_prompt)

        return linkedIn_post
     
        
    def linkedIn_ads_gen(self, product_name:str, product_desc:str, target_audience:str, target_keywords:str, language='En', model_name='Google Palm 2', creativity='Original'):
    
        """
        Generates a LinkedIn ad based on the provided product information and target details.

        Args:
        - product_name (str): The name of the product being advertised.
        - product_desc (str): A description of the product being advertised.
        - target_audience (str): The intended audience or demographic for the product.
        - target_keywords (str): Keywords relevant to the product or its marketing strategy.
        - language (str): the language of the generated content (optional, default value is 'EN').

        Returns:
        - linkedIn_ad (str): The generated LinkedIn ad copy based on the provided parameters.

        """
        
        temp = 0

        if creativity == 'Original':
            temp = 0
        elif creativity == 'Balanced':
            temp = 0.25
        elif creativity == 'Creative':
            temp = 0.5
        elif creativity == 'Spirited':
            temp = 0.75
        elif creativity == 'Visionary':
            temp = 1


        if model_name == 'Google Palm 2':
            llm = call_palm(google_api_key, temperature=temp)

        elif model_name == 'GPT-3.5':
            llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)

        elif model_name == 'GPT-4':
            llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)


        if language == 'En':
            
            linkedIn_ads_prompt = f"Generate a LinkedIn ad for {product_name}. {product_name} is {product_desc} that is targeted at {target_audience} and uses the keywords {target_keywords}. The ad should be persuasive and engaging, and it should include a call to action."
            linkedIn_ads_promptTemp = PromptTemplate(
            input_variables=["text_input"],
            template="You are a Professional LinkedIn Ad Copywriter:\n{text_input}\nFacebook Ad:")
        
        elif language == 'Ar':
            
            linkedIn_ads_prompt = f"أنشئ إعلانًا على LinkedIn لـ {product_name}. {product_name} هو {product_desc} المستهدف نحو {target_audience} ويستخدم الكلمات الرئيسية {target_keywords}. يجب أن يكون الإعلان مقنعًا وجذابًا، ويجب أن يتضمن دعوة للعمل."
            linkedIn_ads_promptTemp = PromptTemplate(
            input_variables=["text_input"],
            template="أنت كاتب إعلانات محترف على LinkedIn:\n{text_input}\nإعلان على فيسبوك:")
        
        linkedIn_ad_extraction_chain = LLMChain(llm=llm, prompt=linkedIn_ads_promptTemp)
        linkedIn_ad = linkedIn_ad_extraction_chain.run(linkedIn_ads_prompt)

        return linkedIn_ad