เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การเพิ่มข้อความของ assistant

Chat model เหมาะอย่างยิ่งสำหรับสร้างแอปพลิเคชันเชิงสนทนา และสามารถพัฒนาให้ดียิ่งขึ้นได้ด้วยการระบุตัวอย่างบทสนทนาให้โมเดลใช้เป็นฐาน

ปรับปรุงแอปพลิเคชันติวเตอร์ภูมิศาสตร์นี้ โดยเพิ่มตัวอย่างคำถามของนักเรียนและคำตอบที่ต้องการลงใน messages:

  • คำถามตัวอย่าง: Give me a quick summary of Portugal.
  • คำตอบตัวอย่าง: Portugal is a country in Europe that borders Spain. The capital city is Lisboa.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การทำงานกับ OpenAI API

ดูคอร์ส

คำแนะนำการฝึกหัด

  • เพิ่มคำถามและคำตอบตัวอย่างที่กำหนดให้เป็นคู่ user-assistant ใน messages ที่ส่งไปยังโมเดล
    • คำถามตัวอย่าง: Give me a quick summary of Portugal.
    • คำตอบตัวอย่าง: Portugal is a country in Europe that borders Spain. The capital city is Lisboa.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

client = OpenAI(api_key="")

response = client.chat.completions.create(
    model="gpt-4o-mini",
    # Add a user and assistant message for in-context learning
    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 Greece."}
    ]
)

print(response.choices[0].message.content)
แก้ไขและรันโค้ด