from foodie_config import OPENAI_API_KEY, LIGHT_TASK_MODEL from openai import OpenAI import logging import random from urllib.parse import quote import urllib.parse client = OpenAI(api_key=OPENAI_API_KEY) def get_dynamic_hook(article_title): try: response = client.chat.completions.create( model=LIGHT_TASK_MODEL, messages=[ {"role": "system", "content": ( "Generate a short, catchy hook (under 100 characters) for a tweet based on this article title about food topics. " "Make it bold and quirky with Upworthy/Buzzfeed flair (e.g., 'This food twist is wild!'), avoiding clichés like 'game-changer'. " "Do not include emojis in the hook. " "Return only the hook text." )}, {"role": "user", "content": article_title} ], max_tokens=30 ) hook = response.choices[0].message.content.strip().replace('**', '') logging.info(f"Generated dynamic hook: {hook}") return hook except Exception as e: logging.error(f"Dynamic hook generation failed: {e}") return "This food scoop will blow your mind!" def get_viral_share_prompt(article_title, content): try: prompt = ( "Generate a short, viral share prompt (under 40 characters) to encourage sharing a food-related article on social media. " "Make it bold, quirky, and engaging with a Buzzfeed/Upworthy flair (e.g., 'Obsessed? Share Now'). " "Avoid clichés like 'game-changer' and words like 'elevate'. " "Do not include emojis, the platform name (e.g., Twitter, Facebook), or any HTML. " "Do not wrap the prompt in quotation marks. " "Return only the prompt text." ) response = client.chat.completions.create( model=LIGHT_TASK_MODEL, messages=[ {"role": "system", "content": prompt}, {"role": "user", "content": f"Title: {article_title}\nContent: {content}"} ], max_tokens=20, temperature=0.9 ) share_prompt = response.choices[0].message.content.strip() share_prompt = share_prompt.strip('"\'') logging.info(f"Generated viral share prompt: {share_prompt}") return share_prompt except Exception as e: logging.error(f"Viral share prompt generation failed: {e}") return "Love This? Share It"