使用 Claude 进行分析型问题求解
推广活动很成功,网站流量上涨了 40%,但付费订阅仅增加了 5%。请启用 Claude 的扩展思考来解析这一不匹配:详细分析将为 SkyTrack 的下一轮增长冲刺提供依据。
anthropic 库和 client 已预加载。
本练习是课程的一部分
Claude 模型入门
练习说明
- 编写一个用于分析性思考的提示词。
- 在 API 调用中使用
thinking参数以开启扩展思考。 - 将
max_tokens设置为较高值(例如 1400),以便为 Claude 的推理和作答留出足够空间。 - 打印分析结果。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create an analytical thinking prompt
analysis_prompt = """
Analyze this business scenario and walk me through your reasoning:
Our website traffic increased 40% but sales only grew 5%.
___
Provide multiple possible explanations and rank them by likelihood.
"""
# Request detailed analytical thinking
response = client.messages.create(model="claude-sonnet-4-6", thinking=____, max_tokens=____, messages=[{"role": "user", "content": analysis_prompt}])
# Print the analysis results
print("Analysis results:")
print(response.content[0].thinking)