add enguagement tweet & fix filtered words
This commit is contained in:
+27
-25
@@ -122,33 +122,35 @@ def save_post_counts(counts):
|
||||
logging.info("Saved post counts to x_post_counts.json")
|
||||
|
||||
def generate_article_tweet(author, post, persona):
|
||||
persona_config = PERSONA_CONFIGS[persona]
|
||||
base_prompt = persona_config["x_prompt"].format(
|
||||
description=persona_config["description"],
|
||||
tone=persona_config["tone"]
|
||||
title = post["title"]
|
||||
url = post["url"]
|
||||
author_handle = f"@{author['username']}"
|
||||
|
||||
# Base tweet content
|
||||
prompt = (
|
||||
f"Generate a concise tweet (under 280 characters) for {author_handle} using the persona '{persona}'. "
|
||||
f"Summarize the article '{title}' and include the link '{url}'. "
|
||||
f"Highlight the article's appeal, make it engaging, and encourage interaction. "
|
||||
f"Always mention 'InsiderFoodie.com' in the tweet. "
|
||||
f"Avoid using the word 'elevate'—use more humanized language like 'level up' or 'bring to life'. "
|
||||
f"Do not include hashtags or emojis."
|
||||
)
|
||||
prompt = base_prompt.replace(
|
||||
"For article tweets, include the article title, a quirky hook, and the URL.",
|
||||
f"Generate an article tweet including the title '{post['title']}', a quirky hook, and the URL '{post['url']}'."
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
model=SUMMARY_MODEL,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a social media expert crafting engaging tweets."},
|
||||
{"role": "user", "content": prompt}
|
||||
],
|
||||
max_tokens=100,
|
||||
temperature=0.7
|
||||
)
|
||||
try:
|
||||
response = client.chat.completions.create(
|
||||
model=LIGHT_TASK_MODEL,
|
||||
messages=[
|
||||
{"role": "system", "content": prompt},
|
||||
{"role": "user", "content": f"Generate tweet for {post['title']}."}
|
||||
],
|
||||
max_tokens=100,
|
||||
temperature=0.9
|
||||
)
|
||||
tweet = response.choices[0].message.content.strip()
|
||||
if len(tweet) > 280:
|
||||
tweet = tweet[:277] + "..."
|
||||
logging.info(f"Generated article tweet for {author['username']}: {tweet}")
|
||||
return tweet
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to generate article tweet for {author['username']}: {e}")
|
||||
return f"This trend is fire! Check out {post['title']} at {post['url']} #Foodie"
|
||||
|
||||
tweet = response.choices[0].message.content.strip()
|
||||
if len(tweet) > 280:
|
||||
tweet = tweet[:277] + "..."
|
||||
|
||||
return tweet
|
||||
|
||||
def post_tweet(author, tweet):
|
||||
credentials = next((cred for cred in X_API_CREDENTIALS if cred["username"] == author["username"]), None)
|
||||
|
||||
Reference in New Issue
Block a user