Create your own and custom Copilot in VSCode with Ollama and CodeGPT

Daniel Avila
CodeGPT
Published in
4 min readMar 4, 2024

--

Ollama is a AI tool that lets you easily set up and run Large Language Models right on your own computer.

With Ollama, you can use really powerful models like Mistral, Llama 2 or Gemma and even make your own custom models. It works on macOS, Linux, and Windows, so pretty much anyone can use it.

Download Ollama

Get Ollama by visiting https://ollama.com/download

Download a Model

To run a AI model on your computer, you first need to download it from the Ollama server. For the full list of available models, visit the following link: https://ollama.com/library

You can search for a specific model or sort by categories.

In this tutorial, we’ll download the CodeLlama model, a specialized programming model created by Meta (https://github.com/facebookresearch/codellama)

To download the model, run the following command:

ollama pull codellama

The model download will kick off, so now, you’ll need to wait patiently 🙄

Listing Models

If you want to show the list of models you’ve already downloaded, execute the following command:

ollama list

Running a Model

Now that you have the models downloaded, you can run them in the terminal by executing the following command:

ollama run codellama

Test the model; you should see the response directly in the terminal

If you received a response, that means the model is already installed and ready to be used on your computer. Congratulations! 👏

Modelfile

A Modelfile is the blueprint for creating and sharing models with Ollama. Using Modelfile, you can create a custom configuration for a model and then upload it to Ollama to run it.

These are the parameters you can configure within the Modelfile:

Create a Modelfile

Now, let’s create a Modelfile by selecting the CodeLlama model to load it as a custom model in CodeGPT.

Create a folder named CodeLLama and then create a file called Modelfile, add the following code:

FROM codellama

# sets the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1

# sets the context window size to 1500, this controls how many tokens the LLM can use as context to generate the next token
PARAMETER num_ctx 1500

# sets a custom system message to specify the behavior of the chat assistant
SYSTEM You are expert Code Assistant

Run the following command to activate this new configuration. In this case, we will create the configuration model “codegpt-codellama”

ollama create codegpt-codellama -f ./Codellama/Modelfile

If we run ollama list, we’ll be able to see that the new model is already in our list.

Test this new configuration by using ollama run codegpt-codellama with our model set up to be a code assistant.

Configure your model as Copilot in VSCode

Once you have your new model configuration up and running, let’s connect it with Visual Studio Code using the CodeGPT extension and linking it with Ollama.

Install CodeGPT from the marketplace tab in VSCode.

From the extensions menu, click on the CodeGPT icon, then expand the provider selector and choose Ollama

Once the provider is selected, in the model selector, type the name of the model we just created, in this case, codegpt-codellama

That’s it! 🙌

You now have this new model, created by you, ready to be used as a programming assistant Copilot within Visual Studio Code thanks to Ollama and CodeGPT

If you want access to the best models for programmers, you can create a free account at https://codegpt.co and install these models directly into your code editor.

--

--