Using GPT-3 to Create a Bot that Transforms Tweets into Poetry - No Coding Experience Necessary!
With the help of GPT-3, and Pipedream's innovative HTTP request builder tool, you can now turn tweets into poems - without any coding experience!
In this blog post, we will guide you through the process of using GPT-3 to build a bot that can turn tweets into beautiful short poems.
In the example below, the Twitter bot @twitbartbot inferred a reference to Chicago deep dish pizza restaurant and made a short poem about it:
But with this same technique you can add the power of A.I. to any of the 1,000+ app integrations that Pipedream has to offer, not just Twitter.
Watch this video or follow the guide below to learn how to use Connected Accounts with the HTTP request builder action in Pipedream.
Copy this workflow to your account, or follow the guide below to build it from scratch.
Twitter Bart, the tweet to poem GPT-3 Workflow Template
Getting Started
First, if you haven't already sign up for an OpenAI account.
Then you'll need to generate an OpenAI API key in order to interact with your account in a Pipedream workflow.
After logging into OpenAI, open up your profile menu in the top right and select View API keys.
Then click Create a new secret key to create a new API key. This will be your personal key to interact with GPT-3.
Copy this key to a secure location like a password manager. Now you're ready to start building a workflow.
Triggering the workflow on new Tweets
Now, sign into your Pipedream account or create one if you haven't already.
We'll start with a brand new workflow, and select Twitter as our trigger.
In this guide, we're using My Tweets action to trigger this workflow on our own account's tweets. But you can use a Search Tweets action to search tweets with a specific hashtag.
Then once your source has been created, you'll be able to select a Tweet to develop your workflow with.
In this guide, I choose a reply I sent to a friend asking for Chicago deep dish recommendations:
The full_text
field of a tweet is the actual content of a tweet. We'll pass this value to a GPT3 prompt.
Connecting your workflow to GPT-3
Now that we have a single tweet selected, we can now integrate our workflow into GPT-3.
Add another step to your workflow, and select the Send any HTTP Request action.
This will add an HTTP Request Builder action to your workflow. If you've ever used Postman or Insomnia, this will be very familiar to you.
Now we can connect our OpenAI account to this HTTP request. Click the Authorization Type dropdown and choose Select an app.
In the next window, search for the OpenAI app and select it.
Finally, click the Connect OpenAI account and paste in your OpenAI API key you created in the first step.
Now your OpenAI account is connected to this HTTP request step. You can integrate with any OpenAI endpoint.
There's no need to change your HTTP request headers or look up how to authenticate with an API. Pipedream automatically adjusts the HTTP request builder to successfully authenticate your account.
Poem-ifying the Tweet with GPT-3
The last step is to configure the HTTP request to pass our tweet to GPT-3 as a prompt.
Under the Body section of the HTTP request builder, select application/json as the Content-Type.
Now we can simply update our HTTP request to match the OpenAI's Completion endpoint.
For GPT-3 to answer a prompt, we'll need to tell this endpoint the prompt and which model to use to answer the prompt with.
Use the screenshot below as an example:
In the example above, we're defining text-davinci-003
as the A.I. model that OpenAI should use to process our prompt with.
The prompt
is our "question" to the A.I. model. In this example, we're asking it to turn the tweet from the first step into a short poem:
Turn the text below into a short poem:
{{ steps.trigger.event.full_text }}
The steps.trigger.event.full_text
is the content of the tweet we selected in step one.
If you're using some other trigger, like an HTTP webhook, or Google Sheet, or Discord message, then you'll need to adjust this value to match your trigger.
Finally, define a max_tokens
parameter on to limit the number of tokens used to create a response. This is another way to limit the number of characters.
Last but not least, click Test to send this prompt to GPT-3 and it will reply with a poemified version of the tweet. Pretty incredible right?
In this example, even just mentioning Millenium Park and Giordanos, GPT-3 was able to infer we're talking about Chicago. In poem response, it hints at a city and Lake Michigan.
Replying to the original thread
The main focus this tutorial is integrating GPT-3 into a workflow.
If you're simply sending tweets without mentioning other Twitter users, you can use the Twitter create a tweet action.
However, this bot sends replies to existing tweets, which requires mentioning them:
If you want to have a bot reply to existing tweets, you'll need to use a custom Twitter Bot.
Learn how to set up a custom Twitter Bot in the video below:
Then you'll able to use the Twitter Developer App integration in Pipedream without these restrictions.
Next steps
You've now created a workflow that leverages cutting edge A.I. and without any code!
You can use OpenAI for so much more, including content generation, summaries, image generation and even translations.
Now that you've learned a basic workflow, try watching our free University course to learn how to harness the power of workflows for both no-code and code-ful workflows.
Learn more and get connected!
🔨 Start building at https://pipedream.com
📣 Read our blog https://pipedream.com/blog
💬 Join our community https://pipedream.com/community