Introducere în modelele Claude
Nikhil Rangarajan
Data Scientist
SDK-ul oficial Python pentru accesarea Claude
Ajută la structurarea interacțiunilor cu Claude
Instalare prin pip:
pip install anthropic
Importarea bibliotecii:
import anthropic

$$
import anthropicclient = anthropic.Anthropic( api_key=os.getenv("ANTHROPIC_API_KEY") )
$$
🔑 Cheia nu este necesară în exercițiile cursului
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: Limitează dimensiunea răspunsului (aproximativ 4 caractere per token în engleză.)messages: O listă de interacțiuni care începe cu mesajul utilizatoruluiresponse - Întregul răspuns structurat al API-uluiresponse.content - Returnează lista de părți ale mesajului[{'type': 'text',
'text': 'Claude is...'}]
response.content[0].text - Răspunsul asistentului"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
Introducere în modelele Claude