CustomGPT.ai Blog

Developer’s Toolkit: Custom GPT RAG API Test Harness for Ensuring Endpoint Availability

Developer’s Toolkit Custom GPT RAG API Test Harness for Ensuring Endpoint Availability

In this blog post, we will explore using automated test scripts for testing access to RAG API endpoints related to projects, conversations, and message sending. By running these tests, developers can ensure that the RAG API functions as expected and can identify any issues or errors in the API responses. 

The primary purpose of this testing script is to validate the core functionalities of the CustomGPT.ai platform, ensuring that each endpoint behaves correctly and consistently. 

Automated testing not only saves time but also enhances the reliability of the RAG API, allowing developers to focus on building more advanced features with confidence. Let’s dive into how this script works and how it can be utilized to streamline your development workflow.

Purpose of the Testing Script

The primary purpose of this testing script is to automate the verification of various RAG API endpoints for the CustomGPT.ai platform. This ensures that the RAG API functions correctly and meets the expected standards. 

Here are the specific purposes and benefits:

Automated Testing

The script automates testing the RAG API endpoints, reducing the need for manual testing and minimizing human error.

Validation of RAG API Endpoints

It validates the GET and POST endpoints for projects, conversations, and sending messages to ensure they return the correct status codes and response data.

Consistency and Reliability

By running these tests, developers can ensure that the RAG API consistently behaves as expected, providing reliable performance across different use cases.

Early Detection of Issues

Automated tests help in identifying issues or bugs early in the development process, allowing developers to fix them before they impact end-users.

Continuous Integration

It can be integrated into continuous integration (CI) pipelines, ensuring that the RAG API is tested automatically with every code change or deployment.

Quality Assurance

Ensuring that the RAG API endpoints meet the defined specifications and perform correctly is crucial for maintaining high-quality software.

By using this script, developers and QA teams can streamline the testing process, improve the RAG API’s reliability, and ensure a seamless experience for users interacting with the CustomGPT.ai platform.

Automating RAG API Endpoint Testing with CustomGPT.ai: A Comprehensive Guide on its Functionality

The script is a set of automated tests written in Python using the pytest framework to test various endpoints of the CustomGPT.ai RAG API. It includes tests for GET and POST endpoints related to projects, conversations, and sending messages.

The functionality of each test is as follows:

Importing Required Libraries

Imports the pytest framework for writing and running test cases. Then Imports the requests library to handle HTTP requests and responses for interacting with the CustomGPT.ai RAG API.

AD 4nXcIHUa9hNSwa7KsOzloNzFw02naOCGs4UqcpvaDEi3jLl0xCG6tj91V7gmT5ueTcrWDwKjULRi0675ALD7GvIEyQE13ULvuOthA 069E2tRWD5VKawLoZQT QLuG7YfThzrVXeYaq8iomAWMhQlF0SaC6I?key=TMtsIlFCXxyAxA44FRN PA

Setting Up RAG API Constants

The script sets up key constants needed for interacting with the CustomGPT.ai RAG API. BASE_URL defines the root endpoint for project-related RAG API calls, while RAG_API_TOKEN is a placeholder for the user’s RAG API token needed for authorization. project and session are placeholders for the project ID and session ID, which will be used in subsequent RAG API requests to target specific projects and conversations.

AD 4nXcwWmqzfgnTtt1hMa6lRDnRrlP5cvbm2eoHimcGAzLp917Q4DcschLcGOy6X3Vkq Ojozz4P1hZQtSzFFfCXm1amsmFm6jWqvk9LGXDPdT17L2aMv8E783yCwAw2ZfFrnchor5T9ncAWLNi7w4OaWvkz 3v?key=TMtsIlFCXxyAxA44FRN PA

Configuring Request Headers

The script defines a headers template for making RAG API requests to the CustomGPT.ai endpoint. This includes the Authorization header, which uses the RAG API token for authentication, and headers for Accept and Content-Type set to application/json to specify that the RAG API requests and responses will be in JSON format.

AD 4nXd ZoKJb8WasOSniG5Y nIPT z1ztt CWqCzmvZjnHVfdWyKY6QWw1iMhvTyaZ6P yAjFXtcunaasXjMaOwh9Wrad488pBsJ3IiScDXqN8ykgz 20IWz2YVOH3WQW8YjVmOxao5MMfOvhoHinEPuE90V Q?key=TMtsIlFCXxyAxA44FRN PA

Testing GET Endpoint

This function test_get_project_details() tests the GET endpoint for retrieving project details from the CustomGPT.ai RAG API. It sends a request to the specified project URL, verifies if the response status code is 200, checks if the response contains the ‘data’ key, and ensures that the RAG API call is successful.

AD 4nXdMZGXJhkqAvFkHfb7XCieQX0KXLx YAwTobbOtjVaZzFiTcRPpxeq bJzWvFQJcxT0fTWgnawp7fZATzH115BtqltY2Gk 92TYf99KOqYDzJEDEKcM1mEjjb7xl1xLDayN3VewGldrWbNqGcO4AVfJ36i1?key=TMtsIlFCXxyAxA44FRN PA

Testing POST Endpoint for Conversation Creation

In the function test_create_conversation(), a POST request is sent to the CustomGPT.ai RAG API endpoint to create a conversation with a specified name. It verifies if the response status code is 201, indicating a successful creation, and checks if the response contains the ‘id’ of the created conversation.

AD 4nXfVNVKzs4PnvSvJhlDydaj3FWCEzK0UnjaIpd4pL DCXLJXdq8qDQVpumgAiB0QbCOe 8T7F1WAX R hM4jGNkYSfhqjPRQcvVGprEAasTydEXz3926N BXCCOOcdUozBpVTCE7svbqYUInSPdB5lg7qi5C?key=TMtsIlFCXxyAxA44FRN PA

Testing POST Endpoint for Sending Messages

In the test_send_message() function, a POST request is made to the CustomGPT.ai RAG API endpoint to send a message within a conversation session. It verifies if the response status code is 200 if the response contains the ‘data’ key, if the ‘id’ is present in the response data, and if the RAG API call succeeds.

AD 4nXf9A9Qngz FEqXYVYTDoKj6779vQbLsVR fvM3UGN9kSclRDu5R9T1u2SzTaiBwe1W FFtLP2ukR6kn Enhs92MdKr5Hsja1StBK65VF59ie fBseBLGAeRQLlAQK2foruzEQkgYkQRSWzpYh4KCV o I26?key=TMtsIlFCXxyAxA44FRN PA

Running the Tests

The conditional statement if __name__ == “__main__”: ensures that the tests are run when the script is executed directly. The pytestmain() function is called to execute all the test functions defined in the script using the pytest framework. This allows developers to conveniently run the tests and verify the functionality of the CustomGPT.ai RAG API endpoints.

AD 4nXceuBYC64b418mdJseh TkoXjRzzy8hCKrgM3uQG Fjhm7vuiPNvE3VAB9PSFEacEWjHM7p9WKVFJ87GryF4G65VTJFjEolLYIL37gSIzlldYWJLsgG0I6SaS34PFlYLXqIe5rCWoPx4NG27d0TtioOl6qL?key=TMtsIlFCXxyAxA44FRN PA

Run and Test the Script

To run the test_endpoints script, follow these steps:

  • Download the file from the CustomGPT.ai cookbook.
AD 4nXfmy6YTEeam9zF zM0De4sD3QSBoqPvpowgGL dhfoH0 EooMw6Ne80zmsZ0AH4t01r IiuYp2bxbGaIDXPKk6 YSxwaSgZCh2ToOGkGVihCwaErfH7tRJluelYA2HMdbc7MTUwMQuBLA6Z6n5JpOZFoZ?key=TMtsIlFCXxyAxA44FRN PA
  • Open the downloaded Python file and replace the following parameters with the actual RAG API key, Project ID, and session ID. You can find these values from your CustomGPT.ai Project.
AD 4nXfAjpqhYPXEyRjrsZ4MDNrYICytrP FDm8TF b51g4OwRH46EfO9OI6YJGw1jz31M wawi9 lNvcftgXKxkuWKyoIfvUkzfOdiS YbB3CKTjUsKwe66vx7xXBljc5tjgZzOVVuu1HowqP9TUuW9Mzikm74o?key=TMtsIlFCXxyAxA44FRN PA
  • Open your command line interface (CLI).
  • Navigate to the directory where the test_endpoints.py script is located using the ‘cd’ command.
  • Once in the correct directory, execute the script by typing ‘python test_endpoints.py’ and pressing Enter.
AD 4nXc43Q2xX9Zvgsjye0rGSpFRDUDXAhPaxZR9fGgWtNnFfnBd5PP97D5EQG07A1qbFkocaZIHQFVDELxLmoTiEYxwpzJC5PGcijOGdvUekcWK6tbRLZRAH9K9zzp8vhvT6YdarxZrrDcO 2PcxXjZhrMbos4?key=TMtsIlFCXxyAxA44FRN PA
  • The script will start running the defined tests for the CustomGPT.ai RAG API endpoints.
  • After the script execution completes, review the output in the CLI to see the results of each test.
AD 4nXdjKwcq5wqIxeAh3MqJ9u8fz7AJWAVvI4rmWiB69vkETsL5mxVrCBxvnDCsHO CmF4y UiS QMI7yHf7P6AfIE3L5WK94 ecchvOdxxuucNymG8xwp pKHMNDx8HiGr5aW87nzXcGKIjngdCsFDk4u0VwN?key=TMtsIlFCXxyAxA44FRN PA
  • If any tests fail, carefully examine the error messages provided to identify the issues encountered.
  • Make any necessary adjustments to the script or the RAG API configuration to address any failures.

Once the issues are resolved, rerun the script to verify that all tests pass successfully.

In summary, running the test_endpoints script involves navigating to the script’s directory in the command line and executing it using Python. After execution, review the test results to ensure the proper functioning of the CustomGPT.ai RAG API endpoints.

Conclusion

In conclusion, this post has provided an overview of the test_endpoints script, which serves as a valuable tool for automating the testing process of CustomGPT.ai RAG API endpoints. By running these tests, developers can ensure the reliability and functionality of their RAG API integrations, identifying and addressing any issues efficiently. Through comprehensive testing, developers can enhance the performance and usability of their chatbot applications, ultimately delivering a more seamless user experience. 
To elevate your chatbot’s performance and streamline your development process, sign up for CustomGPT.ai today.

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.