Djupanalys och kodgenerering

Arbeta med DeepSeek i Python

James Chapman

AI Curriculum Lead, DataCamp

Sammanfattning...

print(response.choices[0].message.content)
Step 1 - ...
Step 2 - ...
Final Answer: ...
  • Resonemang är påslaget som standard → justera med reasoning_effort="high" eller "max"
  • temperature har ingen effekt vid resonemang
Arbeta med DeepSeek i Python

1. Håll det enkelt

  • Koncisa prompter

Vad är skillnaderna mellan listor och tupler i Python?

I Python finns olika datastrukturer. Listor är...

  • Att ge exempel (t.ex. few-shot) kan försämra prestandan

Vem utvecklade programmeringsspråket Python?

Example 1:
Q: Who developed the R programming language?
A: Ross Ihaka and Robert Gentleman
Arbeta med DeepSeek i Python

2. Uppmuntra resonemang

 

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

 

Ökad tokenanvändning

Längre svarstid

Arbeta med DeepSeek i Python

3. Undvik enkla uppgifter!

 

Chattläge

En chattmodell löser enkelt en enkel uppgift.

 

Resonemangsläge

En resonemangsmodell som kämpar med enkla problem.

Arbeta med DeepSeek i Python

3. Undvik enkla uppgifter!

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro-0813",
    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**
  • För triviala uppslagningar är strukturerat resonemang överdrivet
  • Kostar fler tokens och ger längre svarstid än ett chattsvar
Arbeta med DeepSeek i Python

Exempel: felsökning av kod

En människa som felsöker kod.

Arbetsflödet för resonemangsmodellen.

Arbeta med DeepSeek i Python

Exempel: felsökning av kod

En resonemangsmodell som åtgärdar kod utifrån felet.

Arbeta med DeepSeek i Python

Exempel: felsökning av kod

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

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

count_to_ten(1)
"""
Arbeta med DeepSeek i 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)
Arbeta med DeepSeek i Python

Nu kör vi en övning!

Arbeta med DeepSeek i Python

Preparing Video For Download...