一句话:用自然语言短语表达多假设补全,避免生成多份完整代码,兼顾命中意图与低开销。
基于 LLM 的代码补全通常只提供单条建议,在上下文有歧义时难以覆盖开发者真实意图。现有多假设补全方法生成多个完整代码候选以提高命中率,但带来高延迟和开发者认知负担。本文提出 FastMCC,将多个假设表示为简洁的自然语言短语而非完整代码,并采用两阶段推理:先生成初始代码建议及替代意图短语;当用户选择某个短语后,再生成与该意图对齐的代码。作者设计了轻量微调框架,使基础代码 LLM 获得该能力且不损害原有补全性能。在三个代码 LLM 上的实验表明,FastMCC 保持初始建议的通过率,同时为多假设选项节省 76.6% 的生成 token。
LLM-based code completion systems typically offer only one suggestion, often failing to cover developers’ intent, especially with ambiguous context. Current multiple-hypotheses code completion, i.e., generating multiple full-code candidates to increase the possibility to hit the user intent, can mitigate this but with a price of high latency and developers’ cognitive burden. To fill this gap, we propose FastMCC, which presents multiple hypotheses as concise natural language phrases instead of full code. It uses a two-stage inference: first generating an initial code suggestion followed by alternative intent phrases; then generating intent-aligned code if a phrase is selected. We design a lightweight fine-tuning framework to equip base code LLMs with this capability without compromising their original code completion performance. Experiments on three code LLMs show FastMCC maintains the pass rate of initial suggestions, while saving 76.6% generated tokens for multiple-hypotheses options.