Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat

Abstract

DeepSeek-R1 can run locally using Ollama, which is also compatible with OpenAI. This allows us to configure Ollama to use DeepSeek-R1 as a seamless replacement for an OpenAI model. In this article, we’ll build a simple chatbot using…


This content originally appeared on DEV Community and was authored by Akmal Chaudhri

Abstract

DeepSeek-R1 can run locally using Ollama, which is also compatible with OpenAI. This allows us to configure Ollama to use DeepSeek-R1 as a seamless replacement for an OpenAI model. In this article, we'll build a simple chatbot using Ollama and DeepSeek-R1.

The notebook file used in this article is available on GitHub.

Introduction

In a previous article, we tested a DeepSeek-R1 using Ollama for four different test cases. We'll now build a simple chatbot to test DeepSeek-R1 using OpenAI chat completions.

We'll use the smallest DeepSeek-R1 model, as it does not require any GPUs.

With Jupyter and Ollama running locally, we'll load the notebook downloaded from GitHub.

Run the code

After installing and importing the appropriate libraries, we'll download the smallest DeepSeek-R1 model, as follows:

model = "deepseek-r1:1.5b"

ollama.pull(model)

Next, we'll configure Ollama for OpenAI compatibility:

ollama_client = OpenAI(
    base_url = "http://localhost:11434/v1",
    api_key = "ollama"
)

Finally, we'll ask a question using chat completions:

response = ollama_client.chat.completions.create(
    model = model,
    messages = [
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "What is the answer to life, the universe and everything?"}
    ]
)

content = response.choices[0].message.content
remove_think_tags = True

if remove_think_tags:
    content = re.sub(r"<think>.*?</think>", "", content, flags = re.DOTALL)

print(content)

We'll disable <think> and </think> using a flag so that we can control the output of its reasoning process.

Example output:

Without knowing what a final theory would look like, we might not be able to distinguish life from non-living matter. Similarly, for the universe itself, without knowing about the ultimate reality, we can't tell. Therefore, both concepts remain indefinitely speculative and undetermined in their completeness.

**Final Answer:**
In our current understanding, neither the universe nor life is fully established with an accepted answer due to the inherent uncertainties in defining ultimate principles and truth.

Summary

We can easily use DeepSeek-R1 with Ollama for chat completions. Since Ollama provides OpenAI compatibility, it is easy to use DeepSeek-R1 as a drop-in replacement for an OpenAI model.


This content originally appeared on DEV Community and was authored by Akmal Chaudhri


Print Share Comment Cite Upload Translate Updates
APA

Akmal Chaudhri | Sciencx (2025-03-17T19:11:01+00:00) Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat. Retrieved from https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/

MLA
" » Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat." Akmal Chaudhri | Sciencx - Monday March 17, 2025, https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/
HARVARD
Akmal Chaudhri | Sciencx Monday March 17, 2025 » Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat., viewed ,<https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/>
VANCOUVER
Akmal Chaudhri | Sciencx - » Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/
CHICAGO
" » Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat." Akmal Chaudhri | Sciencx - Accessed . https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/
IEEE
" » Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat." Akmal Chaudhri | Sciencx [Online]. Available: https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/. [Accessed: ]
rf:citation
» Quick tip: Using Ollama and DeepSeek-R1 with OpenAI Chat | Akmal Chaudhri | Sciencx | https://www.scien.cx/2025/03/17/quick-tip-using-ollama-and-deepseek-r1-with-openai-chat/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.