DeepSeek과의 다중 턴 대화

Python으로 DeepSeek 활용하기

James Chapman

AI Curriculum Lead, DataCamp

어시스턴트 메시지

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