Copilot-in-the-Loop: Fixing Code Smells in Copilot-Generated Python Code using Copilot
作者: Beiqi Zhang, Peng Liang, Qiong Feng, Yujia Fu, Zengyang Li
分类: cs.SE, cs.AI
发布日期: 2024-01-25 (更新: 2024-08-21)
备注: The 39th IEEE/ACM International Conference on Automated Software Engineering (ASE), NIER Track
💡 一句话要点
提出Copilot-in-the-Loop以修复Copilot生成的Python代码中的代码异味
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码异味 Python Copilot 自然语言处理 代码生成 重构工具 AI辅助编程
📋 核心要点
- 现有方法对Copilot生成的Python代码中的代码异味关注不足,导致可读性和可维护性下降。
- 论文提出通过构建数据集和使用Copilot Chat评估其修复能力,探索代码异味的检测与修复。
- 实验结果显示,Copilot Chat在修复代码异味方面表现出色,最高修复率达到87.1%。
📝 摘要(中文)
作为一种流行的动态语言,Python在存在代码异味时可读性和可维护性下降。近年来,大型语言模型的进展引发了对AI驱动的代码生成和重构工具的关注。GitHub Copilot是其中一个广泛使用的工具。2023年9月发布的Copilot Chat作为一种交互式工具,旨在促进自然语言驱动的编码。然而,关于Copilot生成的Python代码中的代码异味及Copilot Chat修复这些异味的能力的研究仍然有限。为此,我们构建了一个包含102种代码异味的数据集,旨在探索Copilot生成的Python代码中代码异味的出现情况,并评估Copilot Chat在使用不同提示修复这些异味的有效性。结果表明,Copilot生成的Python代码中可以检测到10种代码异味中的8种,其中“多重嵌套容器”最为常见。对于这些代码异味,Copilot Chat的最高修复率达到87.1%,显示出其在修复Copilot自身生成的Python代码异味方面的潜力。此外,通过提供更详细的提示,可以提高Copilot Chat修复这些异味的有效性。
🔬 方法详解
问题定义:本论文旨在解决Copilot生成的Python代码中存在的代码异味问题。现有方法对这些异味的识别和修复能力不足,影响了代码的可读性和可维护性。
核心思路:论文的核心思路是构建一个包含多种代码异味的数据集,并利用Copilot Chat进行修复评估。通过不同的提示,探索其在修复代码异味方面的有效性。
技术框架:整体框架包括数据集构建、代码异味检测和修复评估三个主要模块。首先,收集和标注Copilot生成的Python代码中的代码异味;其次,使用Copilot Chat进行修复;最后,评估修复效果。
关键创新:最重要的技术创新在于构建了一个专门针对Copilot生成代码的代码异味数据集,并系统性地评估了Copilot Chat的修复能力。这一方法与传统的代码重构工具相比,更加依赖于自然语言处理技术。
关键设计:在实验中,设计了多种提示策略,以提高Copilot Chat的修复效果。通过调整提示的详细程度,发现可以显著提升修复率。
🖼️ 关键图片
📊 实验亮点
实验结果显示,Copilot Chat在修复Copilot生成的Python代码中的代码异味方面表现优异,8种代码异味中最高修复率达到87.1%。通过优化提示策略,修复效果得到了显著提升,为AI辅助编程工具的应用提供了新的思路。
🎯 应用场景
该研究的潜在应用领域包括软件开发、代码审查及教育等。通过提高Copilot生成代码的质量,开发者可以更高效地进行代码维护和重构,减少技术债务。此外,该研究为未来AI辅助编程工具的改进提供了重要的实证依据。
📄 摘要(原文)
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.