CitrusLeaf Tech

OpenAI and ChatGPT from a Node Developer's Perspective

OpenAI and ChatGPT from a Node Developer’s Perspective

OpenAI and ChatGPT are trending everywhere. From HR managers to Software engineers, everyone’s talking about them. Looks like The Age of Information has finally matured and we have Artificial Intelligence being used practically. It’s not limited to scientific research anymore. It has come out of its shell to be commercially viable and help people with more practical problems.

AI has been in use in multiple fields like legal, medical and services. It can now be used to write software thanks to OpenAI!

OpenAI is an artificial intelligence research laboratory consisting of the for-profit corporation OpenAI LP and its parent company, the non-profit OpenAI Inc. With AI models trained using petabytes of data over many years, OpenAI is leading the artificial intelligence race at the moment.

ChatGPT: A Dialog Interface to AI

ChatGPT was released for public beta on Nov 30, 2022. Since then, it has swept almost everyone’s attention on the Internet. ChatGPT provides a chat-like dialog based interface in which humans can interact with AI in a more natural way. You do not have to setup your own AI models anymore.

Prior to ChatGPT, one had to either use OpenAI’s APIs and integrate them into some GUI. With ChatGPT, it has become much easier to get answers from AI. You can now ask AI to write articles, generate code, generate images from text, understand sentiments and what not.

We believe that ChatGPT is a turning point in human history, similar to the introduction of the iPhone which ushered a new era of mobile computing.

Exploring ChatGPT as a NodeJS Developer

Since our remote developers already use AI for generating boilerplate code and once we saw what ChatGPT could do, it was natural for us to try it out. We wanted to see how fast and accurate it is, when it comes to generating code. We tried ChatGPT with different questions of varying difficulty. 

Here are some of the questions that we asked-

Question 1: How to get date difference in JavaScript?

Answer:

As you can see, the answer was correct and so was the explanation. But this was a very simple question. Let’s try another, tougher question.

Q2. How to modify DOM elements using Cypress?

Answer:

While we were expecting an answer, we were not expecting 4 different examples! Looks like it’ll not only give you the required answer, OpenAI’s ChatGPT will also give you a full explanation with multiple examples. Interesting!

Let’s now see how well it generates code for 3rd party API integration in NodeJS. We recently integrated DocuSign in one of our NodeJS projects. Let’s see how ChatGPT will do the same task.

Q3: How to integrate DocuSign in NodeJS?

Answer:

const request = require('request');

// Set the API endpoint and authentication details
const API_ENDPOINT = 'https://demo.docusign.net/restapi';
const USERNAME = 'your_username';
const PASSWORD = 'your_password';
const INTEGRATOR_KEY = 'your_integrator_key';

// Set the request body
const body = {
  emailSubject: 'Please sign this document',
  documents: [{
	documentBase64: 'BASE64_ENCODED_FILE_CONTENT',
	name: 'document.pdf',
	fileExtension: 'pdf'
  }],
  recipients: {
	signers: [{
  	email: '[email protected]',
  	name: 'Signer Name',
  	recipientId: '1'
	}]
  },
  status: 'sent'
};

// Set the request options
const options = {
  url: `${API_ENDPOINT}/v2/accounts/account_id/envelopes`,
  body: JSON.stringify(body),
  auth: {
	user: USERNAME,
	pass: PASSWORD
  },
  headers: {
	'X-DocuSign-Authentication': JSON.stringify({
  	Username: USERNAME,
  	Password: PASSWORD,
  	IntegratorKey: INTEGRATOR_KEY
	}),
	'Content-Type': 'application/json'
  }
};

// Send the request
request.post(options, (err, res, body) => {
  if (err) {
	// Handle error
	console.error(err);
  } else {
	// Parse the response body
	const response = JSON.parse(body);
	console.log(response);
  }
});

This is mind blowing! It generated the complete integration code right from authentication to envelope generation in DocuSign!

Just to be clear, we used JavaScript here because it’s a universal language. Maybe that’s why OpenAI was so quick and accurate in answering our questions. It looks like it has been trained for some popular programming languages more than others.

AI assisted software development is here

As we mentioned earlier, AI is now commercially viable. Looking at how quick ChatGPT can answer and with good accuracy, the road ahead is very clear. Developers finally have a friend who can write boilerplate code for them. As with every technology, AI will also mature over time and become more accurate.

ChatGPT can already refactor and rewrite code in multiple languages. Software developers will be able to use it to write better, more secure code in less time. This means that businesses will not have to wait for longer times between feature releases.

More accuracy is required

Not everyone is happy with ChatGPT though. Stackoverflow has already banned generated code from ChatGPT citing accuracy issues. They believe that the average rate of getting correct answers is very low and the code is not as secure as it should be. 

We tried asking a few more difficult questions like fixing a piece of code for SQL vulnerability, it couldn’t refactor it. Sometimes, it gave us non-working code examples (how to integrate REST APIs in Flutter?).

A few users have even tricked it to reveal its own source code!

Closing Notes

As remote NodeJS developers, we couldn’t be more happy to have an AI assistant which can write boilerplate and repetitive code for us. We think we can now focus more on business logic and writing better test cases around them. In fact, we have already started using it. Of course, we check all the generated code meticulously for security and performance issues. So far, we are satisfied with the results, at least for regular development work. For anything more complex, our dedicated NodeJS developers gets their hands dirty and tackle the complexities easily.

We can already see that there’s a lot of scope for improvement in ChatGPT and OpenAI is putting a lot of effort into it. Hopefully, we should get a better version of it soon.

If you are looking to Hire NodeJS Developers, look no further than CitrusLeaf. We use Artificial Intelligence for faster development and deliver you apps at light speed.