Generate code completions from a partial code snippet using a GGUF language model.
How it works
Reads a code prefix from the --code flag or piped stdin
Loads a GGUF model via inference.LoadFile
Constructs a completion prompt and generates the continuation
Prints the original code followed by the generated completion
Works best with code-capable models (CodeLlama, DeepSeek Coder, Qwen 2.5 Coder) but any instruction-tuned model can produce reasonable completions.
Usage
go build -o code-completion ./examples/code-completion/
# Pass code via flag
./code-completion --model path/to/model.gguf --code "func fibonacci(n int) int {"
# Pass code via stdin
echo "func add(a, b int) int {" | ./code-completion --model path/to/model.gguf
# Use GPU and lower temperature for more deterministic output
./code-completion --model path/to/model.gguf --device cuda --temperature 0.1 \
--code "// quicksort sorts a slice of integers in place.
func quicksort(arr []int) {"
Command code-completion demonstrates using a language model for code completion.
It reads a code snippet (from a flag or stdin), appends a completion prompt,
and generates the continuation. This pattern works with any code-capable GGUF
model (e.g., CodeLlama, DeepSeek Coder, Qwen 2.5 Coder).
Usage:
go build -o code-completion ./examples/code-completion/
./code-completion --model path/to/model.gguf --code "func fibonacci(n int) int {"
echo "func add(a, b int) int {" | ./code-completion --model path/to/model.gguf