Tvůj první požadavek

Introduction to Claude Models

Nikhil Rangarajan

Data Scientist

Co je knihovna Anthropic?

  • Oficiální Python SDK pro přístup ke Claude

  • Pomáhá strukturovat interakce s Claude

  • Instalace přes pip:

    pip install anthropic
    
  • Import knihovny:

    import anthropic
    

Diagram začínající promptem, pokračující přes Anthropic API k modelu Claude

Introduction to Claude Models

Autentizace a nastavení

$$

import anthropic

client = anthropic.Anthropic( api_key=os.getenv("ANTHROPIC_API_KEY") )

$$

🔑 Klíč není v cvičeních kurzu potřeba

Introduction to Claude Models

Odesíláme první prompt

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 Sonnet
  • max_tokens: Omezuje velikost výstupu (přibližně 4 znaky na token v angličtině.)
    • Token: nejmenší jednotka textu, kterou model zpracovává
  • messages: Seznam interakcí začínající vstupem uživatele
Introduction to Claude Models

Extrakce výstupu modelu

  • response - Celá strukturovaná odpověď API
  • response.content - Vrací seznam částí zprávy
    [{'type': 'text', 
    'text': 'Claude is...'}]
    
  • response.content[0].text - Odpověď asistenta
    "Claude is..."
    
Introduction to Claude Models

Vše dohromady

import anthropic


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)
Introduction to Claude Models

Vše dohromady

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) 
Introduction to Claude Models

Vše dohromady

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) 
Introduction to Claude Models

Vše dohromady

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) 
Introduction to Claude Models

Vše dohromady

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
Introduction to Claude Models

Pojďme cvičit!

Introduction to Claude Models

Preparing Video For Download...