Introduzione ai modelli Claude
Nikhil Rangarajan
Data Scientist
SDK Python ufficiale per accedere a Claude
Aiuta a strutturare le interazioni con Claude
Installazione con pip:
pip install anthropic
Import della libreria:
import anthropic

$$
import anthropicclient = anthropic.Anthropic( api_key=os.getenv("ANTHROPIC_API_KEY") )
$$
🔑 Chiave non necessaria negli esercizi del corso
response = client.messages.create(model="claude-sonnet-4-6",max_tokens=100,messages=[{"role": "user", "content": "What DataCamp course do you recommend to learn Claude?"}])
model: Claude Sonnetmax_tokens: Limita la dimensione dell'output (circa 4 caratteri per token in inglese)messages: Elenco di interazioni che parte dall'input dell'utenteresponse - Risposta API completa e strutturataresponse.content - Restituisce una lista di parti del messaggio[{'type': 'text',
'text': 'Claude is...'}]
response.content[0].text - Risposta dell'assistente"Claude is..."
import anthropicclient = anthropic.Anthropic()response = client.messages.create( model="claude-sonnet-4-6", max_tokens=100, messages=[{"role": "user", "content": "Summarize the benefits of Claude in one sentence."}] )print(response.content[0].text)
import anthropic #Importing
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=100,
messages=[{"role": "user",
"content": "Summarize the benefits of Claude in one sentence."}]
)
print(response.content[0].text)
import anthropic #Importing
client = anthropic.Anthropic() #Initializing
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=100,
messages=[{"role": "user",
"content": "Summarize the benefits of Claude in one sentence."}]
)
print(response.content[0].text)
import anthropic #Importing
client = anthropic.Anthropic() #Initializing
response = client.messages.create( #Requesting
model="claude-sonnet-4-6",
max_tokens=100,
messages=[{"role": "user",
"content": "Summarize the benefits of Claude in one sentence."}]
)
print(response.content[0].text)
import anthropic #Importing
client = anthropic.Anthropic() #Initializing
response = client.messages.create( #Requesting
model="claude-sonnet-4-6",
max_tokens=100,
messages=[{"role": "user",
"content": "Summarize the benefits of Claude in one sentence."}]
)
print(response.content[0].text) #Extracting
Introduzione ai modelli Claude