Analisi profonda e generazione di codice

Lavorare con DeepSeek in Python

James Chapman

Curriculum Manager, DataCamp

Ricapitolando...

Output di ragionamento
<think>
Thought process...
</think>

Final response: ...
  • PensaFaiAggiorna
  • model="deepseek-ai/DeepSeek-R1"
  • Nessun parametro temperature per i modelli di ragionamento
Lavorare con DeepSeek in Python

1. Tieni tutto semplice

  • Prompt concisi

What are the differences between lists and tuples in Python?

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

  • Fornire esempi (es. few-shot) può ridurre le prestazioni

Who developed the Python programming language?

Example 1:
Q: Who developed the R programming language?
A: Ross Ihaka and Robert Gentleman
Lavorare con DeepSeek in Python

2. Incoraggia il ragionamento

 

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

 

Accuratezza migliorata

Più token usati

Risposta più lenta

Lavorare con DeepSeek in Python

3. Evita i compiti banali!

 

Modelli chat

Un modello chat che risolve facilmente un compito semplice.

 

Modelli di ragionamento

Un modello di ragionamento che fatica con problemi semplici.

1 Creato con GPT-4o
Lavorare con DeepSeek in Python

3. Evita i compiti banali!

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-R1",
    messages=[{"role": "user", "content": "Return the result of 1+1."}]
)
<think>
Okay, so the user is asking for the result of 1 plus 1. Let me think about this. Well, basic
arithmetic tells me that when you add two numbers together, you combine their values. So 1 added
to another 1 should be... hmm. Let me visualize it. If I have one apple and someone gives me
another apple, I now have two apples. That makes sense. So 1 + 1 equals 2. Wait, is there any
trick here? The question seems straightforward, but maybe I should double-check. Let me count on
my fingers. One finger up, then add another...
</think>

The result of 1 + 1 is **2**.
Lavorare con DeepSeek in Python

3. Evita i compiti banali!

Output chat

The result of \(1 + 1\) is \(2\). 
\[
1 + 1 = 2
\]
Lavorare con DeepSeek in Python

Esempio: Debug del codice

Una persona che fa il debug del codice.

Il workflow di un modello di ragionamento.

1 Creato con GPT-4o
Lavorare con DeepSeek in Python

Esempio: Debug del codice

Un modello di ragionamento che corregge il codice in base all'errore.

1 Creato con GPT-4o
Lavorare con DeepSeek in Python

Esempio: Debug del codice

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

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

count_to_ten(1)
"""
Lavorare con DeepSeek in Python
<think>
Okay, let's see. The user provided a Python function called count_to_ten...

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. Oh right, that's the issue...

So the fix is to add an increment to start inside the loop. Like start += 1...
</think>

Here is the corrected code:

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

count_to_ten(1)
Lavorare con DeepSeek in Python

Vamos praticar!

Lavorare con DeepSeek in Python

Preparing Video For Download...