ควบคุมความสร้างสรรค์ด้วย temperature
คุณคือหัวหน้าทีมผลิตภัณฑ์ของ Luna Gear ที่กำลังเปิดตัวกระเป๋าเป้รักษ์โลก TerraPack ทีมต้องการแคปชันสำหรับทดสอบแบบ A/B สองเวอร์ชัน ได้แก่ เวอร์ชันที่เรียบร้อยและให้ข้อมูล กับเวอร์ชันที่สนุกและดึงดูดความสนใจ
ไลบรารี anthropic, client และสตริง product_info ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Claude Models เบื้องต้น
คำแนะนำการฝึกหัด
- กำหนดค่า
temperatureต่ำสำหรับผลลัพธ์ที่สม่ำเสมอและเป็นมืออาชีพ (0.1-0.3) - กำหนดค่า
temperatureสูงสำหรับผลลัพธ์ที่สร้างสรรค์และหลากหลาย (0.7-0.9) - แสดงผลเนื้อหาจาก conservative response และ creative response
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
conservative_response = client.messages.create(
# Conservative caption with low temperature
model="claude-sonnet-4-6", temperature=____, max_tokens=150,
messages=[{"role": "user",
"content": f"Write a professional caption for this product: {product_info}"}])
creative_response = client.messages.create(
# Creative caption with high temperature
model="claude-sonnet-4-6", temperature=____, max_tokens=150,
messages=[{"role": "user",
"content": f"Write a fun, engaging caption for this product: {product_info}"}])
# Print the Conservative and Creative Responses
print("Conservative caption:", ____)
print("\nCreative caption:", ____)