
Code Llama can fill a gap inside existing code by using fill-in-the-middle (FIM) markers. Meta documents infilling for the 7B and 13B base and Instruct variants; check the selected checkpoint's model card and inference implementation before assuming other sizes or variants support the same workflow.
Put the surrounding code around the gap
In the prefix-suffix-middle (PSM) layout, put the code before the gap after <PRE>, the code after the gap after <SUF>, then place <MID> where the model should generate the missing code:
<PRE>{{prefix_code}}<SUF>{{suffix_code}}<MID>Meta's reference code inserts these markers as special tokens, so prefer a runtime's infilling API over typing them as plain text. Keep the prefix and suffix intact. Include enough nearby code to show names, types, imports and style, but keep unrelated file content out of the prompt. The Code Llama paper describes these models' infilling capability and the official Code Llama repository contains inference examples.

