In this tutorial, you’ll learn how to add a sitemap to an existing project on CustomGPT.ai using our CustomGPT’s RAG API. We’ll cover setting up your environment in Google Colab, and then updating the project. Follow along with the code walkthrough to understand each step of the process.
Make sure you have read our Getting Started with CustomGPT.ai for New Developers blog to get an overview of the entire platform.
Notebook Link – https://github.com/Poll-The-People/customgpt-cookbook/blob/main/examples/Add_a_sitemap_to_an_existing_project.ipynb
1. Prerequisites to use CustomGPT’s RAG API
Before you begin, make sure you have the following:
- CustomGPT.ai Account: Sign up and log in at CustomGPT.ai.
- RAG API Key: Generate your RAG API token from your dashboard and keep it secure.
- Basic Python Knowledge: Familiarity with Python and making HTTP requests using libraries like requests.
- Google Colab: We’ll run the code on Google Colab, so you don’t need any local setup.
2. Setting Up Your Environment in Google Colab
Opening the Notebook
- Upload the Notebook: Open Google Colab and upload the
Add_a_sitemap_to_an_existing_project
.ipynb file. - Verify the Code Cells: Ensure that the required libraries (requests and json) are available. These come pre-installed in Colab, so you’re all set to run the code.
Configuring Your RAG API Key and Endpoints
At the beginning of the notebook, the RAG API endpoint and token are configured:
api_endpoint = 'https://app.customgpt.ai/api/v1/'
api_token = 'ADD_YOUR_API_TOKEN_HERE'
# imports
import requests
import json
Replace ‘ADD_YOUR_API_TOKEN_HERE
‘ with your actual RAG API token. This token authenticates your RAG API calls to CustomGPT, so keep it secure. Plus add the required imports.
Get Your RAG API Key
To get your RAG API key, there are two ways:
Method 1 – Via Agent
- Agent > All Agents.
- Select your agent and go to deploy, click on the API key section and create an API.
Method 2 – Via Profile section.
- Go to profile (top right corner of your screen)
- Click on My Profile
- You will see the screen something like this (below screenshot). Here you can click on “Create API key”, give it a name and copy the key.
Please save this secret key somewhere safe and accessible. For security reasons, You won’t be able to view it again through your CustomGPT.ai account. If you lose this secret key, you’ll need to generate a new one.
3. Code Walkthrough
Let’s break down the notebook code to understand how it works.
3.1 Retrieving the Project ID
Go to the particular project you wish to add / upload files to, then, navigate to the Deploy section.
You will find the Agent ID on the right top corner.
project_id = 1234
This ID is crucial as it tells the RAG API where to add the file in the next step.
3.2 Adding (or Updating) the Sitemap to the Existing Project
With the project ID in hand, you can now add a new sitemap to your project:
- Set the New Sitemap Path:
new_sitemap_path = 'https://adorosario.github.io/small-sitemap.xml'
- Prepare the Payload: The payload now includes just the sitemap path:
payload = json.dumps({
"sitemap_path": new_sitemap_path
})
- Construct the RAG API Endpoint and Send the Request: The endpoint is built using the project ID:
url = api_endpoint + 'projects' + f"/{project_id}/" + 'sources'
create_source = requests.request('POST', url, headers=headers, data=payload)
print(create_source.text)
- The response should confirm that the sitemap has been successfully added (or updated) in your project.
4. Running and Testing the Notebook
Now that your notebook is set up, it’s time to execute it to create your project and upload files. Follow these instructions to make sure everything works as expected.
Executing the Notebook
- Run Each Cell Sequentially:
Start by executing the cells in order. First, your project will be created, and then the sitemap will be added. - Monitor the Outputs:
- Check the JSON response after project creation for the project ID.
- Verify the final output to ensure the sitemap has been added.
Verifying on CustomGPT.ai
After running the notebook, log into your CustomGPT.ai dashboard. Your project should now display the updated sitemap information, confirming that your RAG API calls were successful.
5. Troubleshooting Common Issues
While the process is straightforward, here are some common issues you might encounter:
- Invalid RAG API Key: Ensure your RAG API key is correctly set in the notebook.
- Endpoint Errors: Verify that the constructed URL, especially with the project ID, is accurate.
- Network Issues: Check your internet connection if the requests are timing out.
- JSON Parsing Errors: Make sure the RAG API responses are properly formatted and that you are accessing the correct keys.
For additional help, refer to the CustomGPT.ai documentation or reach out via community support channels.
6. Conclusion
In this guide, we demonstrated how to add a sitemap to an existing project using the CustomGPT”s RAG API in a Google Colab notebook. You learned how to:
- Configure your RAG API key and set up the environment.
- Create a new project with an initial sitemap.
- Extract the project ID and add (or update) the sitemap using a subsequent RAG API call.
- Run the notebook and verify the changes on your CustomGPT.ai dashboard.
By following these steps, you can easily manage and update your project configurations through RAG API calls. Enjoy building your projects and integrating powerful features with CustomGPT.ai!
If you have any questions or need further assistance, feel free to reach out. Happy coding with CustomGPT.ai!
Priyansh is Developer Relations Advocate who loves technology, writer about them, creates deeply researched content about them.