|
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 |
|
|
|
|
|
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"] |
|
|
|
|
|
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''' |
|
Generate a LinkedIn post using the below information. No preamble. |
|
|
|
1) Topic: {tag} |
|
2) Length: {length_str} |
|
3) Language: {language} |
|
If Language is Hinglish then it means it is a mix of Hindi and English. |
|
The script for the generated post should always be English. |
|
''' |
|
|
|
|
|
examples = few_shot.get_filtered_posts(length, language, tag) |
|
|
|
if len(examples) > 0: |
|
prompt += "4) Use the writing style as per the following examples." |
|
|
|
for i, post in enumerate(examples): |
|
post_text = post['text'] |
|
prompt += f'\n\n Example {i+1}: \n\n {post_text}' |
|
|
|
if i == 1: |
|
break |
|
|
|
return prompt |
|
|
|
|
|
if __name__ == "__main__": |
|
print(generate_post("Medium", "English", "Mental Health")) |