Update post_generator.py
Browse files- post_generator.py +7 -3
post_generator.py
CHANGED
@@ -45,13 +45,14 @@ def generate_post(length, language, tag, selected_tone=None):
|
|
45 |
"""
|
46 |
prompt = get_prompt(length, language, tag)
|
47 |
response = llm.invoke(prompt)
|
48 |
-
post_content = response.content
|
49 |
|
50 |
# Generate a dynamic closing line using LLM
|
51 |
if selected_tone and tag:
|
52 |
try:
|
53 |
closing_line = generate_closing_line(language, tag, selected_tone)
|
54 |
-
|
|
|
55 |
except Exception as e:
|
56 |
# Fallback in case of LLM failure
|
57 |
post_content += f"\n\nThank you for reading. Your feedback is valued! π"
|
@@ -68,6 +69,7 @@ def get_prompt(length, language, tag):
|
|
68 |
2. Post Length: "{length_str}"
|
69 |
3. Language: "{language}" (Hinglish means Hindi phrases written in English script).
|
70 |
4. Incorporate creativity, enthusiasm, emotional appeal, and actionable advice.
|
|
|
71 |
'''
|
72 |
|
73 |
examples = few_shot.get_filtered_posts(length, language, tag)
|
@@ -75,7 +77,9 @@ def get_prompt(length, language, tag):
|
|
75 |
prompt += "\nExamples of great posts:\n"
|
76 |
for i, post in enumerate(examples[:2]): # Limit to 2 examples
|
77 |
post_text = post['text']
|
78 |
-
|
|
|
|
|
79 |
|
80 |
prompt += "\nNow write the post."
|
81 |
return prompt
|
|
|
45 |
"""
|
46 |
prompt = get_prompt(length, language, tag)
|
47 |
response = llm.invoke(prompt)
|
48 |
+
post_content = response.content.strip()
|
49 |
|
50 |
# Generate a dynamic closing line using LLM
|
51 |
if selected_tone and tag:
|
52 |
try:
|
53 |
closing_line = generate_closing_line(language, tag, selected_tone)
|
54 |
+
# Append the closing line with hashtags
|
55 |
+
post_content += f"\n\n{closing_line}"
|
56 |
except Exception as e:
|
57 |
# Fallback in case of LLM failure
|
58 |
post_content += f"\n\nThank you for reading. Your feedback is valued! π"
|
|
|
69 |
2. Post Length: "{length_str}"
|
70 |
3. Language: "{language}" (Hinglish means Hindi phrases written in English script).
|
71 |
4. Incorporate creativity, enthusiasm, emotional appeal, and actionable advice.
|
72 |
+
5. Do not include hashtags in the main content.
|
73 |
'''
|
74 |
|
75 |
examples = few_shot.get_filtered_posts(length, language, tag)
|
|
|
77 |
prompt += "\nExamples of great posts:\n"
|
78 |
for i, post in enumerate(examples[:2]): # Limit to 2 examples
|
79 |
post_text = post['text']
|
80 |
+
# Remove hashtags from examples
|
81 |
+
cleaned_post_text = " ".join(word for word in post_text.split() if not word.startswith("#"))
|
82 |
+
prompt += f"Example {i + 1}: {cleaned_post_text}\n"
|
83 |
|
84 |
prompt += "\nNow write the post."
|
85 |
return prompt
|