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