Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,33 @@ def authenticate_openai():
|
|
| 21 |
# Function to generate a tweet using GPT-3
|
| 22 |
def generate_tweet():
|
| 23 |
response = openai.Completion.create(
|
| 24 |
-
engine="text-davinci-003", # Choose the model to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
|
|
|
|
| 21 |
# Function to generate a tweet using GPT-3
|
| 22 |
def generate_tweet():
|
| 23 |
response = openai.Completion.create(
|
| 24 |
+
engine="text-davinci-003", # Choose the model to use
|
| 25 |
+
prompt="Create a tweet in the style of a humorous AI agent, keeping it casual and engaging.",
|
| 26 |
+
max_tokens=50
|
| 27 |
+
)
|
| 28 |
+
tweet = response.choices[0].text.strip()
|
| 29 |
+
return tweet
|
| 30 |
+
|
| 31 |
+
# Function to send the tweet to Twitter
|
| 32 |
+
def send_tweet(api, tweet):
|
| 33 |
+
try:
|
| 34 |
+
api.update_status(tweet) # Send the generated tweet
|
| 35 |
+
print(f"Tweet sent: {tweet}")
|
| 36 |
+
except tweepy.TweepError as e:
|
| 37 |
+
print(f"Error: {e}")
|
| 38 |
+
|
| 39 |
+
# Main function to control the tweet posting loop
|
| 40 |
+
def main():
|
| 41 |
+
twitter_api = authenticate_twitter() # Get Twitter API instance
|
| 42 |
+
authenticate_openai() # Authenticate OpenAI API
|
| 43 |
+
|
| 44 |
+
while True:
|
| 45 |
+
tweet = generate_tweet() # Generate a new tweet
|
| 46 |
+
print(f"Generated Tweet: {tweet}")
|
| 47 |
+
send_tweet(twitter_api, tweet) # Send the tweet to Twitter
|
| 48 |
+
time.sleep(1800) # Wait for 30 minutes before posting the next tweet
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
main() # Start the program
|
| 52 |
|
| 53 |
|