Usare il ruolo assistant

Lavorare con DeepSeek in Python

James Chapman

AI Curriculum Lead, DataCamp

Attività a singolo turno

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": "What is the difference between mutable and immutable objects?"}]
)
  • System: controlla il comportamento dell'assistant
  • User: dà istruzioni all'assistant
  • Assistant: risposta all'istruzione dell'utente
Lavorare con DeepSeek in Python

Fornire esempi

 

  • Guida il modello nella direzione giusta
  • Fornire messaggi dell'assistant è una forma più strutturata di shot-prompting
  • Esempio: Python Programming Tutor
    • Domande e risposte d'esempio dell'utente

Un gufo data science.

Lavorare con DeepSeek in Python

Fornire esempi

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?"}] )
Lavorare con DeepSeek in Python

La risposta

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects cannot
(like tuples or strings).
  • Sperimenta con il numero di esempi
Lavorare con DeepSeek in Python

System vs. assistant vs. user

System → formato del template importante

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

Assistant → conversazioni di esempio

User → contesto richiesto per il nuovo input (spesso a singolo turno)

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

Job Title: Data Engineer
...
Lavorare con DeepSeek in Python

Esercitiamoci!

Lavorare con DeepSeek in Python

Preparing Video For Download...