Wykorzystanie roli asystenta

Praca z API OpenAI

James Chapman

Curriculum Manager, DataCamp

Uzupełnienia czatu dla zadań jednoetapowych

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: kontroluje zachowanie asystenta
  • User: instruuje asystenta
  • Assistant: odpowiedź na instrukcję użytkownika
Praca z API OpenAI

Podawanie przykładów

 

  • Naprowadzenie modelu we właściwym kierunku
  • Podawanie wiadomości asystenta to bardziej ustrukturyzowana forma shot-promptingu
  • Przykład: Korepetytor programowania w Pythonie
    • Przykładowe pytania i odpowiedzi użytkownika

Sowa zajmująca się data science.

Praca z API OpenAI

Podawanie przykładów

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?"}] )
Praca z API OpenAI

Odpowiedź

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).
  • Eksperymentuj z liczbą przykładów
Praca z API OpenAI

System vs. asystent vs. użytkownik

System → ważne formatowanie szablonu

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

Assistant → przykładowe rozmowy

User → kontekst wymagany dla nowego wejścia (często jednoetapowe)

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

Job Title: Data Engineer
...
Praca z API OpenAI

Czas na ćwiczenia!

Praca z API OpenAI

Preparing Video For Download...