Wprowadzenie do modeli Claude
Nikhil Rangarajan
Data Scientist
Oficjalne SDK Pythona do obsługi Claude
Ułatwia komunikację z Claude
Instalacja przez pip:
pip install anthropic
Importowanie biblioteki:
import anthropic

$$
import anthropicclient = anthropic.Anthropic( api_key=os.getenv("ANTHROPIC_API_KEY") )
$$
🔑 Klucz nie jest potrzebny w ćwiczeniach kursu
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: Ogranicza rozmiar odpowiedzi (ok. 4 znaki na token w języku angielskim.)messages: Lista interakcji zaczynająca się od zapytania użytkownikaresponse — pełna strukturalna odpowiedź APIresponse.content — zwraca listę części wiadomości[{'type': 'text',
'text': 'Claude is...'}]
response.content[0].text — odpowiedź asystenta"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 #Importowanie
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 #Importowanie
client = anthropic.Anthropic() #Inicjalizacja
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 #Importowanie
client = anthropic.Anthropic() #Inicjalizacja
response = client.messages.create( #Zapytanie
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 #Importowanie
client = anthropic.Anthropic() #Inicjalizacja
response = client.messages.create( #Zapytanie
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) #Wyodrębnianie
Wprowadzenie do modeli Claude