1. Introduction
Hi there! In this guide, we’ll show you how to update agent’s name using the CustomGPT RAG API’s Python SDK. Although the code still refers to “project,” in our discussions we often call them “agents.” Whether you’re rebranding your chatbot or simply organizing your work, this tutorial will walk you through creating an agent and then updating its name—all in a clear, step-by-step format.
Make sure you have read our Getting Started with CustomGPT.ai for New Developers blog to get an overview of the entire platform.
Get the cookbook link here – https://github.com/Poll-The-People/customgpt-cookbook/blob/main/examples/Update%20a%20project%20name.ipynb
2. Setting Up the Environment
Before we start, we need to prepare our workspace in Google Colab. This involves specifying the API endpoint, setting up your API token, and importing the necessary libraries.
Code Sample:
# setup API URL and API Token
api_endpoint = 'https://app.customgpt.ai/api/v1/'
api_token = 'ADD_YOUR_API_TOKEN_HERE'
headers = {
'Content-type': 'application/json',
'Authorization': 'Bearer ' + api_token
}
# imports
import requests
import json
What This Does:
- API Endpoint & Token: Sets the base URL for all API calls and uses your API token for authentication (ensure you replace ‘ADD_YOUR_API_TOKEN_HERE’ with your actual API token).
- Headers: Prepares the HTTP headers required for the requests, including the content type and authorization details.
- Imports: Loads the requests library to handle HTTP requests and the json module to manage JSON data.
Get API keys
To get your 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.
Now that our environment is ready, let’s ensure you have everything set up before moving forward.
3. Prerequisites
Before you dive in, check that you have the following:
- CustomGPT.ai Account: Sign up and log in at CustomGPT.ai.
- API Key: Generate your API token from your account dashboard.
- Basic Python Knowledge: Familiarity with Python and REST APIs will help you follow along.
- Google Colab: We’re using Google Colab—so no local installation is needed!
With these prerequisites in hand, it’s time to create your agent.
4. Creating an Agent (Project) for Your Account
In this section, you’ll create a new agent using a sitemap. Remember, even though the code says “project,” think of this as creating your agent’s workspace.
Code Sample:
# Give a name to your project
project_name = 'Example ChatBot using Sitemap'
sitemap_path = 'https://adorosario.github.io/small-sitemap.xml'
payload = json.dumps({
"project_name": project_name,
"sitemap_path": sitemap_path
})
url = api_endpoint + 'projects'
create_project = requests.request('POST', url, headers=headers, data=payload)
print(create_project.text)
Explanation:
- Agent Details: The code sets a name for your agent and provides a sitemap URL which serves as the content source.
- Payload Creation: Your agent details are converted into JSON format, which is required by the API.
- POST Request: A POST request is sent to create your agent. If successful, the API returns a response containing details like the agent’s unique ID.
- Output: The code prints the JSON response, which should look similar to:
{"data":{"id":507,"project_name":"Example ChatBot using Sitemap",...},"status":"success"}
Great! Now that your agent is created, let’s update its name to give it a fresh identity.
5. Updating the Project Name
Once you have your agent’s ID, you can update agent’s name. This might be useful when rebranding or refining your agent’s title for clarity.
Code Sample:
# Check status of the project if chat bot is active
data = json.loads(create_project.text)["data"]
# Get project id from response for created project
updated_project_name = 'New Example ChatBot using Sitemap'
project_id = data["id"]
payload = json.dumps({
"project_name": updated_project_name
})
# Update the project
url = api_endpoint + 'projects' + f"/{project_id}"
create_project = requests.request('POST', url, headers=headers, data=payload)
print(create_project.text)
Explanation:
- Extracting Agent ID: The code parses the original response to retrieve the agent’s unique ID (project_id).
- Define New Name: A new name is assigned to the agent by setting the variable updated_project_name.
- Payload for Update: The new agent name is then converted into JSON format.
- POST Request for Update: A POST request is sent to the agent’s specific URL (constructed using its ID) to update the name.
- Output: The updated JSON response is printed, showing that your agent now has the new name, for example:
{"data":{"id":507,"project_name":"New Example ChatBot using Sitemap",...},"status":"success"}
Nice work! Your agent now sports a fresh new identity. Next, let’s go over a few common issues you might encounter.
6. Troubleshooting Common Issues
Here are a few tips to resolve common problems you might face:
- Invalid API Token: Make sure you have replaced ‘ADD_YOUR_API_TOKEN_HERE’ with your actual API token.
- Incorrect JSON Formatting: If you encounter errors when parsing or sending JSON, verify that your payload is correctly formatted.
- Connection Problems: Ensure your internet connection is stable and that the API endpoint URL is correct.
- Unexpected API Responses: Double-check that you’re using the correct endpoints and that the agent ID is being correctly extracted from the response.
If you continue to have issues, consult the official CustomGPT documentation or join the community forum for further support.
7. Conclusion
Congratulations! You’ve now learned how to:
- Set up your Google Colab environment with the necessary API endpoint, token, and libraries.
- Create an agent (project) using a sitemap as the content source.
- Update the agent’s name to give it a fresh identity.
This process is a great way to manage and rebrand your chatbot on the fly. If you have any questions or need further help, feel free to check out the CustomGPT documentation or ask in our community.
Happy coding, and enjoy building your custom chatbot solutions with CustomGPT!
Priyansh is Developer Relations Advocate who loves technology, writer about them, creates deeply researched content about them.