Who it is forA Go backend developer who needs text generation in a service and wants to avoid cgo or a separate inference server.
The problemCalling a hosted model API adds a network dependency, and cgo-based bindings complicate builds and cross-compiling.
The outcomeA Go program that loads a GGUF file, generates text from a prompt, and prints the result.
What you need first
- A Go toolchain installed on your machine
- A GGUF model file, such as model.gguf
- Enough memory for the model weights and KV cache, since the README notes wasm32 caps linear memory at 4 GiB
Steps
- Install a Go toolchain and download a GGUF model file to your machine.
- Run
go get github.com/goccy/go-llamain your Go module. (inferred, check the README) - Copy the README example into main.go and set the LoadModel path to your model file.
- Run
CGO_ENABLED=0 go run .to build and run without cgo. (inferred, check the README)
Prompt for your agent
In the Go module at <project-path>, add the goccy/go-llama package and use the README example to load <model-file>.gguf and generate text from the prompt "Once upon a time". Expected output: the generated text printed to stdout. Verify that the program exits without error when built with CGO_ENABLED=0.
Caveat. The README example uses a model file named model.gguf, and generation speed and memory use depend on the model size and quantization you choose.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for goccy/go-llama and "Add local GGUF text generation to a Go program"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer