File size: 2,011 Bytes
65e80b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# How to Run Deepseek Locally

This guide explains how to run the Deepseek model locally using Ollama as your server. Follow these steps to set up and use the model.

## Prerequisites

Ensure you have Ollama installed on your machine. If not, follow the installation instructions for Windows at:

[Ollama Installation Guide](https://ollama.com/download/windows)

## Getting Started with Deepseek Model

### Step 1: Pull the Deepseek Model

To use models in Ollama, start by downloading the desired model using the `pull` command. Open your terminal and run:

```bash
ollama pull <model>
```

### Step 2: Run the Model

After downloading, you can start the model with the following command:

```bash
ollama run <model>
```

This command activates the model, allowing you to enter queries or instructions, and receive responses.

### Step 3: Using the Model with OpenAI API Specifications

Ollama is now compatible with the OpenAI Chat Completions API. This allows you to use additional tooling and applications with Ollama locally. Here's how to set it up:

```python
from openai import OpenAI

model_name = "<model name>"
# Initialize the OpenAI client
client = OpenAI(
    base_url = 'http://localhost:11434/v1',
    api_key='ollama',  # This is required but unused
)

# Create chat completions
response = client.chat.completions.create(
  model=model_name,
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The LA Dodgers won in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)

# Print the response
print(response.choices[0].message.content)
```

### Step 4: Configuring WSL2 for Local Server Access

If you are using WSL2 and wish to access the Ollama server running on your Windows machine, you need to configure WSL2 with mirror mode to share localhost between WSL2 and Windows. For more details, see:

[Network Configuration Guide](network.md)