DEDUPED Hot AI repos, turned into use cases Get the Monday 5

How to add local GGUF text generation to a Go program with Go Llama

Call a local GGUF model from Go code and get generated text back, with no cgo.

Short answer: Install a Go toolchain and download a GGUF model file to your machine; then run go get github.com/goccy/go-llama in your Go module; copy the README example into main.go and set the LoadModel path to your model file. All steps.

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

  1. Install a Go toolchain and download a GGUF model file to your machine.
  2. Run go get github.com/goccy/go-llama in your Go module. (inferred, check the README)
  3. Copy the README example into main.go and set the LoadModel path to your model file.
  4. 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

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer