Optimize Your Custom GPT Workflow: Automating Document Management with CustomGPT.ai API

CustomGPT.ai

While CustomGPT.ai may be known for its no-code AI development platform, it also features an incredibly robust, developer friendly, modern API and SDK

This blog post introduces example code for a command line utility that searches a CustomGPT.ai project for all documents or items containing a specific string and then deletes them. This functionality is critical for maintaining an organized and relevant knowledge base within your chatbot project. 

This post will guide you through the capabilities of the CustomGPT.ai API, particularly focusing on creating, deleting items, deleting all items, deleting based on a filter, and updating items within a project. 

The Source Deleter Command Line Tool

The source_deleter tool is a powerful command line utility designed to streamline document management within a CustomGPT.ai project. The full source code is available on GitHub. Take a look! 

Here’s its functionality to perform different tasks:

Get all files (Custom data) Function

The code snippet begins by importing the requests library and defining a function called get_files. This function is designed to retrieve a list of all uploaded files for a specific project using the CustomGPT.ai API

  • It starts by initializing an empty list called all_files to store the file information. It then constructs the appropriate URL using the provided project_id to access the correct API endpoint. 
  • The function sets up the necessary headers, including the API key for authorization. It sends a GET request to the URL with these headers. If the API responds successfully (status code 200), it parses the JSON response to extract the list of files and adds them to the all_files list.
  •  If the request fails, it prints an error message with the status code and response text. Finally, the function returns the list of files, making it straightforward to manage and retrieve files uploaded to a CustomGPT.ai project.

Delete File Function

This code snippet defines a function called delete_file that deletes a specific file from a CustomGPT.ai project using its file ID. 

  • The function takes three arguments: api_key, project_id, and file_id. It constructs a URL to the appropriate API endpoint using the project_id and file_id. 
  • The necessary headers, including the API key for authorization, are set up. The function sends a DELETE request to the URL with these headers. 
  • If the request is successful (status code 200), it prints a success message indicating that the file with the specified ID has been deleted. If the request fails, it prints an error message with the status code and response text, providing details about the failure. 

This function simplifies the process of removing specific files from a CustomGPT.ai project.

Function to delete the file containing a specific string

This code snippet defines a function named delete_files_containing_string.

  • The function takes three arguments: api_key, project_id, and search_string. It aims to delete all files within a CustomGPT.ai project that contain a specified string in their filename.
  • First, it calls the get_files function to fetch all files from the project specified by project_id. Then, it iterates over each file in the fetched list. For each file, it checks if the search_string (case-insensitive) is present in the filename. If the string is found, it calls the delete_file function to delete that file from the project using its file_id.

In summary, this function facilitates the deletion of files containing a specified string in their filename from a CustomGPT.ai project.

Main Function

This portion of the code serves as the entry point for the script. The main function prompts the user to input their CustomGPT.ai API key, project ID, and the string they wish to search for in filenames. It then calls the delete_files_containing_string function with these inputs to initiate the process of deleting files containing the specified string from the CustomGPT project.

The if __name__ == “__main__”: block ensures that the main function is executed only when the script is run directly, not when it’s imported as a module in another script. This ensures that the script behaves as intended when executed from the command line.

Execute the script of the Source_deleter tool

To run the source_deleter tool from the command line download the source_deleter.py file and follow the given instructions:

  • Open the command line interface on your computer.
  • Navigate to the directory where the source_deleter.py file is located using the cd command. Define the path.
  • Once you’re in the directory containing the source_deleter.py file, type python source_deleter.py and press Enter to execute the script.
  • You will be prompted to enter your CustomGPT API key. Copy your API key from the CustomGPT.ai platform and paste it into the command line, then press Enter.

Read the full blog on how to get your API key and Project ID..

  • Next, you’ll need to enter the project ID for the CustomGPT project you wish to manage. You can find this ID in the settings of your chatbot project on the CustomGPT.ai platform. Paste the project ID into the command line and press Enter.
  • Finally, the script will ask you to enter a string that it will use to identify files for deletion. For example, if you enter .pdf, the script will delete all files with a .pdf extension within the specified project.
  • Type the string you want to search for and press Enter.

The script will then search for and delete any documents within the specified project that contain the provided string in their filenames. So, now you can use this command line tool and manage the documents within your chatbot project efficiently. 

Conclusion

In conclusion, this blog post has explored the functionality of the source_deleter tool, demonstrating how it can be used to manage documents within a CustomGPT.ai project efficiently. By leveraging the CustomGPT API, developers can automate the process of deleting files based on specific criteria, saving time and streamlining their workflow. From fetching files to deleting them based on a given string, this tool offers a practical solution for document management within chatbot projects.

 With its simple command-line interface and integration with the CustomGPT platform, developers can easily incorporate this tool into their workflow to enhance project management and efficiency. Overall, the source_deleter tool serves as a valuable resource for developers working with CustomGPT.ai, helping them manage their chatbot projects effectively.

Build a Custom GPT for your business, in minutes.

Deliver exceptional customer experiences and maximize employee efficiency with custom AI agents.

Trusted by thousands of organizations worldwide

Related posts

2 Comments


Avatar photo
Nic Gedde
July 16, 2024 at 7:39 am
Reply

How can u upload a file using API?


    Avatar photo
    Alden Do Rosario
    July 19, 2024 at 5:49 pm
    Reply

    We have some examples in the cookbook — do take a look at our new enhanced information page: https://customgpt.ai/api (PS: We also just sent a newsletter about our new API — it has a “Book a call” link in case you need help)

Leave a reply

Your email address will not be published. Required fields are marked *

*

3x productivity.
Cut costs in half.

Launch a custom AI agent in minutes.

Instantly access all your data.
Automate customer service.
Streamline employee training.
Accelerate research.
Gain customer insights.

Try 100% free. Cancel anytime.