Copilot-in-the-Loop:使用Copilot修复Copilot生成的Python代码中的代码坏味
Copilot-in-the-Loop: Fixing Code Smells in Copilot-Generated Python Code using Copilot
AI总结:
本研究构建了包含102个代码坏味的数据集,发现Copilot生成的Python代码中存在8种坏味,其中多重嵌套容器最常见;Copilot Chat最高可修复87.1%的坏味,且更详细的提示词能提升修复效果。
摘要:
作为最流行的动态语言之一,Python在存在代码坏味时,其可读性和可维护性会下降。大型语言模型的最新进展引发了人们对用于代码生成和重构的AI辅助工具日益增长的兴趣。GitHub Copilot就是这样一种已被广泛使用的工具。Copilot Chat于2023年9月发布,作为一个交互式工具,旨在促进基于自然语言的编程。然而,对于Copilot生成的Python代码中的代码坏味以及Copilot Chat修复这些代码坏味的能力,关注有限。为此,我们构建了一个包含102个Copilot生成的Python代码中代码坏味的数据集。我们的目标是首先探索Copilot生成的Python代码中代码坏味的发生情况,然后评估Copilot Chat在使用不同提示词修复这些代码坏味方面的有效性。结果表明,在Copilot生成的Python代码中可以检测到10种代码坏味类型中的8种,其中多重嵌套容器是最常见的一种。对于这些代码坏味,Copilot Chat的最高修复率达到87.1%,显示出修复Copilot自身生成的Python代码坏味的潜力。此外,通过提供更详细的提示词,可以提高Copilot Chat修复这些坏味的效果。
英文摘要:
As one of the most popular dynamic languages, Python experiences a decrease in readability and maintainability when code smells are present. Recent advancements in Large Language Models have sparked growing interest in AI-enabled tools for both code generation and refactoring. GitHub Copilot is one such tool that has gained widespread usage. Copilot Chat, released in September 2023, functions as an interactive tool aimed at facilitating natural language-powered coding. However, limited attention has been given to understanding code smells in Copilot-generated Python code and Copilot Chat's ability to fix the code smells. To this end, we built a dataset comprising 102 code smells in Copilot-generated Python code. Our aim is to first explore the occurrence of code smells in Copilot-generated Python code and then evaluate the effectiveness of Copilot Chat in fixing these code smells employing different prompts. The results show that 8 out of 10 types of code smells can be detected in Copilot-generated Python code, among which Multiply-Nested Container is the most common one. For these code smells, Copilot Chat achieves a highest fixing rate of 87.1%, showing promise in fixing Python code smells generated by Copilot itself. In addition, the effectiveness of Copilot Chat in fixing these smells can be improved by providing more detailed prompts.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。