DEV Community

Navneet Karnani
Navneet Karnani

Posted on • Originally published at blog.mandraketech.in on

[HttpServer series] The fight of the GenAI tools - ChatGPT, Bard, CodyAI?

Now that the Dev Environment is ready, lets get started.

In the world of ChatGPT and Bard, I do not want to start from scratch. So, I will ask both of them:

I want to write a Java application which uses the HttpServer that ships as part of the JRE to build a web server that serves an endpoint called "/health". This endpoint should return the Memory and CPU usage of the java process that is running. Do feel free to use the JMX route to fetch the required information, since my application will always be running inside a docker container.

The response from Bard was really good here. It talked about the Docker file build instructions, and all the references. This is, in my opinion, very valuable. As a programmer, there is always the angle of copyright, and Intellectual Property that we should be worried about. It used JMX Service connector to fetch an MBeamServerConnection, and then fetch the health information from there.

The response from ChatGPT, apart from not quoting the sources, was more "complete". It had error handling, and also better function formation as part of the code structuring. This implementation used the ManagementFactory directly to fetch the required information. It did not give me instructions for building the Docker image, but then, I had not asked for it either. There as an assumption in the question above that my application is already running in a container.

Based on the responses to this, I realised that I missed some aspects in the prompt. So, I changed it to:

I am writing an application that will run with Java 21. I want to use the HttpServer that ships as part of the JRE to build a web server that serves an endpoint called "/health". This endpoint should return the Memory and CPU usage of the java process that is running. My application will always be running inside a docker container. If you can provide me with a Dockerfile based build environment too, that will help. I use maven, and pom.xml to do my build.

The responses changed a bit with this change. But first, let me set the expectations. ChatGPT 3.5 ( the free version ) does not have Java 21 information. But Bard claims to have it. So, I expect both of them to honour that appropriately.

This time, Bard just could not keep pace with the prompts. I asked it to start afresh, but it just went off in a completely different track. So, I have to say that ChatGPT is the better of the two, in this case.

I also have access to Cody AI from Sourcegraph, and its Pro version is free until February 2024. So, I asked this question to Cody too. Given its integration with VS Code, and the API limits on usage, I am going to use a combination of Cody AI and ChatGPT to achieve the goal.

So, we will use that as our guide in this exercise. Next, we start writing code.

Top comments (0)