自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

天啊,ChatGPT真的要代替我們工作了嗎?

人工智能
利用ChatGPT這樣的AI可以生成一些代碼,如上面的例子所示,但是面對(duì)一些復(fù)雜的業(yè)務(wù)還是做不到的。我們可以借助這樣的工具,幫助我們提高工作上的效率,但是也不用擔(dān)心他們會(huì)取代我們。

?前言

最近這段ChatGPT?真的非?;?,和ChatGPT?相關(guān)的AI 服務(wù)也是各種如火如荼的研究中。今天我們來(lái)看下ChatGPT?在編碼方面的應(yīng)用,最近發(fā)現(xiàn)一個(gè)叫做“AI Coding Assistant?” 的IntelliJ IDEA?插件,它就是集合了ChatGPT的技術(shù),我們來(lái)看看有多么的智能,是否以后真的有可能會(huì)代替我們程序員的工作。

插件安裝

為了開(kāi)始使用該插件,必須要有一個(gè) OpenAI? 的令牌。如果你不知道在哪里可以找到它,可以在https://platform.openai.com/account/api-keys這里獲取,關(guān)于如何注冊(cè)。百度谷歌教程一大堆。

此外,下載并安裝IntelliJ IDEA的AI Coding Assistant”插件:

圖片

圖一——IntelliJ IDEA 設(shè)置中的 “AI Coding Assistant”插件

嘗試一下

  1. 生成打印hello world的代碼?

第一個(gè)任務(wù)先來(lái)個(gè)簡(jiǎn)單的,就是讓它自動(dòng)生成打印hello world的代碼。

圖片

  1. 生成一個(gè)pojo

現(xiàn)在你給我生成一個(gè)Person類(lèi)。

圖片

  1. 現(xiàn)在給我創(chuàng)建一個(gè)函數(shù)來(lái)返回生成的人員列表?

圖片

  1. 有了person數(shù)據(jù)以后,我們可以實(shí)現(xiàn)一些簡(jiǎn)單的算法,比如找到列表中最年長(zhǎng)的人,列表中人的最小/最大/平均年齡?

圖片

  1. 其中有趣的部分是我們可以要求更新現(xiàn)有代碼。因?yàn)槲抑朗褂?Java Stream API 編寫(xiě)相同算法的更好方法,所以讓我們嘗試讓它進(jìn)行重構(gòu)

圖片

  1. 我們可以創(chuàng)建一個(gè)函數(shù)并要求它根據(jù)函數(shù)名的意思生成代碼。?

圖片

  1. 然后你在給我把javadoc也補(bǔ)充了把

圖片

  1. 那你還能給我的代碼添加注釋嗎,解釋下這段代碼是干嘛的嗎??

圖片

  1. 最后我們來(lái)看看通過(guò)這個(gè)AI插件生成的最終的代碼長(zhǎng)啥樣??
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;
}
}

結(jié)論

利用ChatGPT這樣的AI可以生成一些代碼,如上面的例子所示,但是面對(duì)一些復(fù)雜的業(yè)務(wù)還是做不到的。我們可以借助這樣的工具,幫助我們提高工作上的效率,但是也不用擔(dān)心他們會(huì)取代我們。

責(zé)任編輯:武曉燕 來(lái)源: JAVA旭陽(yáng)
相關(guān)推薦

2021-01-29 17:07:26

排序算法數(shù)組

2022-12-08 20:16:43

2021-10-20 06:58:11

SQL數(shù)據(jù)庫(kù)程序員

2010-01-14 17:52:02

2023-02-27 08:25:46

ChatGPTJDGoogle

2021-08-18 15:23:42

SDNSD-WAN軟件定義網(wǎng)絡(luò)

2021-05-18 08:42:23

谷歌SoC主板

2010-03-03 09:09:53

Android SDK

2019-01-07 16:35:58

微軟開(kāi)源Java

2013-07-15 16:55:45

2021-09-06 15:46:08

996職場(chǎng)數(shù)據(jù)

2023-07-04 10:18:25

開(kāi)源模型

2020-01-15 10:17:41

Kubernetes容器負(fù)載均衡

2023-03-01 09:39:05

2017-03-03 09:55:25

2012-01-12 12:53:25

2023-05-24 10:04:48

2023-07-26 13:11:21

ChatGPT平臺(tái)工具

2021-04-13 15:56:24

JavaPython技術(shù)

2018-01-14 16:21:57

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)