Lune

ICSE2025顶会

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

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

摘要

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 code snippet 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' ability on the adaptation task. Specifically, we enhance the prompt by enriching the context and decomposing the task, which alleviates context misapplication and improves requirement understanding. Besides, we enable LLMs' reflection by requiring them to interact with a human or a LLM counselor, compensating for unclear requirement. Our 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.

问 Lune

几分钟读透这篇 Paper,不用再花一下午。

Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。

已有 3 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。

可以从这些问题问起

Lune 可以查阅

全文 · 引用它的顶会 Paper · 相关的 Paper

获取答案

免费开始,无需绑卡

脉络

  • AdaptEval: A Benchmark for Evaluating Large Language Models on Code Snippet Adaptation 引用了 Language Models are Few-Shot Learners
  • AdaptEval: A Benchmark for Evaluating Large Language Models on Code Snippet Adaptation 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • AdaptEval: A Benchmark for Evaluating Large Language Models on Code Snippet Adaptation 引用了 The Curious Case of Neural Text Degeneration
  • Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code Adaptation 引用了 AdaptEval: A Benchmark for Evaluating Large Language Models on Code Snippet Adaptation
  • Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code Adaptation 引用了 Wired for Reuse: Automating Context-Aware Code Adaptation in IDEs via LLM-Based Agent
  • Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code Adaptation 引用了 Language Models are Few-Shot Learners
  • Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code Adaptation 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Rethinking the Role of Demonstrations: What Makes In-Context Learning Work? 引用了 Language Models are Few-Shot Learners
  • Rethinking the Role of Demonstrations: What Makes In-Context Learning Work? 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Language Models are Few-Shot Learners 引用了 The Curious Case of Neural Text Degeneration
  • WizardCoder: Empowering Code Large Language Models with Evol-Instruct 引用了 Language Models are Few-Shot Learners
它引用的引用它的从左到右按年份排列,引用越多,位置越高。

引用它的顶会 Paper3

  1. AdaptEval: A Benchmark for Evaluating Large Language Models on Code Snippet AdaptationTanghaoran Zhang, Xinjun Mao, Shangwen Wang, Yuxin Zhao 等ASE 2025 · 1 次引用
  2. Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code AdaptationTanghaoran Zhang, Xinjun Mao, Shangwen Wang, Yuxin Zhao 等FSE 2026
  3. Wired for Reuse: Automating Context-Aware Code Adaptation in IDEs via LLM-Based AgentTaiming Wang, Yanjie Jiang, Chunhao Dong, Yuxia Zhang 等ASE 2025

它引用的 Paper17

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah 等NeurIPS 2020 · 64,255 次引用
  2. Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma 等NeurIPS 2022 · 22,562 次引用
  3. The Curious Case of Neural Text DegenerationAri Holtzman, Jan Buys, Li Du, Maxwell Forbes 等ICLR 2020 · 4,112 次引用
  4. WizardCoder: Empowering Code Large Language Models with Evol-InstructZiyang Luo, Can Xu, Pu Zhao, Qingfeng Sun 等ICLR 2024 · 945 次引用
  5. Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?Sewon Min, Xinxi Lyu, Ari Holtzman, Mikel Artetxe 等EMNLP 2022 · 634 次引用

相关 Paper

  1. Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context LearningMingyang Geng, Shangwen Wang, Dezun Dong, Haotian Wang 等ICSE 2024 · 124 次引用
  2. From Code Generation to Conceptual Learning: Student Use of LLMs in a Web Programming CourseHajara-Yasmin Isa, Matthew Weston, Muhammad Rizky Wellyanto, Ishita Karna 等CHI 2026 · 1 次引用
  3. Selective Prompt Anchoring for Code GenerationYuan Tian, Tianyi ZhangICML 2025
  4. Do Large Language Models Pay Similar Attention Like Human Programmers When Generating Code?Bonan Kou, Shengmai Chen, Zhijie Wang, Lei Ma 等FSE 2024 · 8 次引用
  5. AdaptAgent: A Multi-agent, Domain-Guided Reasoning Framework for Code AdaptationXiaokai Rong, Hridya Dhulipala, Aashish Yadavally, Tien N. NguyenISSTA 2026
黄昏的海面,两侧是细线勾勒的悬崖