In our last blog, we had a look at the Guide on CustomGPT SDK in detail. In this blog, we will programmatically build a Custom chatbot using CustpmGPT SDK. Creating a chatbot and performing various other tasks using CustomGPT SDK involves the following few steps. Let’s outline those now.
Start downloading the CustomGPT Software Development Kit (SDK) by executing the command “!pip install customgpt-client” in your Jupyter notebook. This kit contains the tools and resources you need to create and integrate the CustomGPT chatbot into your application.
Define the purpose of your chatbot, for what you want to build your chatbot. Initialize your chatbot project by specifying details like the name of your chatbot and the sitemap for your chatbot. Create a sitemap for your project using the free sitemap tool offered by CustomGPT.
To create your chatbot, use the CustomGPT SDK libraries to write the necessary code. These libraries are toolkits that provide functions and tools to use CustomGPT’s capabilities.
Import “CustomGPT” from the “customgpt_client library” to write code for your chatbot. Use the API_key that you get from your CustomGPT account and place it in “YOUR_API_TOKEN.”
See the full blog on How to get your CustomGPT API_key.
Now create your CustomGPT chatbot by specifying its project_name and sitemap_path you created above. When you specify these details, a project will be created into your CustomGPT account using API_key. Through API_key customgpt first authorizes you as a valid user to access and integrate the CustomGPT chatbot into your application.
Now run the code, and your chatbot will be created successfully. In response, you will also get information about your chatbot like your project_id. This project_id will be used to test your chatbot activation.
After creating your chatbot project, it’s essential to check its status and ensure that the chatbot is active and ready to answer your questions. In the provided code, we retrieve information about the project, including its ID and chatbot activation status. This step involves making inquiries about the project’s details to confirm whether the chatbot is active, as indicated by the “is_chat_active” flag in the project detail response.
Now write your project_id in this line of code “project_id = data.id” and run the code. If the generated response is shown as True it indicates that the chatbot is active and ready to answer and if the chatbot is not active the response will be shown as False.
In response True is shown indicating that the chatbot has been created and activated successfully.
First, create a conversation in your project before start querying the chatbot. To create the first conversation run the following lines of code in your development environment.
Here with SDK, you don’t have to perform different operations to create and query chatbot using API endpoints separately. With the CustomGPT SDK, just write your API_key and project_id and it will perform all operations using built-in functions following just a few lines of code.
After checking the status of your chatbot, now it’s time to ask it some relevant questions to test if is it working as intended.
By executing the above lines of code your query will be sent to the CustomGPT chatbot using the build-in function “CustomGPT.Conversation.send” from SDK. Then CustomGPT SDK will forward this query to your CustomGPT chatbot. The response is displayed using the “print function”. This way you can check if your chatbot is generating relevant and accurate responses based on the data it has been trained on.
You can also retrieve messages from any conversation in your project. This can be done by using the CustomGPT SDK to retrieve messages from a specific conversation using the function “CustomGPT.Conversation.message” in your CustomGPT project.
This functionality allows you to access past user interactions, messages, and queries in your project. It’s a function for reviewing the performance of your chatbot, and understanding user interactions, so you can adjust to enhance its conversational abilities and behavior.
You can also delete conversations of your chatbot easily using CustomGPT SDK. In the code lines below, we are using the CustomGPT SDK to delete a specific conversation from your project using the built-in function “CustomGPT.Conversation.delete”.
You can delete an entire project using the CustomGPT SDK to delete a specific project.
By executing the built-in function “CustomGPT.Project.delete” from CustomGPT SDK, the project will be removed including all its data. The print function at last displays the response that the project has been deleted successfully.
In the following code, we are utilizing the CustomGPT SDK to retrieve specific settings related to a particular project, identified by its unique project ID.
When you execute this code, you get a detailed of various settings associated with the project. These settings include preferences, configurations, or parameters that influence how your chatbot behaves or interacts. Understanding project settings is crucial for fine-tuning your chatbot’s behavior and ensuring it aligns with your desired outcomes.
Utilizing the CustomGPT SDK comes with a host of advantages tailored for developers for chatbot creation:
By following the steps outlined in this guide, developers can effortlessly build and customize chatbots, enhancing their applications’ capabilities without the need for extensive coding.
This SDK not only streamlines the development process but also offers a plethora of advantages, from efficiency and consistency to flexibility and enhanced functionality. As we conclude, envision the CustomGPT SDK as your ally, simplifying the creation and integration of CustomGPT chatbots and elevating the user experience within your applications. Stay connected for more insights and practical applications of CustomGPT APIs in upcoming blogs.