Memanfaatkan peran assistant

Bekerja dengan DeepSeek di Python

James Chapman

AI Curriculum Lead, DataCamp

Tugas satu giliran

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who responds using concise,
                         one-sentence explanations."},
            {"role": "user",
             "content": "What is the difference between mutable and immutable objects?"}]
)
  • System: mengendalikan perilaku assistant
  • User: memberi instruksi kepada assistant
  • Assistant: respons atas instruksi user
Bekerja dengan DeepSeek di Python

Memberikan contoh

 

  • Mengarahkan model ke tujuan yang tepat
  • Memberikan pesan assistant adalah bentuk shot-prompting yang lebih terstruktur
  • Contoh: Tutor Pemrograman Python
    • Contoh pertanyaan dan jawaban user

Seekor burung hantu data science.

Bekerja dengan DeepSeek di Python

Memberikan contoh

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who responds using concise,
                         one-sentence explanations."},

{"role": "user", "content": "How do you define a Python list?"},
{"role": "assistant", "content": "Lists are defined by enclosing a comma-separated sequence of objects inside square brackets [ ]."},
{"role": "user", "content": "What is the difference between mutable and immutable objects?"}] )
Bekerja dengan DeepSeek di Python

Respons

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects cannot
(like tuples or strings).
  • Eksperimen dengan jumlah contoh
Bekerja dengan DeepSeek di Python

System vs. assistant vs. user

System → pemformatan templat penting

Output the information in this format:
name | age | occupation

Assistant → percakapan contoh

User → konteks yang dibutuhkan untuk masukan baru (sering satu giliran)

Create a job advert for an AI Engineer. Use this job advert as a template:

Job Title: Data Engineer
...
Bekerja dengan DeepSeek di Python

Ayo berlatih!

Bekerja dengan DeepSeek di Python

Preparing Video For Download...