CodeGemma is Google’s code model built on the Gemma family, and Ollama ships the 7B build. It handles code completion and code chat. This guide pulls it, asks it to explain a short snippet, and shows how to test the code it writes.
Before you start
- Ollama installed and running.
- At least 8 GB of free RAM for the 7B build, plus about 5 GB of free disk.
- A terminal and a short code snippet to ask about.
Pull the model
Download the 7B build:
ollama pull codegemma:7b
Then start a chat:
ollama run codegemma:7b
Ask it to explain a snippet
Paste a snippet of under 20 lines and ask for a line-by-line explanation. Choose code you understand so you can judge the answer.
Ask it to write a small function and run it
Ask for a function with a clear expected output, then run it yourself and compare. If the output differs, the code is wrong, however confident the explanation sounds.
Worked example
Sample prompt:
Write a Python function called first_even that takes a list of numbers and returns the first even number, or None if there is none. Show what it returns for [3, 7, 8, 9].
Check by hand: the first even number in [3, 7, 8, 9] is 8. The function should return 8. Run the code to confirm.
Expected result
UNTESTED in this guide: no chat was run while writing it. The expected result is a Python function that returns 8 for [3, 7, 8, 9], with an explanation that matches the code.
Limitations
CodeGemma is a code model, so its general chat answers are weaker than a chat model’s. Always run generated code before trusting it, and never paste secrets or private keys into a prompt.
