Mehrstufige Unterhaltungen mit DeepSeek

Arbeiten mit DeepSeek in Python

James Chapman

AI Curriculum Lead, DataCamp

Assistant-Nachrichten

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  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?"}] )
Arbeiten mit DeepSeek in Python

Eine Unterhaltung aufbauen

Sende eine Nutzeranfrage, die dem Assistant sagt, dass ich James heiße. Der Assistant antwortet mit „Hi James!"

Arbeiten mit DeepSeek in Python

Eine Unterhaltung aufbauen

Die Antwort „Hi James!" des Assistant wird in die Nachrichtenliste von Dictionaries übernommen.

Arbeiten mit DeepSeek in Python

Eine Unterhaltung aufbauen

Die Antwort „Hi James!" des Assistant wird in die Nachrichtenliste von Dictionaries übernommen.

Arbeiten mit DeepSeek in Python

Eine Unterhaltung aufbauen

Am Ende der Nachrichtenliste von Dictionaries wird eine Nutzerfrage hinzugefügt: „Wie heiße ich?"

Arbeiten mit DeepSeek in Python

Eine Unterhaltung aufbauen

Der Assistant antwortet mit „Du heißt James."

Arbeiten mit DeepSeek in 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-V4.1-Flash", messages=messages )
assistant_dict = {"role": "assistant", "content": response.choices[0].message.content} messages.append(assistant_dict)
print("Assistant: ", response.choices[0].message.content, "\n")
Arbeiten mit DeepSeek in Python

Unterhaltung mit einer KI

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.
Arbeiten mit DeepSeek in Python

Lass uns üben!

Arbeiten mit DeepSeek in Python

Preparing Video For Download...