arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2405.04600cs.SE
收藏

利用大语言模型实现未知仓库的上下文感知API补全

Contextual API Completion for Unseen Repositories Using LLMs

Noor Nashid, Taha Shabani, Parsa Alian, Ali Mesbah

AI总结:

针对大模型在未知仓库API补全中因缺乏领域信息产生幻觉的问题,提出结合仓库全局与局部上下文的LANCE方法,在涵盖两种语言的APIEval基准上,准确率显著优于Copilot,且无需语言特定微调即可高效部署。

摘要:

大语言模型在处理各类代码相关任务上已取得显著进展,但由于缺乏真实场景下的领域特定信息(例如未知软件项目的仓库内API调用),其输出生成的不一致性阻碍了实际应用。本文提出一种新颖技术,通过利用代码仓库内的全局和局部上下文信息缓解幻觉问题,用于API补全任务。该方法专为优化代码补全任务设计,重点聚焦于提升局部API补全的效果。\n在进行API补全时,我们会分析相关的import语句,从方法签名中提取局部API的相关信息。针对API token补全任务,我们分析行内变量并将其与对应的已导入模块关联,从而使方法能够从可用的局部API中排序出最符合上下文的建议。此外,针对对话式API补全任务,我们通过在项目内进行基于检索的搜索,收集与开发者查询最相关的API。\n我们在自研基准APIEval框架下使用工具LANCE开展实验,该基准涵盖两种不同的编程语言。评估结果显示,API token补全的平均准确率为82.6%,对话式API补全任务的平均准确率为76.9%。平均而言,LANCE在API token补全和对话式API补全任务上分别比Copilot高出143%和142%。本研究结果对开发者具有重要意义,表明这种轻量级上下文分析方法可应用于多语言环境,无需特定语言的训练或微调,仅需少量示例和极低工作量即可高效部署。

英文摘要:

Large language models have made substantial progress in addressing diverse code-related tasks. However, their adoption is hindered by inconsistencies in generating output due to the lack of real-world, domain-specific information, such as for intra-repository API calls for unseen software projects. We introduce a novel technique to mitigate hallucinations by leveraging global and local contextual information within a code repository for API completion tasks. Our approach is tailored to refine code completion tasks, with a focus on optimizing local API completions. We examine relevant import statements during API completion to derive insights into local APIs, drawing from their method signatures. For API token completion, we analyze the inline variables and correlate them with the appropriate imported modules, thereby allowing our approach to rank the most contextually relevant suggestions from the available local APIs. Further, for conversational API completion, we gather APIs that are most relevant to the developer query with a retrieval-based search across the project. We employ our tool, LANCE, within the framework of our proposed benchmark, APIEval, encompassing two different programming languages. Our evaluation yields an average accuracy of 82.6% for API token completion and 76.9% for conversational API completion tasks. On average, LANCE surpasses Copilot by 143% and 142% for API token completion and conversational API completion, respectively. The implications of our findings are substantial for developers, suggesting that our lightweight context analysis can be applied to multilingual environments without language-specific training or fine-tuning, allowing for efficient implementation with minimal examples and effort.

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

↑