Large Language Models (LLMs) have demonstrated impressive performance in software engineering tasks. However, improving their accuracy in generating correct and reliable code remains challenging. Numerous prompt engineering techniques (PETs) have been developed to address this, but no single approach is universally optimal. Selecting the right PET for each query is difficult for two primary reasons: (1) interactive prompting techniques may not consistently deliver the expected benefits, especially for simpler queries, and (2) current automated prompt engineering methods lack adaptability and fail to fully utilize multi-stage responses. To overcome these challenges, we propose PET-Select, a PET-agnostic selection model that uses code complexity as a proxy to classify queries and select the most appropriate PET. By incorporating contrastive learning, PET-Select effectively distinguishes between simple and complex problems, allowing it to choose PETs that are best suited for each query's complexity level. Our evaluations on the MBPP and HumanEval benchmarks using GPT-3.5 Turbo and GPT-4o show up to a 1.9% improvement in pass@1 accuracy, along with a 74.8% reduction in token usage. Additionally, we provide both quantitative and qualitative results to demonstrate how PET-Select effectively selects the most appropriate techniques for each code generation query, further showcasing its efficiency in optimizing PET selection.
翻译:大型语言模型(LLM)在软件工程任务中展现出卓越性能,然而提升其生成正确可靠代码的准确性仍具挑战性。尽管已有多种提示工程技术(PET)被提出以应对该问题,但尚无单一方法能普遍适用。为每个查询选择合适的PET主要面临两大难点:(1)交互式提示技术可能无法持续提供预期收益,尤其对于简单查询;(2)当前自动化提示工程方法缺乏适应性,且未能充分利用多阶段响应。为克服这些挑战,我们提出PET-Select——一种与具体PET无关的选择模型,该模型以代码复杂度为代理指标对查询进行分类,从而选择最合适的PET。通过引入对比学习机制,PET-Select能有效区分简单与复杂问题,使其可根据查询的复杂度级别选择最优PET。我们在MBPP和HumanEval基准测试中使用GPT-3.5 Turbo和GPT-4o进行评估,结果显示pass@1准确率最高提升1.9%,同时token使用量减少74.8%。此外,我们通过定量与定性分析证明PET-Select如何有效为每个代码生成查询选择最合适的技术,进一步展现了其在优化PET选择方面的高效性。