[Prompt Engineering] Include method/function definitions for code near the cursor
Hypothesis: The LLM will do a lot better if we include the function/method prototypes for the current code that we're working on. For example, let's suppose the user's prompt were this:
def enqueue_batch(batch, index)
job = enqueue!(
If we were able to find and provide the definition of enqueue!
, that might help the LLM auto-complete this better:
def self.enqueue!(uploads, to_store)
perform_async(uploads.ids, to_store)
end
Often the method/function might be defined in another file, so having multiple files and/or an indexed database would probably be more effective for method lookup. However, we can demonstrate that if the definition is in the same file, we can create better prompts.
Proposal:
- Run the code through TreeSitter.
- Attempt to identify all function/method prototypes.
- Try to find a match for the given call.
- Augment the prompt with that definition, commenting out code if necessary.
Edited by Stan Hu