Can Generative AI Teach me Technical Concepts?

I’ve been looking at using ChatGPT to experiment and see whether it can support my testing in a meaningful way. Previously I’ve looked at whether it can write a test approach and write exploratory test ideas to mixed success; but can it help me learn technical concepts?

In this experiment I’ll ask Generative AI to explain some well known concepts in technology. My aim is to see if it can take what’s online and give it to me in an easy to understand way. As before, I’m somewhat of a beginner in forming queries to ChatGPT so my results may be impacted by limitations in my ability to ask it things.

Fig 1. HAL – The AI in 2001: A Space Odyssey

Let’s ask about APIs

Experiment 1: Ask ChatGPT to explain what an API is using a basic request “Explain what an API is.

Vid 1. ChatGPT explaining what an API is

Here’s a cut down section of the response ChatGPT provided, showing what I considered to be the salient points for an overall description.

Think of an API as a messenger or intermediary that enables different applications to talk to each other and share data or functionality. It acts as a contract or interface between software components, specifying how they can interact and what operations can be performed.

APIs can support various types of interactions. They may allow applications to retrieve data from a server, submit data for processing, perform actions on remote systems, or even control hardware devices. The communication between applications typically occurs over the internet using standard protocols such as HTTP (Hypertext Transfer Protocol).

In summary, an API acts as a bridge between different software applications, allowing them to communicate and exchange data or functionality. It plays a crucial role in enabling integration, interoperability, and building complex software systems by leveraging the capabilities of external services or platforms.

The salient points I’ve cut out made up about 50% of the response, the other 50% goes into more detail and is also pretty useful (talking about architecture and HTTP methods).

Okay so, ChatGPT was able to return a response that provides a good baseline understanding of what an API is conceptually. It also tells us a bit about what they do, they retrieve and submit data, perform actions and control devices. Perhaps with a more tailored question perhaps we can find out more about those actions.

Experiment 2: Follow up what ChatGPT told us about APIs to find up more using a basic request “Explain what interactions an API can make.

Vid 2. ChatGPT explaining what an API can do

This response gives a list of the requests that a REST API can make with a pretty good explanation of each. Here’s a snippet of the first few:

GET: This interaction is used to retrieve data or resources from a server or API endpoint. For example, a weather API may provide a GET method to retrieve the current weather conditions based on a specific location.

POST: This interaction is used to send data or create new resources on a server or API endpoint. For example, a social media API may provide a POST method to allow users to create new posts or submit comments.

PUT: This interaction is used to update existing resources on a server or API endpoint. For example, an e-commerce API may provide a PUT method to allow users to update their shipping address or modify the contents of a shopping cart.

DELETE: This interaction is used to delete resources from a server or API endpoint. For example, a file storage API may provide a DELETE method to allow users to remove files or folders.

Personally, I think these are good explanations and give me more understanding of what I can do with an API. That examples have been given are good because it gives more understandability and flavour to the explanation.

When I asked ChatGPT to regenerate the response it gave a similar but different set of information that was more theoretical, rather than the list of actions.

Retrieving data: APIs allow applications to fetch information from a remote server or database. For example, a weather API can provide current weather conditions based on a location, and a social media API can retrieve posts or user profiles.

Sending data: APIs also enable applications to send data to another system. This can involve submitting data for processing or creating new entries in a remote system. For instance, a payment API can be used to send transaction details to a payment gateway for processing.

Updating data: APIs often provide methods for modifying existing data. This can involve editing or deleting specific records. For example, an e-commerce API may allow updating the quantity or removing items from a shopping cart.

I think that both of these responses would be useful in building my understanding and in potentially helping me to work out what risks could be inherent in an API.

But to be sure, let’s ask another question and chase what we can learn about further, how can we send data via an API?

Experiment 3: Ask a specific question to ChatGPT to find out specific information about an API request using a basic request “Explain how to send data to an API using POST.

Vid 3. ChatGPT telling me how to make an API POST request

In this response we got a set of instructions that comes with loads of examples and information. This might be a little dense for if I were new to an API, but it’s totally understandable.

Determine the API endpoint: Find out the URL where the API is located and the specific endpoint that accepts POST requests. The API documentation or the service provider should provide this information.

Format the data: Prepare the data you want to send in the appropriate format. Most commonly, data is formatted as JSON (JavaScript Object Notation) or form data.

For JSON data, create a JSON object with the required key-value pairs. For example:

{
  "key1": "value1",
  "key2": "value2"
}

Set up the request: Use a programming language or a tool of your choice to set up an HTTP request to the API endpoint. You can use libraries like requests in Python, fetch in JavaScript, or tools like cURL or Postman.

These steps are a bit generic, but I like that it’s giving me more to look at (suggesting I use a tool like Postman) as I can then ask about these things. One thing that I don’t like about this response, is that it gives me examples in JSON, JavaScript and Python for different steps rather than being consistent.

When I regenerated the response to the question I got a very similar response just without the example payloads. maybe this means there’s not a lot of content about this online, or I need to refine the question some more.

Determine the API endpoint: Identify the URL where the API is located, including the specific endpoint you want to send the data to.

Understand the data format: Determine the data format expected by the API, such as JSON, XML, or form data. This information is usually provided in the API documentation.

Prepare the request headers: Set the necessary headers in your HTTP request. At minimum, you typically need to include the "Content-Type" header to specify the format of the data you're sending.

Experiment 4: Refine the question asked to ChatGPT to find out specific information about an API request using a basic request “Explain how to send data to an API using POST in the Postman tool.

Vid 4. ChatGPT telling me how to make an API POST request using Postman

This request gives me more specific steps (kind of like test steps) as I’ve now specified a specific tool. This would be an awesome way to start understanding the use of a tool and getting started.

Open the Postman tool on your computer. If you don't have it installed, you can download it from the Postman website (https://www.postman.com/) and install it.

Create a new request by clicking on the "New" button located at the top left corner of the Postman window. This will open a new tab for your request.

In the new tab, select the HTTP method as "POST" by clicking on the dropdown menu next to the request URL field and choosing "POST."

Enter the URL of the API endpoint you want to send the data to in the request URL field. Make sure you include the full URL, including the protocol (e.g., https://api.example.com/endpoint).

Switch to the "Body" tab below the request URL field. Here you can specify the data you want to send to the API in the request body.

This set of instructions didn’t provide me with an example payload, unlike the previous request, which i found useful. Let’s ask for some examples by modifying the query.

Experiment 4b: Refine the question asked to ChatGPT to find out specific information about an API request using a basic request “Explain how to send data to an API using POST in the Postman tool. Include an example payload.

Vid 5. ChatGPT telling me how to make an API POST request using Postman (including an example payload).

Okay now we’re cooking with gas! This has given me pretty much the same as the last response with steps to follow, but also includes a JSON payload example to give me context of what I should be doing.

In the "Body" section, select the format for the request payload. Common options are "form-data", "x-www-form-urlencoded", or "raw" (e.g., JSON).

If you choose "raw", select the appropriate format from the dropdown (e.g., JSON, XML, Text). Then, enter the payload in the editor below. Ensure the payload is valid according to the selected format.

Here's an example of a JSON payload:
{
  "name": "John Doe",
  "email": "johndoe@example.com",
  "age": 30
}

Once you have entered the payload, click the "Send" button to send the POST request to the API.

With additional requests and refinements of the question I could likely get more information to solve problems I have as I try to use the API.

Conclusions and Thoughts

Generative AI seems to be a good way of getting information about things written in a clear, short form way that’s easy to digest. It’s like Googling to find the answer for something but potentially a bit more targeted with its response.

Note: I Googled “Explain how to send data to an API using POST in the Postman tool.” and the first response was also a pretty good tutorial that also included pictures (where ChatGPT did not).

Again, with other uses of Generative AI to do things, where one result is presented, it’s easy to get a false confidence of “oh this must be right” as we can’t see other sources. So whilst i think it’s useful and good, we should be cautious in how we treat these responses and treat them with healthy scepticism.

I only tried using this tool to learn about something basic (and at quite a basic level) so I’ll need to do some more experiments to see how it can teach me about complex technical things.

It looks like we can use Generative AI to get answers to some questions, or to teach us about basic things. What have your experiences in this realm been? Have you tried to use it to explain something more complex?

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.