Khai thác vai trò assistant

Làm việc với OpenAI API

James Chapman

Curriculum Manager, DataCamp

Chat completions cho tác vụ một lượt

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: điều khiển hành vi của assistant
  • User: chỉ dẫn cho assistant
  • Assistant: phản hồi yêu cầu của user
Làm việc với OpenAI API

Cung cấp ví dụ

 

  • Hướng mô hình đi đúng hướng
  • Cung cấp tin nhắn assistant là dạng shot-prompting có cấu trúc hơn
  • Ví dụ: Gia sư Lập trình Python
    • Câu hỏi và trả lời mẫu của người dùng

Một con cú khoa học dữ liệu.

Làm việc với OpenAI API

Cung cấp ví dụ

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?"}] )
Làm việc với OpenAI API

Phản hồi

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).
  • Thử nghiệm số lượng ví dụ
Làm việc với OpenAI API

System vs. assistant vs. user

System → định dạng mẫu quan trọng

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

Assistant → hội thoại minh họa

User → ngữ cảnh cần cho đầu vào mới (thường một lượt)

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

Job Title: Data Engineer
...
Làm việc với OpenAI API

Ayo berlatih!

Làm việc với OpenAI API

Preparing Video For Download...