Bắt đầu ngayBắt đầu miễn phí

Thêm nhiều thông điệp từ assistant!

Mở rộng các thông điệp trước đó của bạn để cung cấp thêm ví dụ, được lưu dưới dạng example1, response1, example2, response2, example3, và response3.

Hãy xem liệu chúng ta có thể khiến mô hình xuất ra thông tin đúng định dạng mong muốn không!

Bài tập này là một phần của khóa học

Làm việc với OpenAI API

Xem khóa học

Hướng dẫn bài tập

  • Mở rộng các thông điệp trước đó của bạn để bao gồm thêm các ví dụ về các quốc gia khác, được lưu dưới dạng example1, response1, example2, response2, example3, và response3.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

client = OpenAI(api_key="")

response = client.chat.completions.create(
   model="gpt-4o-mini",
   # Add in the extra examples and responses
   messages=[
       {"role": "system", "content": "You are a helpful Geography tutor that generates concise summaries for different countries."},
       {"role": "user", "content": "Give me a quick summary of Portugal."},
       {"role": "assistant", "content": "Portugal is a country in Europe that borders Spain. The capital city is Lisboa."},
       {"role": "user", "content": ____},
       {"role": "assistant", "content": ____},
       {"role": "user", "content": ____},
       {"role": "assistant", "content": ____},
       {"role": "user", "content": ____},
       {"role": "assistant", "content": ____},
       {"role": "user", "content": "Give me a quick summary of Greece."}
   ]
)

print(response.choices[0].message.content)
Chỉnh sửa và Chạy Mã