Home > Technology peripherals > AI > body text

Oh my god, is ChatGPT really going to work for us?

PHPz
Release: 2023-04-13 08:19:02
forward
1258 people have browsed it

​Foreword

ChatGPT​ is really very popular recently, and AI services related to ChatGPT are also being researched in full swing. Today we take a look at the application of ChatGPT in coding. Recently we found an IntelliJ IDEA plug-in called "AI Coding Assistant", which integrates ChatGPT technology. Let's see how smart it is and whether it will really work in the future. It is possible that it will replace the work of our programmers.

Plug-in installation

In order to start using the plug-in, you must have an OpenAI token. If you don't know where to find it, you can get it here https://platform.openai.com/account/api-keys on how to register. Baidu and Google have a lot of tutorials.

In addition, download and install the "AI Coding Assistant" plug-in for IntelliJ IDEA:

Oh my god, is ChatGPT really going to work for us?

Figure 1 - "AI Coding Assistant" plug-in in IntelliJ IDEA settings

Try it

  1. Generate the code to print hello world

The first task is a simple one, which is to let it automatically generate and print hello world code.

Oh my god, is ChatGPT really going to work for us?

  1. Generate a pojo

Now you generate a Person class for me.

Oh my god, is ChatGPT really going to work for us?

  1. Now create a function for me to return the generated list of people

Oh my god, is ChatGPT really going to work for us?

  1. After having the person data , we can implement some simple algorithms, such as finding the oldest person in the list, the minimum/maximum/average age of the people in the list

Oh my god, is ChatGPT really going to work for us?

  1. The interesting part of this is that we can ask to update the existing code. Since I know a better way of writing the same algorithm using the Java Stream API, let's try to make it refactor

Oh my god, is ChatGPT really going to work for us?

  1. We can create a function and ask it to generate code based on the meaning of the function name.​

Oh my god, is ChatGPT really going to work for us?

  1. Then you I also added the javadoc

Oh my god, is ChatGPT really going to work for us?

  1. Can you also add comments to my code and explain what this code does? ?​

Oh my god, is ChatGPT really going to work for us?

  1. Finally, let’s take a look at what the final code generated by this AI plug-in looks like?​
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
final List<Person> people = generatePeople();
// find oldest person in the list
Person oldestPerson = people.stream()
.max(Comparator.comparing(Person::getAge))
.orElseThrow(NoSuchElementException::new);
System.out.println("Oldest person is: " + oldestPerson.getName());
// find max,min,avg age of the people
IntSummaryStatistics stats = people.stream()
.mapToInt(Person::getAge)
.summaryStatistics();
System.out.println("Max Age: " + stats.getMax());
System.out.println("Min Age: " + stats.getMin());
System.out.println("Avg Age: " + stats.getAverage());
}

public static List<Person> generatePeople() {
return Arrays.asList(
new Person("John", 25),
new Person("Jane", 30),
new Person("Jack", 20),
new Person("Jill", 35)
);
}

/**
* Capitalizes the first letter of a given string and lowercases the rest.
*
* @param s The string to capitalize
* @return The capitalized string
*/
public static String capitalize(String s) {
/*
This code checks if the length of the string "s" is 0. If it is, it returns the string.
If not, it returns the first character of the string in uppercase and the rest of the characters in lowercase.
*/
if (s.length() == 0)
return s;
return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
}
}

// class Person with name and age
class Person {
private String name;
private int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}
}
Copy after login

Conclusion

Using AI such as ChatGPT can generate some codes, as shown in the example above, but it is still impossible to face some complex businesses. We can use such tools to help us improve efficiency at work, but don’t worry that they will replace us.

The above is the detailed content of Oh my god, is ChatGPT really going to work for us?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template