from llm_helper import llm from few_shot import FewShotPosts few_shot = FewShotPosts() def get_length_str(length): if length == "Short": return "1 to 5 lines" if length == "Medium": return "6 to 10 lines" if length == "Long": return "11 to 15 lines" def generate_post(length, language, tag, selected_tone=None): prompt = get_prompt(length, language, tag) response = llm.invoke(prompt) post_content = response.content # Add closing statements dynamically based on tone and language closing_lines = { "Motivational": { "English": [ "Stay inspired and keep moving forward! πŸ’ͺ", "Your journey to greatness begins today. 🌟", "Remember, small steps lead to big achievements. πŸš€", "Keep pushing your boundaries. You’ve got this! πŸ”₯" ], "Hinglish": [ "Dhire dhire aage badho aur safalta pao! πŸ’ͺ", "Sapne bade rakho, unhe pura karo. 🌟", "Chhoti chhoti koshis se bade lakshya hasil hote hain! πŸš€", "Apne boundaries todho, aap kar sakte ho! πŸ”₯" ] }, "Professional": { "English": [ "Looking forward to hearing your thoughts! πŸ‘”", "Let’s collaborate and make an impact together. 🌐", "Feel free to share your perspective below. πŸ“’", "Insights and feedback are always welcome. πŸ’‘" ], "Hinglish": [ "Aapke vichar sunne ka intezaar hai! πŸ‘”", "Chaliye milkar kuch asar karte hain. 🌐", "Neeche apne vichar zaroor share karein. πŸ“’", "Aapka feedback hamare liye mahatvapurn hai. πŸ’‘" ] }, "Informal": { "English": [ "What do you think? Let's chat in the comments! πŸ˜„", "Drop your thoughts below, would love to hear from you! πŸ—¨οΈ", "Let’s keep the conversation rolling. Share your views! πŸš€", "Got something to add? Don’t hold back! 😎" ], "Hinglish": [ "Kya sochte ho? Comments mein baat karte hain! πŸ˜„", "Apne vichar neeche likho, sunne ke liye excited hoon! πŸ—¨οΈ", "Charcha ko jaari rakhein, apne vichar share karein! πŸš€", "Kuch add karna hai? Sharmana mat, batao! 😎" ] }, "Neutral": { "English": [ "Thank you for reading. Your feedback is valued! πŸ™Œ", "Let’s connect and share ideas. 🌟", "Looking forward to engaging with you in the comments. πŸ’¬", "Your thoughts are always appreciated. 😊" ], "Hinglish": [ "Padhne ke liye dhanyavaad. Aapka feedback mahatvapurn hai! πŸ™Œ", "Chaliye judein aur naye ideas share karein. 🌟", "Aapke vichar comments mein padhne ka intezaar hai. πŸ’¬", "Aapke sujhav hamesha sarankrit hote hain. 😊" ] } } if selected_tone and selected_tone in closing_lines: if language == "Hinglish" and "Hinglish" in closing_lines[selected_tone]: closing_line = closing_lines[selected_tone]["Hinglish"] else: closing_line = closing_lines[selected_tone]["English"] # Randomly select a closing line import random post_content += f"\n\n{random.choice(closing_line)}" return post_content def get_prompt(length, language, tag): length_str = get_length_str(length) prompt = f''' Write a professional, engaging LinkedIn post. 1. Topic: "{tag}" 2. Post Length: "{length_str}" 3. Language: "{language}" (Hinglish means Hindi phrases written in English script). 4. Incorporate creativity, enthusiasm, emotional appeal, and actionable advice. ''' examples = few_shot.get_filtered_posts(length, language, tag) if examples: prompt += "\nExamples of great posts:\n" for i, post in enumerate(examples[:2]): # Limit to 2 examples post_text = post['text'] prompt += f"Example {i + 1}: {post_text}\n" prompt += "\nNow write the post." return prompt if __name__ == "__main__": print(generate_post("Medium", "English", "Mental Health"))