top of page

#2 - Let ChatGPT Program Your Own Twitter Sentiment Analyzer Without Coding

In recent years, there has been a growing interest in leveraging the power of large language models (LLMs) like OpenAI's ChatGPT to streamline and simplify complex tasks, including programming. This article explores the cutting-edge possibilities offered by ChatGPT in developing your own Twitter Sentiment Analyzer without writing a single line of code. As artificial intelligence continues to advance, LLMs are poised to revolutionize the way we approach coding, making it more accessible and efficient for people from diverse backgrounds and skill levels.


The future of utilizing LLMs for coding tasks is incredibly promising. By harnessing their natural language processing abilities, these models have the potential to save time, reduce errors, and facilitate innovative solutions. As LLMs continue to improve, the scope and complexity of coding tasks they can handle are expected to grow exponentially.

In this article, we will discuss a Google Chrome extension that capitalizes on ChatGPT's prowess to analyze sentiments on Twitter. With a seamless integration, this extension transforms your Twitter browsing experience by color-coding tweets in real-time. As you scroll through your feed, tweets will be highlighted in red, green, or gray to indicate negative, positive, or neutral sentiments, respectively. This intuitive color-coding system enables users to quickly gauge the prevailing mood of their feed, empowering them to engage with content more thoughtfully and efficiently.

You will need Google Chrome browser for this example.

#1. Open OpenAI ChatGPT

#2. Select the GPT-4 model. If you are using the free version that does not have GPT-4 it is still ok but you may need to try a few times to get an accurate result. I run it about 20 times and 15 of them worked.

#3. Run the prompt below:

I am writing a google chrome extension for my own use and need an example that colors a post on twitter.com website based on the sentiment of the post content with the help of OpenAI API. The example should be in plain javascript. The extension should have this functionality:

1) Provide me with example code for each file separately. The manifest.json file should be version 3. It should not have the icon attribute. The manifest should limit the content_scripts only to work on https://twitter.com and the manifest should not have a service_worker. The content script should be called content.js. The permissions attribute in the manifest allows only a list of permissions such as activeTab.

2) It should analyze each twitter post that is on the screen and also each twitter post that is loaded when I scroll the web page.

3) It should extract all text from each post.

4) The latest openapi model is text-davinci-003 and the endpoint is https://api.openai.com/v1/ completions. Do not specify the stop argument in the api call. It should declare the api key as a constant variable and put a placeholder with the text PASTE_YOUR_API_KEY so I can paste it there.

5) It should call the OpenAI api for each twitter post only one time. If the call to OpenAI api fails then it should not call the API again for that twitter post.

6) It should call the OpenAI api with the prompt below where the TEXT_HERE section is replaced with twitter post’s text.

“Classify the text into neutral, negative or positive. Provide me only the sentiment, without a period in lower case. Text: {TEXT_HERE} Sentiment: “

7) Based on the OpenAI api return it should color the frame and the background of the twitter post with the following colors: neutral = gray, negative = red and positive = green.

8) The twitter HTML is structured such that all posts are in a div with data-testid="cellInnerDiv" attribute. These divs are placed in a long hierarchy of other divs.

9) A trimmed down twitter post html div is below. Some tags are excluded for space purposes:

<div data-testid="cellInnerDiv" ><div class="css-1dbjc4n r-j5o65s r-qklmqi r-1adg3ll r-1ny4l3l"><div class="css-1dbjc4n"><article aria-labelledby="id__2sn47rid583 id__yqpyustjpvl id__tptzvmx1qnj id__be9uax4ihg id__vkfm774mew id__gcj1i27ejvu id__had2x7psvhb id__ucg28l9fq9g id__6dj1tuohyat id__qclx2zrwy9r id__e1udfjyp0cs id__te25jtrcf4 id__2sl93z9wi8p id__4no0agfilsp id__bptp4ap478c id__oavo3qp8ojj id__z9c4y8uh5 id__9vndpbu8euq" role="article" tabindex="0" class="css-1dbjc4n r-1loqt21 r-18u37iz r-1ny4l3l r-1udh08x r-1qhn6m8 r-i023vh r-o7ynqc r-6416eg" data-testid="tweet"><div class="css-1dbjc4n r-eqz5dr r-16y2uox r-1wbh5a2"><div class="css-1dbjc4n r-16y2uox r-1wbh5a2 r-1ny4l3l"><div class="css-1dbjc4n r-18u37iz"><div class="css-1dbjc4n r-1iusvr4 r-16y2uox r-1777fci r- kzbkwu"><div class="css-1dbjc4n"><div dir="auto" lang="en" class="css-901oao r-18jsvk2 r-37j5jr r-a023e6 r-16dba41 r-rjixqe r-bcqeeo r-bnwqim r-qvutc0" id="id__e1udfjyp0cs" data-testid="tweetText"><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0">ChatGPT is going international! What do you think? OpenAI's Sam Altman said he is considering opening an office and expanding services in Japan after a meeting with Japan's prime minister. Read more at: </span><a dir="ltr" href="https://t.co/J5hoPqfXWm" rel="noopener noreferrer nofollow" target="_blank" role="link" class="css-4rbku5 css-18t94o4 css-901oao css-16my406 r-1cvl2hr r-1loqt21 r-poiln3 r-bcqeeo r-qvutc0"><span aria-hidden="true" class="css-901oao css-16my406 r-poiln3 r-hiw28u r-qvk6io r-bcqeeo r-qvutc0">https://</span>lnkd.in/ghYbe2zn</a><span class="r-18u37iz"><a dir="ltr" href="/hashtag/chatgpt?src=hashtag_click" role="link" class="css-4rbku5 css-18t94o4 css-901oao css-16my406 r-1cvl2hr r-1loqt21 r-poiln3 r-bcqeeo r-qvutc0">#chatgpt</a></ span><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0"> </span><span class="r-18u37iz"><a dir="ltr" href="/hashtag/artificialintelligence?src=hashtag_click" role="link" class="css-4rbku5 css-18t94o4 css-901oao css-16my406 r-1cvl2hr r-1loqt21 r-poiln3 r-bcqeeo r-qvutc0">#artificialintelligence</a></ span><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0"> </span><span class="r-18u37iz"><a dir="ltr" href="/hashtag/japan?src=hashtag_click" role="link" class="css-4rbku5 css-18t94o4 css-901oao css-16my406 r-1cvl2hr r-1loqt21 r-poiln3 r-bcqeeo r-qvutc0">#japan</a></span></div></div><div aria- labelledby="id__b500zxmahpu id__l8qjnd2tpig" class="css-1dbjc4n r-1ssbvtb r-1s2bzr4" id="id__2sl93z9wi8p"><div aria-labelledby="id__9j0mc6l36nv id__qwr3j88kpwr" class="css-1dbjc4n r-1ets6dv r-1867qdf r-1phboty r-rs99b7 r-1ny4l3l r-1udh08x r-o7ynqc r-6416eg" id="id__l8qjnd2tpig" data- testid="card.wrapper"><div class="css-1dbjc4n" id="id__qwr3j88kpwr"><div class="css-1dbjc4n r-16y2uox r-1wbh5a2 r-z5qs1h r-1777fci r-kzbkwu r-1e081e0 r-ttdzmv" data-testid="card.layoutLarge.detail"><div dir="auto" class="css-901oao css-1hf3ou5 r-14j79pv r-37j5jr r-a023e6 r-16dba41 r-rjixqe r-bcqeeo r- qvutc0"><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0">economictimes.indiatimes.com</ span></div><div dir="auto" class="css-901oao css-1hf3ou5 r-18jsvk2 r-37j5jr r-a023e6 r-16dba41 r-rjixqe r- bcqeeo r-qvutc0"><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0"><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0">Japan government eyes AI adoption as OpenAI CEO Sam Altman mulls opening office</span></span></div><div dir="auto" class="css-901oao css-cens5h r-14j79pv r-37j5jr r-a023e6 r-16dba41 r-rjixqe r-bcqeeo r-qvutc0" ><span class="css-901oao css-16my406 r- poiln3 r-bcqeeo r-qvutc0"><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0">The remarks from Hirokazu Matsuno, a top government spokesperson, came shortly before Sam Altman, chief executive of OpenAI, met Japanese prime minister Fumio Kishida during a visit to Japan.</span></span></div></div></ a></div></div></div></div></div></div></article></div></div></div>


#4. Create the two chrome extension files that ChatGPT generated into a new folder

#5. Get your OpenAI API key. If you don’t know how to get your OpenAI API either ask ChatGPT or just search for “How to get my OpenAI API key” on the web for plenty of YouTube and other resources.

#6. Find and replace the PASTE_YOUR_API_KEY in the content.js file with the OpenAI API key

#7. Install the chrome extension. If you don’t know how to install the new folder as a Google Chrome Extension then either ask ChatGPT or just search for “How to install Google Chrome Extension” on the web for plenty of YouTube and step-by-step guides.

#8. Browse to twitter.com to your home feed and scroll down. With GPT-3.5, there will be a bug about 2 out of 10 times. In that case, you will see the error in the Javascript console of Google Chrome. Just go back to #3 and re-generate in a new ChatGPT session.

#9. The tweet background will get colored red, green or gray based on the sentiments


Bonus! Try changing the prompt to hide the negative tweets to for your kid’s safety. Play with it!


Help? IM me for any errors


For more AI topics follow me on https://lnkd.in/gai3E3ZA.

Or, join one of my AI programs for product managers and business professionals at https://aiproductinstitute.com


7 views0 comments
bottom of page