arXiv:2508.09537cs.SEcs.AI2025-08被引 2

让大模型通过上下文推断编程意图,提升无文档函数补全准确率

From Context to Intent: Reasoning-Guided Function-Level Code Completion

  • 用分步推理提示框架,引导模型从代码上下文推断开发意图
  • 在DevEval和ComplexCodeEval上实现超过25%的性能提升(pass@1)
  • 支持开发者交互修正意图,适合需要高精度补全的工程场景

大型语言模型在代码仓库中的函数补全任务中表现优异,但依赖明确的文档字符串。现实中大量函数缺乏清晰注释,导致模型难以准确生成。为此,本文提出一种基于推理的提示框架,使模型能逐步分析函数前的代码上下文,推断出开发者的实际意图。为支持训练与评估,构建了包含4万例的标注数据集,每例附带中间推理过程和对应文档字符串。在DevEval与ComplexCodeEval上的实验表明,该方法在DeepSeekCoder与CodeLLaMA系列模型上均实现超过25%的相对性能提升(pass@1)。进一步开发了意图交互平台,支持开发者选择或修改候选意图以引导模型,实验证明该方式可进一步优化生成质量。

原文摘要 · Abstract (English)

The growing capabilities of Large Language Models (LLMs) have led to their widespread adoption for function completion within code repositories. Recent studies on such tasks show promising results when explicit instructions, often in the form of docstrings, are available to guide the completion. However, in real-world scenarios, clear docstrings are frequently absent. Under such conditions, LLMs typically fail to produce accurate completions. To enable more automated and accurate function completion in such settings, we aim to enable LLMs to accurately infer the developer's intent prior to code completion. Our key insight is that the preceding code, namely the code context before the function to be completed, often contains valuable cues that help the model understand the intended functionality. However, inferring intent from such implicit context is non-trivial and constitutes a core challenge in function-level code completion. To tackle this challenge, inspired by how humans interpret context, we propose a reasoning-based prompting framework that guides LLMs to utilize these contextual cues to infer intent step by step. To incentivize LLMs to reason through the preceding code and infer intent, we further curate a dataset of 40k examples, each annotated with intermediate reasoning traces and corresponding docstrings. Extensive experiments on DevEval and ComplexCodeEval demonstrate consistent performance improvements across multiple models, achieving over 25% relative gains in pass@1 for both DeepSeekCoder and CodeLLaMA families. Building upon our framework, we further develop an intent-interactive platform that supports lightweight human feedback. This platform allows developers to select from a set of candidate intentions or edit the intent to better guide the model. Our experiments show that this interactive approach leads to further performance improvements.

代码生成意图理解大模型应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。