Files

1 line
4.1 KiB
JSON

{"repo": "bayramannakov/xai-202410", "files": {"grok.py": {"41f64d9d7eb9535e486f7ed1f6d4fa752ea5d309": {"t": 1785674551.153949, "n": 3886, "h": "7276db0c56ee6817", "c": "import dotenv\n\ndotenv.load_dotenv()\n\nimport os\n\nfrom openai import OpenAI\n\nimport json\n\n\nclient = OpenAI(\n api_key=os.getenv(\"XAI_API_KEY\"),\n base_url=\"https://api.x.ai/v1\",\n)\n\ndef get_completion(prompt: str, system_prompt:str) -> str:\n completion = client.chat.completions.create(\n model=\"grok-preview\",\n messages=[\n {\"role\": \"system\", \"content\": system_prompt},\n {\"role\": \"user\", \"content\": prompt},\n ],\n )\n\n return completion.choices[0].message\n\n\n# completion = client.chat.completions.create(\n# model=\"grok-preview\",\n# messages=[\n# {\"role\": \"system\", \"content\": \"You are Grok, you help people get information about the trends and posts on social media\"},\n# {\"role\": \"user\", \"content\": \"What are the topics people are talking about in SF as of Oct 12?\"},\n# ],\n# )\n\ndef get_ad_copy(product, city):\n response = get_completion(\n prompt=f\"\"\"\n\n Today is October 12th, 2024\n \n Instructions:\n 1. Get today's headlines in {city} to understand what people are talking about.\n 2. Use these headlines information to generate 3 variations of ad copies for a {product}. Each variatin should be unique and tailored to a different topic. Do not include hashtags.\n 3. Review the ad copies and make any necessary changes to ensure it is relevant to one of the topics people are talking about in San Francisco as of Oct 12 2024. Be specific about the topic you choose. \n \n Output ad copy in the following json format:\n [{{\n \"ad_copy\": \"The X.AI hackathon is happening in San Francisco on Oct 12. Come build the future with us to support free and open AI for everyone.\",\n \"trend\": \"free and openAI\",\n \"explanation\": \"The ad copy is relevant to the topic of free and openAI that people are talking about in San Francisco as of Oct 12\",\n }},\n {{\n \"ad_copy\": \"Experience the power of the iPhone 16 - it's like having Fleet Week in your pocket. Capture stunning aerial photos and videos with unparalleled clarity, just like the Blue Angels soaring above San Francisco.\",\n \"trend\": \"Fleet Week\",\n \"explanation\": \"The ad copy is relevant to the topic of Fleet Week, where aerial displays by the Blue Angels are a highlight, linking this event to the iPhone's superior camera capabilities.\",\n }},\n {{\n \"ad_copy\": \"Tune in to the sounds of innovation with AirPods 4. While the San Francisco Tech Week highlights the latest in tech, AirPods 4 provides an unparalleled audio experience for those immersed in the city's tech scene..\",\n \"trend\": \"San Francisco Tech Week\",\n \"explanation\": \"This ad copy aligns with San Francisco Tech Week, focusing on how AirPods 4 can enhance the experience of tech events with its superior sound technology\",\n }}]\n\n Just output the json.\n\n Example of a single ad copy with a headline:\n Headline: Cultural Events: The Blue Angels performed over San Francisco Bay as part of Fleet Week, attracting attention and providing a contrast to the city's daily challenges with a display of aerial prowess.\n Ad Copy: \"Join us for the X.AI Hackathon today! While the Blue Angels dazzle us with aerial feats over the San Francisco Bay for Fleet Week, we're diving into a different kind of innovation. Here at X.AI, we're exploring the frontiers of artificial intelligence. Let's soar to new heights together in tech as the Blue Angels do in the skies!\"\n \"\"\",\n system_prompt=\"You are AI social ads assistant; You help people to generate ad copies for their products and events, by tailoring them to the trends\",\n )\n\n json_response = response.content.strip(\"```json\").strip(\"```\")\n\n print(json_response)\n \n return json.loads(json_response)\n\n\n\n"}}}}