Contextual API Completion for Unseen Repositories Using LLMs
<|reference_start|>Contextual API Completion for Unseen Repositories Using LLMs: 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.<|reference_end|>
@article{nashid2024contextual,
    title={Contextual API Completion for Unseen Repositories Using LLMs},
    author={Noor Nashid, Taha Shabani, Parsa Alian, Ali Mesbah},
    journal={arXiv preprint arXiv:2405.04600},
    year={2024},
    archivePrefix={arXiv},
    eprint={2405.04600},
    primaryClass={cs.SE}
}