2.11.2022

Our DevSquad Twitter Posts are now written by OpenAI

We're now generating our DevSquad Tweets with OpenAI's GPT-3. Previously, we just hardcoded the Message:

image

It's obvious to the reader that the tweet is auto generated, reducing the likelyhood of someone interacting with the tweet. Also it doesn't fit twitters platform very well, there are no custom hashtags and a twitter profile where most tweets start with the same 4 words just looks boring.

What if we could make the tweets more interesting by generating them with OpenAI? The language model was mostly trained on data crawled from the web, which probably included a lot of tweets. So it should be pretty good at tweeting!

I jumped into OpenAI's playground and started experimenting. Having played with OpenAI before, I had a rough idea how a good prompt might look and I quickly got great results:

image

We finally chose the following prompt for our bot:

Write a tweet about the following content including three hashtags and not more then 250 characters: 
---
${feedItem.title}
${feedItem.content}
---
Tweet:

250 characters were chosen, so we can append the DevSquad url at the end. Twitter automatically generates a shortlink for urls, so 30 characters should be enough for all urls.

The complete Tweet generation looks like this:

import { RssFeedItem, Tweet } from "./twitter-bot";

const { Configuration, OpenAIApi } = require("openai");

const OPENAI_TOKEN = process.env.OPENAI_TOKEN;

const configuration = new Configuration({
  apiKey: OPENAI_TOKEN,
});
const openai = new OpenAIApi(configuration);

export async function composeTweetWithOpenAI(feedItem: RssFeedItem): Promise<Tweet> {
  const openAIResponse = await openai.createCompletion({
    model: "text-davinci-002",
    prompt: `Write a tweet about the following content including three hashtags and not more then 250 characters: 
---
${feedItem.title}
${feedItem.content}
---
Tweet:
`,
    temperature: 0.7,
    max_tokens: 256,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  });

  return {
    guid: feedItem.guid,
    title: feedItem.title,
    message: openAIResponse.data.choices[0].text + "\n" + feedItem.link,
  };
}

The first tweet last Wednesday looked Promising:

image

I'm now looking forward to read all the future DevSquad tweets.

Lucas

Softwareentwickler

Zur Übersicht

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund