arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2411.15501cs.SEcs.AIcs.HC
收藏

指示还是交互?通过提示工程探索与激发大语言模型在代码片段适配中的能力

Instruct or Interact? Exploring and Eliciting LLMs' Capability in Code Snippet Adaptation Through Prompt Engineering

Key Laboratory of Software Engineering for Complex System(复杂系统软件工程重点实验室)

Tanghaoran Zhang, Yue Yu, Xinjun Mao, Shangwen Wang, Kang Yang, Yao Lu, Zhang Zhang, Yuxin Zhao

AI总结:

本文通过实证研究发现大语言模型在代码片段适配任务上弱于代码生成,并据此提出交互式提示方法,显著提升了LLMs的适配性能,为自主代码复用与适配提供了方法论支持。

摘要:

代码片段适配是软件开发过程中的一项基础活动。与代码生成不同,代码片段适配并非“自由创作”,它要求开发者对给定代码片段进行调整,以适配特定需求和代码上下文。近年来,大语言模型(LLMs)已在代码生成任务中展现出令人鼓舞的效果。然而,它们在适配这一面向复用且依赖上下文的代码变更预测任务上的表现仍不明确。为弥补这一空白,我们开展了一项实证研究,以考察LLMs在适配任务上的性能与问题。我们首先评估了三种主流LLMs的适配表现,并将其与代码生成任务进行对比。结果表明,它们的适配能力弱于生成能力,pass@1下降近15%,且出现更多与上下文相关的错误。通过人工检查200个案例,我们进一步分析了LLMs表现欠佳的原因,这些原因可分为三类:需求不明确、需求错位和上下文误用。基于上述实证研究,我们提出了一种交互式提示方法,以激发LLMs的适配能力。实验结果表明,我们的方法显著提升了LLMs的适配性能。表现最佳的Human-LLM交互成功解决了202个已识别缺陷中的159个,并将pass@1和pass@5相较于初始的基于指令的提示提升了超过40%。考虑到人力成本,我们建议将多智能体交互作为一种折中方案,它能够在具备出色泛化能力的同时取得可比的性能。我们认为,该方法可为基于LLMs的自主代码片段复用与适配提供方法论支持。

英文摘要:

Code snippet adaptation is a fundamental activity in the software development process. Unlike code generation, code snippet adaptation is not a "free creation", which requires developers to tailor a given code snippet in order to fit specific requirements and the code context. Recently, large language models (LLMs) have confirmed their effectiveness in the code generation task with promising results. However, their performance on adaptation, a reuse-oriented and context-dependent code change prediction task, is still unclear. To bridge this gap, we conduct an empirical study to investigate the performance and issues of LLMs on the adaptation task. We first evaluate the adaptation performances of three popular LLMs and compare them to the code generation task. Our result indicates that their adaptation ability is weaker than generation, with a nearly 15% decrease on pass@1 and more context-related errors. By manually inspecting 200 cases, we further investigate the causes of LLMs' sub-optimal performance, which can be classified into three categories, i.e., Unclear Requirement, Requirement Misalignment and Context Misapplication. Based on the above empirical research, we propose an interactive prompting approach to eliciting LLMs' adaptation ability. Experimental result reveals that our approach greatly improve LLMs' adaptation performance. The best-performing Human-LLM interaction successfully solves 159 out of the 202 identified defects and improves the pass@1 and pass@5 by over 40% compared to the initial instruction-based prompt. Considering human efforts, we suggest multi-agent interaction as a trade-off, which can achieve comparable performance with excellent generalization ability. We deem that our approach could provide methodological assistance for autonomous code snippet reuse and adaptation with LLMs.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑