mlsanityData to 7 Oct 2026

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

arXiv 2411.15501 ↗First posted 23 Nov 2024cs.SE cs.AI cs.HCcited by 6

Not on the map. Why?

Abstract (arXiv)

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.

Key facts. Cited by 6 papers in the map (data through 7 Oct 2026). Builds on 34 of its 57 references that are in the map. First posted on arXiv 23 Nov 2024.

Builds on

34 of 57 references.

References · 34

  1. 2020Language Models are Few-Shot Learnerscited by 32,199
  2. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
  3. 2019The Curious Case of Neural Text Degenerationcited by 2,881
  4. 2023A Survey of Large Language Modelscited by 2,537
  5. 2022Emergent Abilities of Large Language Modelscited by 2,483
  6. 2021Pre-train, Prompt, and Predict: A Systematic Survey of Prompting Methods in Natural Language Processingcited by 2,222
  7. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  8. 2022Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?cited by 1,413
  9. 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 728
  10. 2023A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPTcited by 612
  11. 2021Prompt Programming for Large Language Models: Beyond the Few-Shot Paradigmcited by 599
  12. 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
22 more
  1. 2021Design Guidelines for Prompt Engineering Text-to-Image Generative Modelscited by 216
  2. 2023Keep the Conversation Going: Fixing 162 out of 337 bugs for 0.42 each using ChatGPTcited by 125
  3. 2023An Analysis of the Automatic Bug Fixing Performance of ChatGPTcited by 108
  4. 2023Is ChatGPT the Ultimate Programming Assistant -- How far is it?cited by 72
  5. 2023Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learningcited by 71
  6. 2023TELeR: A General Taxonomy of LLM Prompts for Benchmarking Complex Taskscited by 48
  7. 2023What Makes Good In-context Demonstrations for Code Intelligence Tasks with LLMs?cited by 47
  8. 2024AgentFL: Scaling LLM-based Fault Localization to Project-Level Contextcited by 47
  9. 2023Exploring the Potential of ChatGPT in Automated Code Refinement: An Empirical Studycited by 44
  10. 2023Improving ChatGPT Prompt for Code Generationcited by 28
  11. 2023A study on Prompt Design, Advantages and Limitations of ChatGPT for Deep Learning Program Repaircited by 26
  12. 2023CCT5: A Code-Change-Oriented Pre-Trained Modelcited by 17
  13. 2023Prompts Matter: Insights and Strategies for Prompt Engineering in Automated Software Traceabilitycited by 15
  14. 2023ChatGPT: A Study on its Utility for Ubiquitous Software Engineering Taskscited by 12
  15. 2019Analyzing and Supporting Adaptation of Online Code Examplescited by 8
  16. 2016From Query to Usable Code: An Analysis of Stack Overflow Code Snippetscited by 6
  17. 2018Usage and Attribution of Stack Overflow Code Snippets in GitHub Projectscited by 6
  18. 2021APIzation: Generating Reusable APIs from StackOverflow Code Snippetscited by 6
  19. 2017Stack Overflow in Github: Any Snippets There?cited by 5
  20. 2020Optimising the Fit of Stack Overflow Code Snippets into Existing Codecited by 5
  21. 2022Towards Exploring the Code Reuse from Stack Overflow during Software Developmentcited by 5
  22. 2023An empirical study of ChatGPT-3.5 on question answering and code maintenancecited by 4

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 5; 2026: 1.

6 papers.