messages = [
{"role": "user", "content": "Hello, can you help me with Python programming?"}
]
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=messages,
extra_headers={"x-maxim-trace-id": trace_id}
)
# Extract response text
response_text = response.content[0].text
print(response_text)
# Continue the conversation - add assistant's response to messages
messages.append({"role": "assistant", "content": response_text})
messages.append({"role": "user", "content": "Can you write a simple Python function?"})
# Make another call with the same trace_id to continue the conversation
response2 = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=messages,
extra_headers={"x-maxim-trace-id": trace_id}
)
response_text2 = response2.content[0].text
print(response_text2)