API to Chatbot in less than 5 minutes | Vertex AI Extensions

Vaibhav Malpani
Google Cloud - Community
6 min readMay 10, 2024

Learn how to quickly create a chatbot over your API using Vertex AI Extensions. No coding or training required. Interact with your API seamlessly through a chat interface. Read more to explore the possibilities!

What is API?

An API (Application Programming Interface) serves as a bridge between various software programs. It defines a set of rules and requirements that apps may follow to interact with one another.

What is Chatbot?

A software program that simulates human-user conversations. Chatbots are frequently used in messaging apps, websites, and customer service to offer information or do tasks.

Traditionally, a Chatbot is trained on intents to understand which data to be fetched, what all parameters are required and how to extract them from the prompt given by user and at the end format the API response for easy reading. This will improve readability for the user.

Problem Statement:

If any changes are made to API, like taking in a new parameter, change in the response from API, in that case, we will have to make the changes in the chatbot as well to handle the new changes. Similarly, if a new API is added, then the whole process of creating intent, extracting parameters, prettifying API response.

Solution:

Using Extension in Vertex AI, to build Chatbots over your API. How to do it?? Just follow the steps below!!

Disclaimer: Extensions in Vertex AI is still in PREVIEW. It Is under development and gaining functionalities.

AI Generated by SDXL 1.0

How to Build a Chatbot over your API?

  1. Create a sample OpenAPI specification file (only yaml file supported till now). I have used a sample file from swagger and trimmed down the file to only include API related to pets.
  2. Login to Google cloud console, and navigate to Extensions in Vertex AI. Click on “Create Extension”

3. Enter the name that you want to give to the extension, we have given name as “pet_store”. Then enter any description that you want and in the Extension Type, Click on “Custom”. (For other 2 Extension Types stay tuned and follow, I am going to soon write about them)

4. Once you select Custom Extension Type, you will get a below form, just enter details according to your API. In the OpenAPI Spec file section, upload you YAML file created in STEP 1.

If there are no error, you would get the below confirmation as “No errors detected”. Along with that it will also list down all the APIs that are present in the YAML file. (as seen in the below image). For this demo, with will select “No Authentication”, but if your application requires authentication you can set that up in the “Authentication” dropdown.

5. Once the extension is created you would see a screen like shown below. This shows that your Chatbot is ready and you can query it in the below text box. Let us try some examples and check.

Testing the Chatbot:

  1. Lets try to create a new pet in our pet store. I just put the query as “add a pet” and it was quickly able to understand what are the required parameters to create a pet. So the bot asked me one by one to enter the name and then the id for our new pet. Once it got all the required information, it created the pet.

2. Let’s try to get the information for our newly created pet. When I ask “get pet”, it understood that there is not API to get all pets and hence asked me for an id. Once the id is entered, the chatbot was able to fetch the information for the pet we just now created.

3. Let’s add one more pet. When queried for “add a pet”, it asked for the name, then id and then finally the status. Notice how it gave me the options for status (available, pending or sold). This is because these are the options mentioned in the YAML file for the status field.

4. Let’s try to get the new pet that we created. The Chatbot gets the complete information when the id is entered.

5. Now let us try to update the pet and see if the bot is able to handle it. So when I query “update pet”, it asks for the id, and then asks what field i need to update, is it name or status. So when I enter “status is sold”, it updates that and gives the response for the successful status update.

6. To be actually sure if the value is updated in backend or not, I tried to get the pet infomation. But this time, in the first query itself i have the id and did a query as “get pet 123”. This time the Chatbot got the id and did not ask again for the id. In the very next step, it has come back with the response saying the pet with id 123 is sold.

7. Finally, lets now try to delete the pet. When I query “delete pet”, the Chatbot asks me for the id, and when the id is entered it deletes that entry for pet with id 123.

As seen above, We were able to interact with our API, perform CRUD operations (Create, Read, Update, Delete) through the Chatbot which required no training, no coding!!

Opportunities for improvement:

  1. It only supports Content Type with “application/JSON” for input and output.
  2. Currently it does not work with query parameters.
  3. There should be an option to update the YAML file once uploaded. Currently to update the YAML, you would have to delete the old Extension and create a new one.
  4. Currently it only supports calling the Chatbot through REST API or through GCP console. It would be great to have it integrated in the Vertex AI SDK.

Conclusions:

  1. It have become very easy to create a Chatbot over your APIs.
  2. You won’t have to train the Chatbot again once new APIs are added.
  3. You won’t have to manage the context and parameter values given by the user.

If you enjoyed this post, give it a clap! 👏 👏

Interested in similar content? Follow me on Medium, Twitter, LinkedIn for more!

--

--

Vaibhav Malpani
Google Cloud - Community

Google Developer Expert for Google Cloud. Python Developer. Cloud Evangelist.