DeepSeek와의 멀티턴 대화

Python으로 DeepSeek 활용하기

James Chapman

AI Curriculum Lead, DataCamp

어시스턴트 메시지

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?"}] )
Python으로 DeepSeek 활용하기

대화 구성하기

사용자가 자신의 이름이 James라고 알리자 어시스턴트가 "Hi James!"라고 응답하는 화면

Python으로 DeepSeek 활용하기

대화 구성하기

어시스턴트의 "Hi James!" 응답이 메시지 딕셔너리 목록에 추가된 화면

Python으로 DeepSeek 활용하기

대화 구성하기

어시스턴트의 "Hi James!" 응답이 메시지 딕셔너리 목록에 추가된 화면

Python으로 DeepSeek 활용하기

대화 구성하기

메시지 목록 끝에 "What is my name?"이라는 사용자 메시지가 추가된 화면

Python으로 DeepSeek 활용하기

대화 구성하기

어시스턴트가 "Your name is James."라고 답변하는 화면

Python으로 DeepSeek 활용하기
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-Pro", messages=messages )
assistant_dict = {"role": "assistant", "content": response.choices[0].message.content} messages.append(assistant_dict)
print("Assistant: ", response.choices[0].message.content, "\n")
Python으로 DeepSeek 활용하기

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.
Python으로 DeepSeek 활용하기

연습해 봅시다!

Python으로 DeepSeek 활용하기

Preparing Video For Download...