Análise profunda e geração de código

Trabalhando com DeepSeek em Python

James Chapman

AI Curriculum Lead, DataCamp

Recapitulando...

print(response.choices[0].message.content)
Step 1 - ...
Step 2 - ...
Final Answer: ...
  • Raciocínio vem ativado por padrão → ajuste com reasoning_effort="high" ou "max"
  • temperature não afeta durante o raciocínio
Trabalhando com DeepSeek em Python

1. Mantenha simples

  • Prompts concisos

What are the differences between lists and tuples in Python?

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

  • Dar exemplos (ex.: few-shot) pode reduzir o desempenho

Who developed the Python programming language?

Example 1:
Q: Who developed the R programming language?
A: Ross Ihaka and Robert Gentleman
Trabalhando com DeepSeek em Python

2. Estimule o raciocínio

 

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

 

Mais tokens usados

Maior tempo de resposta

Trabalhando com DeepSeek em Python

3. Evite tarefas simples!

 

Modo chat

Um modelo de chat concluindo facilmente uma tarefa simples.

 

Modo de raciocínio

Um modelo de raciocínio com dificuldade em problemas simples.

Trabalhando com DeepSeek em Python

3. Evite tarefas simples!

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash",
    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**
  • Para consultas triviais, raciocínio estruturado é exagero
  • Gasta mais tokens e aumenta a latência vs. resposta estilo chat
Trabalhando com DeepSeek em Python

Exemplo: Depuração de código

Uma pessoa depurando código.

O fluxo de trabalho de um modelo de raciocínio.

Trabalhando com DeepSeek em Python

Exemplo: Depuração de código

Um modelo de raciocínio corrigindo código com base no erro.

Trabalhando com DeepSeek em Python

Exemplo: Depuração de código

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

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

count_to_ten(1)
"""
Trabalhando com DeepSeek em 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)
Trabalhando com DeepSeek em Python

Vamos praticar!

Trabalhando com DeepSeek em Python

Preparing Video For Download...