詳細な分析とコード生成

Python で DeepSeek を使いこなす

James Chapman

AI Curriculum Lead, DataCamp

復習...

print(response.choices[0].message.content)
Step 1 - ...
Step 2 - ...
Final Answer: ...
  • 推論はデフォルトで有効 → reasoning_effort="high" または "max" で調整
  • 推論中は temperature が効果を持ちません
Python で DeepSeek を使いこなす

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
Python で DeepSeek を使いこなす

2. 推論を促す

 

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

 

❌ トークン使用量の増加

❌ 応答時間の増加

Python で DeepSeek を使いこなす

3. 単純なタスクには使わない!

 

チャットモード

簡単なタスクを難なくこなすチャットモデル。

 

推論モード

簡単な問題に苦戦する推論モデル。

Python で DeepSeek を使いこなす

3. 単純なタスクには使わない!

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**
  • 単純な確認作業に対して、構造化された推論は過剰です
  • チャット形式の回答よりもトークン数とレイテンシが増加します
Python で DeepSeek を使いこなす

例:コードのデバッグ

コードをデバッグする人間。

推論モデルのワークフロー。

Python で DeepSeek を使いこなす

例:コードのデバッグ

エラーをもとにコードを修正する推論モデル。

Python で DeepSeek を使いこなす

例:コードのデバッグ

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

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

count_to_ten(1)
"""
Python で DeepSeek を使いこなす
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)
Python で DeepSeek を使いこなす

練習しましょう!

Python で DeepSeek を使いこなす

Preparing Video For Download...