Analiză aprofundată și generare de cod

Lucrul cu DeepSeek în Python

James Chapman

AI Curriculum Lead, DataCamp

Recapitulare...

print(response.choices[0].message.content)
Step 1 - ...
Step 2 - ...
Final Answer: ...
  • Raționamentul este activat implicit → ajustează-l cu reasoning_effort="high" sau "max"
  • temperature nu are niciun efect în timpul raționamentului
Lucrul cu DeepSeek în Python

1. Păstrează simplitatea

  • Prompturi concise

✅ What are the differences between lists and tuples in Python?

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

  • Oferirea de exemple (de ex., few-shot) poate diminua performanța

✅ Who developed the Python programming language?

❌

Example 1:
Q: Who developed the R programming language?
A: Ross Ihaka and Robert Gentleman
Lucrul cu DeepSeek în Python

2. Încurajează raționamentul

 

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

 

❌ Utilizare crescută de tokeni

❌ Timp de răspuns mai mare

Lucrul cu DeepSeek în Python

3. Evită sarcinile simple!

 

Mod chat

Un model de chat care rezolvă ușor o sarcină simplă.

 

Mod de raționament

Un model de raționament care are dificultăți cu probleme simple.

Lucrul cu DeepSeek în Python

3. Evită sarcinile simple!

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**
  • Pentru căutări triviale, raționamentul structurat este exagerat
  • Costă mai mulți tokeni și mai multă latență decât un răspuns de tip chat
Lucrul cu DeepSeek în Python

Exemplu: depanare de cod

Un om care depanează cod.

Fluxul de lucru al modelului de raționament.

Lucrul cu DeepSeek în Python

Exemplu: depanare de cod

Un model de raționament care corectează codul pe baza erorii.

Lucrul cu DeepSeek în Python

Exemplu: depanare de cod

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

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

count_to_ten(1)
"""
Lucrul cu DeepSeek în 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)
Lucrul cu DeepSeek în Python

Hai să exersăm!

Lucrul cu DeepSeek în Python

Preparing Video For Download...