code-completion

command
v1.38.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

Code Completion

Generate code completions from a partial code snippet using a GGUF language model.

How it works

  1. Reads a code prefix from the --code flag or piped stdin
  2. Loads a GGUF model via inference.LoadFile
  3. Constructs a completion prompt and generates the continuation
  4. 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) {"

Flags

Flag Default Description
--model (required) Path to GGUF model file
--device cpu Compute device: "cpu", "cuda"
--code (stdin) Code prefix to complete
--max-tokens 256 Maximum tokens to generate
--temperature 0.2 Sampling temperature (lower = more deterministic)

Documentation

Overview

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL