当前位置:首页 >> 内饰

程序员可以放心了,ChatGPT只能写就95%的代码!

来源:内饰   2024年01月26日 12:17

.lowerBound ) * bracket.rate; break; } else { tax += (bracket.upperBound - bracket.lowerBound ) * bracket.rate; } } return tax; }}public class Main { public static void main(String[] args) { List taxBrackets = new ArrayList<>(Arrays.asList( new TaxBracket(1, 0, 15000, 0.05), new TaxBracket(2, 15001, 45000, 0.10), new TaxBracket(3, 45001, 120000, 0.20), new TaxBracket(4, 120001, 200000, 0.30), new TaxBracket(5, 200001, Integer.MAX_VALUE, 0.40) )); List deductions = new ArrayList<>(Arrays.asList( new Deduction("Standard", 5000), new Deduction("Health_Insurance", 2000), new Deduction("Retirement_Sings", 3000) )); int income = 80000; TaxCalculator calculator = new TaxCalculator(income, taxBrackets, deductions); double tax = calculator.calculateTax(); System.out.println("应纳税略: " + tax); }}

这个意味着概念了TaxBracket和Deduction类,并创建者了一个TaxCalculator类来量化应纳税略。主步骤当中初始化了增值税线路和抵免略,并可用这些接收者量化了一个给定总收入的应纳税略。

注解:它似乎理解了这个DSL是用来量化增值税的,类名,步骤名也比较前提

利耶尔:不不不,确实二阶一个DSLPDF,形成TaxBracket和Deduction,然后再量化增值税,你这里不及了一个二阶器

GPT-4 :坦言,我明白你的消费了。这里是一个可用Ja汇编的二阶器,运用于二阶DSLPDF并量化增值税:

首先,我们所需创建者一个原称DSLParser的类来二阶DSLPDF:

import ja.io.BufferedReader;import ja.io.FileReader;import ja.io.IOException;import ja.util.ArrayList;import ja.util.List;class DSLParser { private final List taxBrackets = new ArrayList<>(); private final List deductions = new ArrayList<>(); private int income; public DSLParser(String filePath) { try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { String line; while ((line = reader.readLine()) != null) { parseLine(line.trim()); } } catch (IOException e) { System.err.println("Error reading file: " + e.getMessage()); } } private void parseLine(String line) { if (line.startsWith("tax_bracket")) { int id = Integer.parseInt(line.split(" ")[1]); int lowerBound = 0; int upperBound = 0; double rate = 0; for (int i = 0; i < 2; i++) { line = getNextLine(); if (line.startsWith("range:")) { String[] range = line.substring(6).trim().split(" - "); lowerBound = Integer.parseInt(range[0]); if (range[1].equals("and above")) { upperBound = Integer.MAX_VALUE; } else { upperBound = Integer.parseInt(range[1]); } } else if (line.startsWith("rate:")) { rate = Double.parseDouble(line.substring(5).trim().replace("%", "")) / 100; } } taxBrackets.add(new TaxBracket(id, lowerBound, upperBound, rate)); } else if (line.startsWith("deduction")) { String name = line.split(" ")[1]; int amount = 0; line = getNextLine(); if (line.startsWith("amount:")) { amount = Integer.parseInt(line.substring(7).trim()); } deductions.add(new Deduction(name, amount)); } else if (line.startsWith("income:")) { income = Integer.parseInt(line.substring(7).trim()); } else if (line.equals("calculate_tax")) { // Do nothing, just a marker to calculate tax } } private String getNextLine() { // Read the next line from the file, or return null if end of file is reached } public List getTaxBrackets() { return taxBrackets; } public List getDeductions() { return deductions; } public int getIncome() { return income; }}

接下来,我们所需更改Main类,以便从DSLPDF复制到税收接收者并量化增值税:

public class Main { public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: ja Main "); return; } DSLParser parser = new DSLParser(args[0]); List taxBrackets = parser.getTaxBrackets(); List deductions = parser.getDeductions(); int income = parser.getIncome(); TaxCalculator calculator = new TaxCalculator(income, taxBrackets, deductions); double tax = calculator.calculateTax(); System.out.println("应纳

注解:这里没负载完,就切掉了。

利耶尔:暂时

GPT-4 :

税略: " + tax);}}

现在,这个意味着仍未还包括了二阶DSLPDF的功能。你可以将上述表达式保存为Ja源PDF(例如`TaxCalculation.ja`),并将你的DSLPDF保存为一个文字PDF(例如`tax.dsl`)。然后可用一般而言命令服务器端代码并运讫表达式:

jac TaxCalculation.jaja Main tax.dsl

这将从tax.dslPDF复制到增值税线路和抵免略接收者,并根据总收入量化增值税。比如说,在可用此步骤此前,你可能所需稍微微调DSLParser类当中的getNextLine步骤,以便准确复制到PDF的下一路上。你可以可用BufferedReader并不一定的readLine步骤意味着这一点。

利耶尔: DSLParser当中getNextLine步骤不能意味着!

GPT-4 :坦言,这是我的疏忽。请在DSLParser类当中填充一个BufferedReader类别的团体参数reader,并在操作符当中初始化它。然后在getNextLine步骤当中意味着复制到下一路上的逻辑。一般而言是更改后的DSLParser类:

class DSLParser { private final List taxBrackets = new ArrayList<>(); private final List deductions = new ArrayList<>(); private int income; private BufferedReader reader; public DSLParser(String filePath) { try { this.reader = new BufferedReader(new FileReader(filePath)); String line; while ((line = reader.readLine()) != null) { parseLine(line.trim()); } reader.close(); } catch (IOException e) { System.err.println("Error reading file: " + e.getMessage()); } } private void parseLine(String line) { // ... (same as before) } private String getNextLine() { try { return reader.readLine(); } catch (IOException e) { System.err.println("Error reading next line: " + e.getMessage()); return null; } } // ... (getTaxBrackets, getDeductions, and getIncome methods)}

现在,DSLParser类已相关联一个reader团体参数,运用于在getNextLine步骤当中复制到PDF的下一路上。这确实使二阶器尽可能准确二阶DSLPDF并量化增值税。

注解:到目前为止,GPT-4把所有的表达式都作运用于了,用时不到5分钟!可以究竟是飞速了,让我开发小组意念,然后一路上讫小熊表达式,恐怕得四五十分钟吧

我把它复制出来,在VS Code当中运讫,发现了一个难题,它不能处理方式文字前后的小写字母。

利耶尔:在parseLine步骤当中,你看得不能考虑PDF当中的一路上章节前后有小写字母的难题

GPT-4 :您是对的,我此前的意味着不能直接影响讫章节前后可能存在的小写字母。在二阶每一路上时,我们可以可用trim()步骤来去除前后的小写字母。一般而言是更改后的DSLParser类当中的parseLine步骤:

private void parseLine(String line) { line = line.trim(); if (line.startsWith("tax_bracket")) { // ... (same as before) } else if (line.startsWith("deduction")) { // ... (same as before) } else if (line.startsWith("income:")) { income = Integer.parseInt(line.substring(7).trim()); } else if (line.equals("calculate_tax")) { // Do nothing, just a marker to calculate tax }}

现在,我们在处理方式每一路上时都会去掉前后的小写字母,这样就可以更准确地二阶带有前后小写字母的讫章节。这将提高二阶器的健壮性,使其尽可能更佳地处理方式不同编解码器的DSLPDF。

注解:说是GPT-4只改了处表达式,其他地方还没改。于是我提议它:

利耶尔:能否在getNextLine步骤当中就要用trim呢?

GPT-4 : 当然可以。您可以在getNextLine步骤当中反之亦然对复制到到的讫章节进讫trim()操作。这样,在函数调用getNextLine步骤时,就可以确保返回的讫章节仍未去除了前后的小写字母。一般而言是更改后的getNextLine步骤:

private String getNextLine() { try { String line = reader.readLine(); if (line != null) { return line.trim(); } } catch (IOException e) { System.err.println("Error reading next line: " + e.getMessage()); } return null;}

在这个更改后的旧版当中,我们在getNextLine步骤实际上对复制到到的讫章节可用了trim()步骤。这意味着在二阶PDF时,无论是通过getNextLine步骤还是在parseLine步骤当中复制到的讫章节,都仍未去除了前后的小写字母。

注解:到目前为止,还一切顺利,但是很快就发生了一件让人头大的难题:GPT-4在处理方式range: 200001 and above 这样编解码器的时候分心,因为一般的编解码器是45001 - 120000, 120001 - 200000 ,都是数字,这里消失一个 and above 文字,它没注解意到。

服务器端在运讫时分心,我把准确反之亦然扔给它:

利耶尔:表达式在运讫时分心:

Exception in thread "main" ja.lang.NumberFormatException: For input string: "200001 and above"at ja.lang.NumberFormatException.forInputString(NumberFormatException.ja:65)at ja.lang.Integer.parseInt(Integer.ja:580)at ja.lang.Integer.parseInt(Integer.ja:615)at DSLParser.parseLine(App.ja:94)at DSLParser.(App.ja:73)at App.main(App.ja:150)

GPT- 4 :坦言给您产生了困扰。这个难题是由于在二阶tax_bracket线路的序数时不能全局方式"and above"的情形避免的。一般而言是复复后的parseLine步骤当中处理方式tax_bracket一小的表达式:表达式略。

注解:GPT-4虽然意识到了难题所在,但是它的更改方案总是有难题,间歇了两三次也复很好。最后我提示它:

利耶尔:在这个表达式当中 range: 200001 and above , 根据就不能“-”, 所以line.substring(6).trim().split(" - ") 这讫表达式是于是就的

GPT-4: 您是对的,我旋即犯了准确。为了处理方式"and above"这种情形,我们确实根据"and above"表达式来切分范围内。一般而言是复复后的parseLine步骤当中处理方式tax_bracket一小的表达式:

private void parseLine(String line) { if (line.startsWith("tax_bracket")) { int id = Integer.parseInt(line.split(" ")[1]); int lowerBound = 0; int upperBound = 0; double rate = 0; for (int i = 0; i < 2; i++) { line = getNextLine(); if (line.startsWith("range:")) { String rangeString = line.substring(6).trim(); if (rangeString.contains("and above")) { String[] range = rangeString.split(" and above"); lowerBound = Integer.parseInt(range[0]); upperBound = Integer.MAX_VALUE; } else { String[] range = rangeString.split(" - "); lowerBound = Integer.parseInt(range[0]); upperBound = Integer.parseInt(range[1]); } } else if (line.startsWith("rate:")) { rate = Double.parseDouble(line.substring(5).trim().replace("%", "")) / 100; } } taxBrackets.add(new TaxBracket(id, lowerBound, upperBound, rate)); } else if (line.startsWith("deduction")) { // ... (same as before) } else if (line.startsWith("income:")) { income = Integer.parseInt(line.substring(7).trim()); } else if (line.equals("calculate_tax")) { // Do nothing, just a marker to calculate tax }}

现在,在二阶增值税线路时,我们首先检查范围内表达式是否相关联"and above"。如果相关联,则根据"and above"切分范围内,并将序数新设为Integer.MAX_VALUE。否则,我们可用" - "分隔符来切分范围内。这次更改确实可以全局方式增值税线路,并避免NumberFormatException极其。

注解:这一次,它终于要用对了。

揭示一下:

ChatGPT实在是太牛了!

它不但可以理解消费,作运用于表达式,更让人难以置信的是可以根据要求急剧地微调表达式,完善功能,复复Bug。

更进一步几乎用自然口语交互,这种能力也我不能在此前的任何工具当中见到过,究竟它是新概念的关键技术几乎不为过。

但是,我们也见到了它忘记(?)意味着一个步骤,特别是一个Bug一直搞不定,直到我明确地说明来。

正如球友@楊_餐前所究竟:ChatGPT能以极快的平均速度作运用于95%的可运讫表达式,但是剩下的5%依然倚赖Python的绝技。

在ChatGPT的反弹下,Python的价值依然是很大的,依然是必备的的。

但是,会用熟练可用ChatGPT的Python,可以用自然口语快速作运用于表达式,效率提升十倍甚至百倍,这将对不可用ChatGPT的Python看成降维反击。

肠炎宁颗粒止泻效果怎么样
天津装修公司
急性肠炎吃肠炎宁好吗
先声必奇
金笛复方鱼腥草合剂是新冠用药吗
友情链接