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.
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:
Figure 1 - "AI Coding Assistant" plug-in in IntelliJ IDEA settings
The first task is a simple one, which is to let it automatically generate and print hello world code.
Now you generate a Person class for me.
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; } }
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!