Kiểm thử và tinh chỉnh system message
Tại Redwood Consulting, đội marketing đang quảng bá ấn phẩm whitepaper Tech Forecast thường niên trên LinkedIn. Bài đăng cần vừa trò chuyện tự nhiên vừa chuyên nghiệp, nhưng bản đầu tiên của bạn lại nhạt nhòa và không có hashtag. Bạn sẽ cần viết một system message cải tiến để luôn tạo ra nội dung sinh động, đúng thương hiệu.
Thư viện anthropic, client, content_request và chuỗi current_system đã đượ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
Hướng dẫn bài tập
- Thiết lập
rolecho nội dung yêu cầu của người dùng. - Viết một
improved_systemmessage đáp ứng yêu cầu mạng xã hội, bao gồm dùng emoji. - Áp dụng
improved_systemmessage cho bài kiểm thử cuối.
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.
# Test current system message
test_response = client.messages.create(
model="claude-sonnet-4-6", max_tokens=75, system=current_system,
messages=[{"role": ____, "content": content_request}])
print("Current output:", test_response.content[0].text)
# Create improved system message based on problems identified
improved_system = ____
final_response = client.messages.create(
# Apply the improved system message
model="claude-sonnet-4-6", max_tokens=75, system=____,
messages=[{"role": "user", "content": content_request}])
print("\nImproved output:", final_response.content[0].text)