Integrating ChatGPT API with a Dialogflow website chatbot

On this website you will see a GPT demo bot.

I built the bot by using the GPT API to generate a Dialogflow ES bot (in other words, the chatbot is powered by Dialogflow ES, but was constructed using GPT API).

This is not the ideal use case for website articles (that is, a search interface would be much better for these situations) but it is a very good way to

a) understand how to use the GPT API and

b) to understand the pros and cons of using the GPT API for various chatbot tasks.

Here are the steps required to build such a bot:

  • Export the WordPress XML file for each post type (you can also do it all at once, but it becomes unwieldy for large-ish websites)
  • Loop through the export XML file and use the GPT API to create Dialogflow ES intents based on the article content (as explained in the next set of steps)
  • Use the GPT Completion API and ask it to generate a summary for the article
  • Use the GPT Completion API and ask it to rewrite the article as a list of 11-15 questions. This is in line with 10 or more training phrases recommended by Dialogflow.
  • Why 11-15 and not a constant number? It is because adding tiny “perturbations” is a form of prompt engineering and generally ensures that the GPT API does not completely fail the request in trying to provide a unique response (compared to the last one)
  • Save all the responses from the completions API calls (i.e. don’t make the same call to the API twice – it is wasteful)
  • Write Python code to parse all the GPT responses and create one Dialogflow ES intent per article
  • The intent name will be based on the article name, as expected
  • The intent training phrases will be a simple concatenation of the article title and the question generated by the GPT API – one training phrase per question generated
  • The response will be the article summary generated by GPT API
  • The response will also include a link to the article. In case the Summary generated by GPT has some inaccuracies (aka hallucations), the reader will still be able to click on the link and read the article for themselves to verify the answer


About this website

BotFlo1 was created by Aravind Mohanoor as a website which provided training and tools for non-programmers who were2 building Dialogflow chatbots.

This website has now expanded into other topics in Natural Language Processing, including the recent Large Language Models (GPT etc.) with a special focus on helping non-programmers identify and use the right tool for their specific NLP task.

1 BotFlo was previously called MiningBusinessData. That is why you see that name in many videos

2 And still are building Dialogflow chatbots. Dialogflow ES first evolved into Dialogflow CX, and Dialogflow CX itself evolved to add Generative AI features in mid-2023