Percakapan multi-giliran dengan DeepSeek

Bekerja dengan DeepSeek di Python

James Chapman

Curriculum Manager, DataCamp

Pesan asisten

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V3",
  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

Membangun percakapan

Mengirim permintaan pengguna yang memberi tahu asisten bahwa nama saya James. Asisten menjawab "Hi James!"

Bekerja dengan DeepSeek di Python

Membangun percakapan

Respons "Hi James!" dari asisten dipindahkan ke daftar messages berupa dictionary.

Bekerja dengan DeepSeek di Python

Membangun percakapan

Respons "Hi James!" dari asisten dipindahkan ke daftar messages berupa dictionary.

Bekerja dengan DeepSeek di Python

Membangun percakapan

Respons pengguna ditambahkan ke akhir daftar messages berupa dictionary dengan pertanyaan "What is my name?"

Bekerja dengan DeepSeek di Python

Membangun percakapan

Asisten menjawab dengan "Nama Anda James."

Bekerja dengan DeepSeek di Python
messages = [{"role": "system",
             "content": "You are a Python programming tutor who responds using concise,
                         one-sentence explanations."}]


user_qs = ["Why is Python so popular?", "Summarize this in one sentence."]
for q in user_qs:
print("User: ", q)
user_dict = {"role": "user", "content": q}
messages.append(user_dict)
response = client.chat.completions.create( model="deepseek-ai/DeepSeek-V3", messages=messages )
assistant_dict = {"role": "assistant", "content": response.choices[0].message.content} messages.append(assistant_dict)
print("Assistant: ", response.choices[0].message.content, "\n")
Bekerja dengan DeepSeek di Python

Percakapan dengan AI

User:  Why is Python so popular?
Assistant:  Python is popular because it's easy to learn, has a simple syntax, and
offers powerful libraries for various applications like web development, data
science, and automation. 

User:  Summarize this in one sentence.
Assistant:  Python's simplicity, versatility, and extensive libraries make it
widely popular.
Bekerja dengan DeepSeek di Python

Ayo berlatih!

Bekerja dengan DeepSeek di Python

Preparing Video For Download...