Skip to main content
QUICK REVIEW

[Paper Review] Repository-Level Prompt Generation for Large Language Models of Code

Disha Shrivastava, Hugo Larochelle|arXiv (Cornell University)|Jun 26, 2022
Software Engineering ResearchComputer Science13 citations
TL;DR

This paper proposes Repo-Level Prompt Generator (RLPG), a black-box framework that generates repository-aware prompts for code LLMs by selecting relevant context from multiple files using learnable prompt proposals. It achieves a 36% relative improvement over Codex on single-line code completion by leveraging structural and semantic repository context without model fine-tuning.

ABSTRACT

With the success of large language models (LLMs) of code and their use as code assistants (e.g. Codex used in GitHub Copilot), techniques for introducing domain-specific knowledge in the prompt design process become important. In this work, we propose a framework called Repo-Level Prompt Generator that learns to generate example-specific prompts using prompt proposals. The prompt proposals take context from the entire repository, thereby incorporating both the structure of the repository and the context from other relevant files (e.g. imports, parent class files). Our technique doesn't require any access to the weights of the LLM, making it applicable in cases where we only have black-box access to the LLM. We conduct experiments on the task of single-line code-autocompletion using code repositories taken from Google Code archives. We demonstrate that an oracle constructed from our prompt proposals gives a remarkably high relative improvement of 36% over Codex, showing the quality of these proposals. Further, we show that when we train a model to predict a prompt proposal, we can achieve significant performance gains over Codex and other baselines. We release our code, data, and trained checkpoints at: \url{https://github.com/shrivastavadisha/repo_level_prompt_generation}.

Motivation & Objective

  • To address the lack of systematic methods for incorporating repository-wide context into prompts for code LLMs.
  • To enable effective, example-specific prompt generation without access to model weights, supporting black-box deployment.
  • To integrate domain expertise into prompt design through interpretable, structured prompt proposals derived from repository structure and file content.
  • To improve code auto-completion performance by selecting relevant context from imports, parent classes, and related files across the repository.
  • To provide a scalable, non-fine-tuning alternative for adapting code LLMs to proprietary or niche software repositories.

Proposed method

  • The framework uses a set of predefined, human-readable prompt proposals that extract specific context from the repository, such as method names and bodies from imported files or class definitions from parent files.
  • A neural Prompt Proposal Classifier (PPC) is trained to predict the most effective prompt proposal for a given code completion target based on the repository and the target position.
  • The selected prompt proposal is combined with the default context (e.g., code before the target hole) to form a final prompt for the LLM.
  • The method operates under black-box access, requiring no fine-tuning of the underlying LLM, making it applicable to proprietary models like Codex.
  • Prompt proposals are designed to be interpretable and grounded in code semantics, such as extracting identifiers from import statements or method signatures from parent classes.
  • The framework is evaluated on single-line code completion using repositories from the Google Code archives, with performance measured against Codex and baselines.

Experimental results

Research questions

  • RQ1Can a learnable prompt selection mechanism improve code completion performance by leveraging repository-wide context without fine-tuning the LLM?
  • RQ2How effective is a black-box, repository-aware prompt generation framework compared to standard few-shot prompting with Codex?
  • RQ3To what extent can prompt proposals capturing structural and semantic context from multiple files improve code completion accuracy?
  • RQ4Can a neural prompt proposal classifier generalize across diverse codebases and achieve consistent performance gains?
  • RQ5How does the framework scale with increasing context length, especially when full repository context is not feasible?

Key findings

  • An oracle constructed from the prompt proposals achieved a 36% relative improvement in code completion accuracy over Codex, demonstrating the quality of the proposed context selection.
  • The trained Prompt Proposal Classifier (PPC) achieved significant performance gains over Codex and other baselines on the single-line code completion task.
  • The framework operates effectively under black-box access, making it applicable to proprietary LLMs like Codex without requiring model weights or fine-tuning.
  • Even with limited context length, RLPG outperforms standard prompting by focusing on semantically relevant, repository-wide context rather than arbitrary snippets.
  • The method remains effective despite repository size, as 70.22% of repositories in the dataset exceeded 32k tokens, highlighting its relevance in long-context scenarios.
  • Preliminary results suggest that extending the framework to combine multiple prompt proposals could yield further improvements, indicating strong potential for future enhancement.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.