Utilizarea rolului de asistent

Lucrul cu DeepSeek în Python

James Chapman

AI Curriculum Lead, DataCamp

Sarcini cu o singură interacțiune

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?"}]
)
  • System: controlează comportamentul asistentului
  • User: instruiește asistentul
  • Assistant: răspunsul la instrucțiunea utilizatorului
Lucrul cu DeepSeek în Python

Oferirea de exemple

 

  • Direcționează modelul corect
  • Mesajele de tip assistant sunt o formă mai structurată de shot-prompting
  • Exemplu: tutore de programare Python
    • Exemple de întrebări și răspunsuri ale utilizatorului

O bufniță de data science.

Lucrul cu DeepSeek în Python

Oferirea de exemple

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?"}] )
Lucrul cu DeepSeek în Python

Răspunsul

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects cannot
(like tuples or strings).
  • Experimentează cu numărul de exemple
Lucrul cu DeepSeek în Python

System vs. assistant vs. user

System → formatare importantă pentru șablon

Output the information in this format:
name | age | occupation

Assistant → exemple de conversații

User → context necesar pentru noua intrare (adesea o singură interacțiune)

Create a job advert for an AI Engineer. Use this job advert as a template:

Job Title: Data Engineer
...
Lucrul cu DeepSeek în Python

Hai să exersăm!

Lucrul cu DeepSeek în Python

Preparing Video For Download...