Updated open API Syntax
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
import random
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
import openai
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from openai import OpenAI # Add this import
|
||||
from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL
|
||||
from dotenv import load_dotenv # Add this import
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
# Initialize OpenAI client
|
||||
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
||||
|
||||
def generate_engagement_tweet(author):
|
||||
author_handle = author["handle"]
|
||||
author_handle = author["x_username"] # Updated to use x_username from X_API_CREDENTIALS
|
||||
prompt = (
|
||||
f"Generate a concise tweet (under 280 characters) for {author_handle}. "
|
||||
f"Create an engaging food-related question or statement to spark interaction. "
|
||||
@@ -18,7 +25,7 @@ def generate_engagement_tweet(author):
|
||||
)
|
||||
|
||||
try:
|
||||
response = openai.ChatCompletion.create(
|
||||
response = client.chat.completions.create(
|
||||
model=SUMMARY_MODEL,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a social media expert crafting engaging tweets."},
|
||||
@@ -35,13 +42,13 @@ def generate_engagement_tweet(author):
|
||||
logging.warning(f"Failed to generate engagement tweet for {author['username']}: {e}")
|
||||
# Fallback templates
|
||||
engagement_templates = [
|
||||
"Whats the most mouthwatering dish youve seen this week Share below and follow {handle} for more foodie ideas on InsiderFoodie.com Link: https://insiderfoodie.com",
|
||||
"Food lovers unite Whats your go to comfort food Tell us and like this tweet for more tasty ideas from {handle} on InsiderFoodie.com Link: https://insiderfoodie.com",
|
||||
"Ever tried a dish that looked too good to eat Share your favorites and follow {handle} for more culinary trends on InsiderFoodie.com Link: https://insiderfoodie.com",
|
||||
"What food trend are you loving right now Let us know and like this tweet to keep up with {handle} on InsiderFoodie.com Link: https://insiderfoodie.com"
|
||||
f"Whats the most mouthwatering dish youve seen this week Share below and follow {author_handle} for more foodie ideas on InsiderFoodie.com Link: https://insiderfoodie.com",
|
||||
f"Food lovers unite Whats your go to comfort food Tell us and like this tweet for more tasty ideas from {author_handle} on InsiderFoodie.com Link: https://insiderfoodie.com",
|
||||
f"Ever tried a dish that looked too good to eat Share your favorites and follow {author_handle} for more culinary trends on InsiderFoodie.com Link: https://insiderfoodie.com",
|
||||
f"What food trend are you loving right now Let us know and like this tweet to keep up with {author_handle} on InsiderFoodie.com Link: https://insiderfoodie.com"
|
||||
]
|
||||
template = random.choice(engagement_templates)
|
||||
return template.format(handle=author_handle)
|
||||
return template
|
||||
|
||||
def post_engagement_tweet():
|
||||
# Reference date for calculating the 2-day interval
|
||||
|
||||
Reference in New Issue
Block a user