Local Coding Agent: Run DeepSeek R1 Locally, Use It with Ollama and Cline

Tue Feb 04 2025

Introduction

Large Language Models (LLMs) are revolutionizing how we interact with computers, and their application in coding is particularly exciting. DeepSeek R1, known for its strong reasoning capabilities similar to other powerful models, offers a compelling option. Even better, distilled versions of DeepSeek R1, like the 7B, 8B, 32B, and 70B parameter models, can be run locally using Ollama. Combine this with Cline, an open-source programming agent VS Code extension, and you have a powerful local coding setup. This post will show you how.

DeepSeek R1 and Ollama: Local Powerhouse

DeepSeek R1 is a powerful LLM with impressive reasoning abilities. While the largest versions require significant resources, distilled versions are designed to run efficiently on consumer hardware. Ollama simplifies the process of running these models locally. It provides a streamlined way to download, manage, and serve LLMs, including DeepSeek R1. This means you can have a powerful coding assistant running directly on your machine, without relying on cloud services.

To get started, you'll need to:

  1. Install Ollama: Follow the instructions on the Ollama website for your operating system.
  2. Download DeepSeek R1: Go to DeepSeek R1 model's page on Ollama, download the version you want to run on your local machine(e.g., 7B, 8B, 32B, or 70B).
  3. Run DeepSeek R1 with Ollama: Use the ollama run command to start the model. For example:
bash
|
ollama run deepseek-r1

Cline: Your Local Coding Agent

Cline is an open-source VS Code extension that acts as a programming agent. It can plan and execute complex programming tasks, significantly boosting developer productivity. Cline can leverage LLMs to understand natural language instructions and translate them into code. Critically, Cline can be configured to use a local LLM over Ollama's OpenAI API compatibility.

Connecting Cline to Ollama

Cline can communicate with Ollama using an OpenAI-compatible connector. Ollama exposes an OpenAI compatible API at http://127.0.0.1:11434/v1, which Cline can use. In Cline's settings, you'll need to configure it to point to this address. This tells Cline to use your locally running DeepSeek R1 instance via Ollama.

Here's a general outline of the steps:

  1. Install Cline: Install the Cline extension from the VS Code marketplace.
  2. Configure Cline: Open Cline's settings in VS Code.
  3. Choose Provider: Select the OpenAI Compatible as API provider in Cline's settings.
  4. Set the API endpoint: Change the API Base URL setting to http://127.0.0.1:11434/v1. This directs Cline to your local Ollama server.
  5. (Optional) API Key: You may not need an API key for local Ollama, but if Cline requires one, you can typically use a placeholder like ollama_key or any other short string. Ollama will not verify it.
  6. Model ID: Please specify the model ID you are running with Ollama, such as deepseek-r1:8b.

The Power of Local

Running DeepSeek R1 locally with Ollama and using it with Cline offers several advantages:

  • Privacy: Your code and prompts remain on your local machine.
  • Speed: Local processing can be faster than relying on remote servers, especially for complex tasks.
  • Cost-effective: You avoid the costs associated with using cloud-based LLM APIs.
  • Offline access: You can work even without an internet connection.

Conclusion

By combining the power of DeepSeek R1, Ollama, and Cline, you can create a truly local and powerful coding environment. This setup allows you to leverage the latest advancements in LLMs for coding assistance, while maintaining privacy, speed, and cost-effectiveness. As LLMs continue to evolve, local solutions like this will become increasingly important for developers. Experiment with different DeepSeek R1 model sizes to find the balance between performance and resource usage that works best for you. Start building amazing things today!