Reasoning with DeepSeek

Working with DeepSeek in Python

James Chapman

AI Curriculum Lead, DataCamp

chat_icon.png

  • Predict next words
  • ✅ Wide-range of use cases
  • ❌ Struggle with deep multi-step tasks

reasoning_icon.png

  • Break complex tasks into sub-tasks
  • ✅ Better performance on complex tasks
  • ❌ Slower and more expensive
Working with DeepSeek in Python

Reasoning and math

A train travels 60 miles in 1.5 hours. If it continues at the same speed, how far will it travel in 4 hours, and what time will it arrive if it leaves at 2:15 PM?

A train traveling on a track.

Working with DeepSeek in Python

Reasoning and math

A train travels 60 miles in 1.5 hours. If it continues at the same speed, how far will it travel in 4 hours, and what time will it arrive if it leaves at 2:15 PM?

  1. Calculate the speed (60 ÷ 1.5 = 40 mph)

  2. Multiply by 4 hours to find the distance (40 × 4 = 160 miles)

  3. Add 4 hours to the departure time (2:15 PM + 4 hours = 6:15 PM)

  4. Return: "160 miles, arrival at 6:15 PM"

Working with DeepSeek in Python

Reasoning about reasoning

The high-level reasoning workflow of thinking, doing, and updating the knowledge.

Working with DeepSeek in Python

Reasoning is on by default

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=[{"role": "user", "content": train_problem}]
)

print(response.choices[0].message.content)
  • V4-Pro reasons by default → no extra parameter needed
Working with DeepSeek in Python
print(response.choices[0].message.content)
**Step 1 - Find the train's speed**
Speed = 60 / 1.5 = **40 mph**

**Step 2 - Distance in 4 hours**
Distance = 40 × 4 = **160 miles**

**Step 3 - Arrival time**
2:15 PM + 4 hours = **6:15 PM**

**Final Answer:** 160 miles, arriving at 6:15 PM
Working with DeepSeek in Python

Disabling reasoning

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    extra_body={"thinking": {"type": "disabled"}},
    messages=[{"role": "user", "content": prompt}]
)
  • Thinking is "enabled" by default; pass "disabled" to opt out
  • Without reasoning, the model behaves like a standard chat model
Working with DeepSeek in Python

Cranking up the effort

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    reasoning_effort="max",
    messages=[{"role": "user", "content": train_problem}]
)

print(response.choices[0].message.content)
  • Default effort is "high" → set to "max" for tougher problems
  • Increasing reasoning effort increases costs
  • Always test on lower reasoning effort values first
Working with DeepSeek in Python

Let's practice!

Working with DeepSeek in Python

Preparing Video For Download...