Ролі в чаті та системні повідомлення

Робота з DeepSeek у Python

James Chapman

AI Curriculum Lead, DataCamp

Від одного ходу до кількох

 

Одноходові завдання

  • Генерація тексту
  • Трансформація тексту
  • Класифікація

Одноходове завдання з одним запитом і однією відповіддю.

Робота з DeepSeek у Python

Від одного ходу до кількох

 

Одноходові завдання

  • Генерація тексту
  • Трансформація тексту
  • Класифікація

 

Багатоходові розмови

→ Спираються на попередні запити та відповіді

Багатоходове завдання з кількома запитами та відповідями.

Робота з DeepSeek у Python

Ролі

 

  • System: керує поведінкою асистента
  • User: інструктує асистента
  • Assistant: відповідає на інструкцію користувача
    • Також може бути додано розробником як приклади

Три ролі у взаємодії в чаті: system, user та assistant.

Робота з DeepSeek у Python

Налаштування запиту

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash",
    messages=[{"role": "user", "content": prompt}]
)
Робота з DeepSeek у Python

Налаштування підказки

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?"}]
Робота з DeepSeek у Python

Виконання запиту

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": "What is the difference between mutable and immutable objects?"}]
)

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects
cannot be modified once created (like tuples or strings).
Робота з DeepSeek у Python

Запобігання зловживанням

 

  • System message: може містити обмежувачі
    • Обмеження на виходи моделі

Захисні відбійники вздовж дороги.

Чат-бот фінансового тьютора та чат-бот фінансового радника.

Робота з DeepSeek у Python

Запобігання зловживанням за допомогою системних повідомлень

sys_msg = """
You are finance education assistant that helps students study for exams.

If you are asked for specific, real-world financial advice with risk to their
finances, respond with only:

I'm sorry, I am not allowed to provide financial advice.
"""
Робота з DeepSeek у Python

Запобігання зловживанням за допомогою системних повідомлень

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  messages=[{"role": "system",
             "content": sys_msg},
            {"role": "user",
             "content": "Which stocks should I invest in?"}]
)

print(response.choices[0].message.content)
I'm sorry, I am not allowed to provide financial advice.
Робота з DeepSeek у Python

Давайте потренуємось!

Робота з DeepSeek у Python

Preparing Video For Download...