arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.13118cs.SE
收藏

为大型语言模型生成代码的指南:实证分析

Guidelines to Prompt Large Language Models for Code Generation: An Empirical Characterization

University of Catania(卡塔尼亚大学);Software Institute – USI Università della Svizzera italiana(瑞士意大利语大学软件研究所);University of Sannio(萨尼奥大学)

Alessandro Midolo, Alessandro Giagnorio, Fiorella Zampetti, Rosalia Tufano, Gabriele Bavota, Massimiliano Di Penta

AI总结:

本文通过实证分析提出10条提示优化指南,帮助开发者改进代码生成提示,提升LLM辅助软件开发工具的效果。

摘要:

大型语言模型(LLMs)如今被广泛用于各种软件工程任务,主要集中在代码生成上。先前的研究已显示如何通过提示工程帮助开发人员改进代码生成提示。然而,迄今为止,尚不存在具体的指南指导开发人员编写适合代码生成的提示。在本工作中,我们推导并评估了开发特定的提示优化指南。首先,我们使用迭代、测试驱动的方法自动优化代码生成提示,并分析该过程的结果,以识别导致测试通过的提示改进项。我们使用这些元素来提取10条提示改进指南,涉及更好地指定输入输出、预置条件、提供示例、各种类型细节或澄清歧义。我们与50名从业者进行评估,他们报告了所提取提示改进模式的使用情况以及他们对这些模式的感知有用性,这并不总是与在了解我们的指南之前的实际使用情况一致。我们的结果不仅对从业者和教育者有启示,也对旨在创建更好的LLM辅助软件开发工具的人有启示。

英文摘要:

Large Language Models (LLMs) are nowadays extensively used for various types of software engineering tasks, primarily code generation. Previous research has shown how suitable prompt engineering could help developers in improving their code generation prompts. However, so far, there do not exist specific guidelines driving developers towards writing suitable prompts for code generation. In this work, we derive and evaluate development-specific prompt optimization guidelines. First, we use an iterative, test-driven approach to automatically refine code generation prompts, and we analyze the outcome of this process to identify prompt improvement items that lead to test passes. We use such elements to elicit 10 guidelines for prompt improvement, related to better specifying I/O, pre-post conditions, providing examples, various types of details, or clarifying ambiguities. We conduct an assessment with 50 practitioners, who report their usage of the elicited prompt improvement patterns, as well as their perceived usefulness, which does not always correspond to the actual usage before knowing our guidelines. Our results lead to implications not only for practitioners and educators, but also for those aimed at creating better LLM-aided software development tools.

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

↑