การวิเคราะห์เชิงลึกและการสร้างโค้ด

การใช้งาน DeepSeek ใน Python

James Chapman

AI Curriculum Lead, DataCamp

สรุป...

print(response.choices[0].message.content)
Step 1 - ...
Step 2 - ...
Final Answer: ...
  • เปิดใช้งานการให้เหตุผลไว้เป็นค่าเริ่มต้น → ปรับได้ด้วย reasoning_effort="high" หรือ "max"
  • temperature ไม่มีผล ขณะที่ใช้ reasoning
การใช้งาน DeepSeek ใน Python

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
การใช้งาน DeepSeek ใน Python

2. กระตุ้นการให้เหตุผล

 

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

 

การใช้ token เพิ่มขึ้น

เวลาตอบสนองเพิ่มขึ้น

การใช้งาน DeepSeek ใน Python

3. หลีกเลี่ยงงานง่ายๆ!

 

โหมดแชท

โมเดลแชทที่ทำงานง่ายๆ ได้อย่างง่ายดาย

 

โหมดการให้เหตุผล

โมเดล Reasoning ที่พยายามแก้ปัญหาง่ายๆ

การใช้งาน DeepSeek ใน Python

3. หลีกเลี่ยงงานง่ายๆ!

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**
  • สำหรับการค้นหาข้อมูลง่ายๆ การให้เหตุผลแบบมีโครงสร้างถือว่าเกินความจำเป็น
  • ใช้ token และเวลาแฝงมากกว่าคำตอบแบบแชททั่วไป
การใช้งาน DeepSeek ใน Python

ตัวอย่าง: การดีบักโค้ด

คนกำลังดีบักโค้ด

ขั้นตอนการทำงานของโมเดล Reasoning

การใช้งาน DeepSeek ใน Python

ตัวอย่าง: การดีบักโค้ด

โมเดล Reasoning กำลังแก้โค้ดตามข้อผิดพลาด

การใช้งาน DeepSeek ใน Python

ตัวอย่าง: การดีบักโค้ด

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

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

count_to_ten(1)
"""
การใช้งาน DeepSeek ใน 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)
การใช้งาน DeepSeek ใน Python

มาฝึกกันเถอะ!

การใช้งาน DeepSeek ใน Python

Preparing Video For Download...