Углублённый анализ и генерация кода

Работа с DeepSeek на Python

James Chapman

AI Curriculum Lead, DataCamp

Повторение...

print(response.choices[0].message.content)
Step 1 - ...
Step 2 - ...
Final Answer: ...
  • Рассуждение включено по умолчанию → настройте через reasoning_effort="high" или "max"
  • temperature не влияет на режим рассуждения
Работа с DeepSeek на Python

1. Простота прежде всего

  • Краткие промпты

What are the differences between lists and tuples in Python?

In Python, there are different data structures. Lists are...

  • Примеры (например, few-shot) могут снижать качество ответа

Who developed the Python programming language?

Example 1:
Q: Who developed the R programming language?
A: Ross Ihaka and Robert Gentleman
Работа с DeepSeek на Python

2. Стимулируйте рассуждение

 

"... Take your time and think through each step."

 

Увеличенный расход токенов

Увеличенное время ответа

Работа с DeepSeek на Python

3. Избегайте простых задач!

 

Режим чата

Чат-модель легко справляется с простой задачей.

 

Режим рассуждения

Модель рассуждения испытывает затруднения с простыми задачами.

Работа с DeepSeek на Python

3. Избегайте простых задач!

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=[{"role": "user", "content": "Return the result of 1+1."}]
)
print(response.choices[0].message.content)
Let's count step by step.
- Start with 1.
- Add another 1.
- 1 + 1 = 2.

**Final Answer: 2**
  • Для тривиальных запросов структурированное рассуждение избыточно
  • Тратит больше токенов и времени, чем обычный чат-ответ
Работа с DeepSeek на Python

Пример: отладка кода

Человек отлаживает код.

Рабочий процесс модели рассуждения.

Работа с DeepSeek на Python

Пример: отладка кода

Модель рассуждения исправляет код на основе ошибки.

Работа с DeepSeek на Python

Пример: отладка кода

prompt = """
[Task: Fix the following code.]

Code:
def count_to_ten(start):
    while start < 10:
        print(start)
    return "Done"

count_to_ten(1)
"""
Работа с DeepSeek на Python
print(response.choices[0].message.content)
Let me walk through the function step by step.

The function uses a while loop: while start < 10. Then it prints start. But wait, inside the loop,
there's no increment for the start variable — that's the issue.

The fix is to add an increment to start inside the loop. Like start += 1.

Here is the corrected code:

def count_to_ten(start):
    while start < 10:
        print(start)
        start += 1
    return "Done"

count_to_ten(1)
Работа с DeepSeek на Python

Давайте потренируемся!

Работа с DeepSeek на Python

Preparing Video For Download...