Utilizarea rolului de asistent

Lucrul cu OpenAI API

James Chapman

Curriculum Manager, DataCamp

Chat completions pentru sarcini single-turn

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a data science tutor."},
            {"role": "user",
             "content": "What is the difference between mutable and immutable objects?"}]
)
  • System: controlează comportamentul asistentului
  • User: instruiește asistentul
  • Assistant: răspuns la instrucțiunea utilizatorului
Lucrul cu OpenAI API

Furnizarea de exemple

 

  • Ghidarea modelului în direcția corectă
  • Mesajele de asistent sunt o formă mai structurată de shot-prompting
  • Exemplu: Tutore de programare Python
    • Întrebări și răspunsuri exemplu

O bufniță de data science.

Lucrul cu OpenAI API

Furnizarea de exemple

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who speaks concisely."},

{"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 OpenAI API

Răspunsul

print(response.choices[0].message.content)
Mutable objects can be changed after creation (e.g., lists, dictionaries). Immutable objects
cannot be altered once created (e.g., strings, tuples).
  • Experimentați cu numărul de exemple
Lucrul cu OpenAI API

System vs. assistant vs. user

System → formatarea importantă a șablonului

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

Assistant → conversații exemplu

User → context pentru noul input (adesea single-turn)

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

Job Title: Data Engineer
...
Lucrul cu OpenAI API

Să exersăm!

Lucrul cu OpenAI API

Preparing Video For Download...