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

Kiểm soát tính sáng tạo bằng temperature

Bạn là product lead tại Luna Gear, đang ra mắt balo thân thiện môi trường TerraPack. Đội ngũ cần hai phiên bản caption để A/B test: một phiên bản chỉn chu, giàu thông tin và một phiên bản tinh nghịch, khuấy động.

Thư viện anthropic, client và chuỗi product_info đã được nạp sẵn.

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

Nhập môn các mô hình Claude

Xem khóa học

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

  • Đặt temperature thấp để cho ra nội dung chuyên nghiệp, nhất quán (0.1-0.3).
  • Đặt temperature cao để cho ra nội dung sáng tạo, đa dạng (0.7-0.9).
  • In nội dung phản hồi thận trọng và phản hồi sáng tạo.

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.

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:", ____)
Chỉnh sửa và Chạy Mã