New Tool Radar

Local AI

How to Run StarCoder2 with Ollama for Code Completion

Run StarCoder2 locally with Ollama and complete a half-written function on your own machine.

Schematic illustration with three step boxes for How to Run StarCoder2 with Ollama for Code Completion.

StarCoder2 is a code model trained on a large public code corpus, and Ollama ships the 7B build. It is suited to completing code rather than chatting about it. This guide pulls it, gives it a half-written function, and checks the completion by running it.

Before you start

  • Ollama installed and running.
  • At least 8 GB of free RAM for the 7B build, plus about 4 GB of free disk.
  • A terminal and a half-written function in a language you know.

Pull the model

Download the 7B build:

ollama pull starcoder2:7b

Then start it:

ollama run starcoder2:7b

Give it a half-written function

Paste the start of a function with a clear docstring or comment that says what it should do, and stop mid-way. Ask the model to complete it, keeping the same style.

Run the completed code

Copy the completion into a file, run it with a known input, and compare the output with the answer you expect. If it fails, read the error and ask for a fix.

Worked example

Sample prompt:

Complete this Python function. Keep the same style.

def is_palindrome(text):
    """Return True if text reads the same forwards and backwards, ignoring case and spaces."""

Check by hand: is_palindrome(“Race car”) should be True and is_palindrome(“hello”) should be False. Run both cases.

Expected result

UNTESTED in this guide: no chat was run while writing it. The expected result is a completed function that returns True for “Race car” and False for “hello” when you run it.

Limitations

StarCoder2 completes code; it does not know your project. It may use libraries you do not have or invent function names. Always run completions in a test file first, never in production code.

Sources

See all