Skip to main content

System Prompt and Multi-Turn Chat

System Prompt

import anthropic

client = anthropic.Anthropic(api_key="your-api-key", base_url="https://aisupermarket.work")

response = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
system="You are a professional Python programming assistant. Answer concisely and accurately.",
messages=[
{"role": "user", "content": "How do I read a file?"}
]
)
print(response.content[0].text)

Multi-Turn Chat

import anthropic

client = anthropic.Anthropic(api_key="your-api-key", base_url="https://aisupermarket.work")
messages = []

def chat(user_input):
messages.append({"role": "user", "content": user_input})
response = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
system="You are a friendly assistant.",
messages=messages
)
reply = response.content[0].text
messages.append({"role": "assistant", "content": reply})
return reply

print(chat("My name is Alex"))
print(chat("Do you remember my name?"))

Multimodal Content Blocks

system can be a string or an array of content blocks:

import anthropic

client = anthropic.Anthropic(api_key="your-api-key", base_url="https://aisupermarket.work")

response = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
system=[
{"type": "text", "text": "You are a coding assistant."},
{"type": "text", "text": "Always provide runnable code examples."}
],
messages=[{"role": "user", "content": "Write a quicksort implementation"}]
)
print(response.content[0].text)