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

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

James Chapman

AI Curriculum Lead, DataCamp

ทบทวน...

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

1. เขียน Prompt ให้กระชับ

  • Prompt กระชับ

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. ส่งเสริมการ Reasoning

 

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

 

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

เวลารอผลลัพธ์นานขึ้น

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

3. หลีกเลี่ยงงานที่ง่ายเกินไป!

 

Chat mode

โมเดล Chat ทำงานง่าย ๆ ได้อย่างคล่องแคล่ว

 

Reasoning mode

โมเดล Reasoning ที่ติดขัดกับงานง่าย ๆ

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

3. หลีกเลี่ยงงานที่ง่ายเกินไป!

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    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**
  • สำหรับคำถามง่าย ๆ การ Reasoning แบบมีโครงสร้างนั้นเกินจำเป็น
  • ใช้ Token มากกว่าและใช้เวลานานกว่าการตอบแบบ Chat ทั่วไป
การใช้งาน DeepSeek ใน Python

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

มนุษย์กำลัง Debug โค้ด

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

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

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

โมเดล Reasoning แก้ไขโค้ดจากข้อผิดพลาดที่พบ

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

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

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...