以火攻火:我们能在多大程度上信任ChatGPT完成源代码相关任务?
Fight Fire with Fire: How Much Can We Trust ChatGPT on Source Code-Related Tasks?
AI总结:
针对ChatGPT在软件开发中应用时生成代码质量验证的问题,本文通过实证研究评估其在代码生成、补全和修复任务中的自我验证能力,发现其存在误判和幻觉等问题,且引导性问题可增强该能力,为相关研究提供启示。
摘要:
随着ChatGPT等大型语言模型在软件开发中应用日益广泛,验证其生成代码内容的质量变得至关重要。近期研究提出将ChatGPT同时作为开发者和测试者用于多智能体协作软件开发,这种多智能体协作使ChatGPT能为自身生成的代码产出测试报告,从而实现代码内容的自我验证并基于报告修复漏洞。然而,这些研究未评估生成的测试报告在代码验证中的有效性。因此,我们开展全面实证研究,评估ChatGPT在代码生成、代码补全和程序修复任务中的自我验证能力。我们要求ChatGPT完成三项任务:(1)生成正确代码并自我验证其正确性;(2)补全无漏洞代码并自我验证漏洞存在情况;(3)修复含漏洞代码并自我验证漏洞是否已解决。基于两个代码生成数据集、一个代码补全数据集和两个程序修复数据集的研究结果,我们得出以下发现:(1)ChatGPT常错误地将自身生成的错误代码预测为正确;(2)ChatGPT行为中出现自我矛盾的幻觉现象;(3)通过提出引导性问题(询问ChatGPT是否认同关于错误生成/修复的代码及补全代码中漏洞的断言),可增强其自我验证能力;(4)使用ChatGPT生成的测试报告能识别补全代码中更多漏洞,但报告中对错误生成代码和修复失败的解释大多不准确。基于这些发现,我们为进一步利用ChatGPT开展研究或开发提供了启示。
英文摘要:
With the increasing utilization of large language models such as ChatGPT during software development, it has become crucial to verify the quality of code content it generates. Recent studies proposed utilizing ChatGPT as both a developer and tester for multi-agent collaborative software development. The multi-agent collaboration empowers ChatGPT to produce test reports for its generated code, enabling it to self-verify the code content and fix bugs based on these reports. However, these studies did not assess the effectiveness of the generated test reports in validating the code. Therefore, we conduct a comprehensive empirical investigation to evaluate ChatGPT's self-verification capability in code generation, code completion, and program repair. We request ChatGPT to (1) generate correct code and then self-verify its correctness; (2) complete code without vulnerabilities and then self-verify for the presence of vulnerabilities; and (3) repair buggy code and then self-verify whether the bugs are resolved. Our findings on two code generation datasets, one code completion dataset, and two program repair datasets reveal the following observations: (1) ChatGPT often erroneously predicts its generated incorrect code as correct. (2) The self-contradictory hallucinations in ChatGPT's behavior arise. (3) The self-verification capability of ChatGPT can be enhanced by asking the guiding question, which queries whether ChatGPT agrees with assertions about incorrectly generated or repaired code and vulnerabilities in completed code. (4) Using test reports generated by ChatGPT can identify more vulnerabilities in completed code, but the explanations for incorrectly generated code and failed repairs are mostly inaccurate in the test reports. Based on these findings, we provide implications for further research or development using ChatGPT.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。