Edit Template

How I built a support agent using ChatGPT?

/ /

Before going further, I need to tell you a little bit of my background.

This month, I completed 5 years in content/growth marketing, and I have a Bachelor’s in Computer Science Engineering from one of the top 10 colleges in my state. It’s been almost 5.5 to 6 years since I last programmed anything. In fact, I’ve never actually developed anything during my college days. I wrote about my journey on how I joined Zoho as a content writer a few years back.

Enough of my background. Now, I’ll give you the context of this blog.

At Requestly, where I’m currently handling the Growth team, we decided to spend a day exploring AI and how it can influence our productivity. We were tasked to either build or find a good AI tool and had a “demo hour” where we showcased what we built/found.

Unsurprisingly, many of my colleagues found a lot of useful tools that can actually improve how we function at Requestly. A few tools I would like to mention here are writemyPRDyoodli, and reword. I found these tools very interesting, and you all should give them a try.

Now, I had way too many ideas on my mind that I wasn’t sure which one I should explore. Then, I finally settled down with the idea of building a ChatGPT module within our blogs and products. While I was exploring ChatGPT, I found this plugin called LinkReader that helps ChatGPT to read all the content within a given URL.

(P.S. This plugin was not available by the time I published this article! One more reason for me to be glad that I built this tool )

I wanted to build a similar tool that can read the content we have already published and provide a summary of the questions asked with a link to the relevant page. As a guy who can’t actually build, I just turned to ChatGPT itself to build an in-house ChatGPT.

It’s all about prompts!

Initially, I didn’t even know where to start and couldn’t find heads or tails of it. I started with building a link scrapper, so I went to ChatGPT and asked it to build me the scrapper by itself. It gave me a code that I didn’t even know how to run it!!

I went back to the basics. I tried to learn what Python Flask is, how to install Python on my Mac and how to run Python scripts. Gathered some ideas, installed Python and ran the script.

Boom! ran into something that every developer treads.

I had to call in some Air Support to clear out the buggies. My Co-founders and colleagues: Sagar, Sahil, and Rohan, were kind enough to get on a huddle with me and found that the port I was trying to call was used by some other tool, and that’s why Localhost wasn’t loading. While exploring this, I learned methods for identifying which tools are utilizing specific ports. You can also learn it from here.

My objective was to build a tool that can answer questions based on the URL I’m giving. Again, I turned to ChatGPT, and it advised me to go with Python Flask. I stayed with Bootstrap as the front end because I had experience in building basic web pages earlier. I named the app Vina as it means “question” in Tamil.

Reading all the content in a given URL will require a combination of different libraries, such as requests to handle the HTTP requests and beautifulsoup4 or lxml to parse the HTML content. So let me walk you through the process of creating the Vina app.

Step 1: Fetch and Parse Web Content

You will first need to fetch and parse the web content. This is how the code will look like:

The fetch_webpage function takes a URL and returns the HTML content of that page as a string. The parse_webpage function takes HTML content and returns a BeautifulSoup object that you can use to navigate the HTML tree. The extract_content function takes a BeautifulSoup object and returns a string with all the text on the page. The main function ties everything together. It fetches the webpage, parses it, extracts the content, and then prints the content.

Step 2: Setup OpenAI GPT Model

Firstly, you’ll need to install the OpenAI python client.

Next, you’ll need to set up the API key. This key is usually provided when you sign up for OpenAI’s API service. You can set this up in your environment using:

Step 3: Process the User Question and Generate a Response

With the web content and user question, you can then call the API to generate a response. The idea here is to prepend the question with the content of the webpage, which will serve as the context for the model. Then, ask the model to generate a summary or answer based on this context.

In this function, context is the content of the webpage, and question is the user’s question.

Step 4: Stitching all of them together

Now that we built a content parser and response generator, it’s time to stitch them together to get our Vina app.

It just changed the format of my prompts to a Q&A format so that the code can process the question and answer it. Once I updated the code, Vina was able to give me answers to the questions I was asking.

Now, I asked ChatGPT to modify the existing code to answer multiple questions for the given URL, and it changed the code like this:

Now all I have to do it to build a front for this code where I can share a URL and ask questions from the URL. So, this is the webpage I created for the Vina tool. I needed two pages- an ‘index’ page where I’ll be feeding the URL and an ‘ask’ page where I’ll be asking my questions and getting my answers.

Finally, after spending close to 4 hours, this is what the Vina app looks like: