Riepilogo ed editing di testo

Lavorare con DeepSeek in Python

James Chapman

Curriculum Manager, DataCamp

Riepilogo...

  • Q&A
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V3",
  messages=[{"role": "user", "content": "How many days are in October?"}]
)

print(response.choices[0].message.content)
October has **31 days**.  

It's one of the seven months in the Gregorian calendar with 31 days...
Lavorare con DeepSeek in Python

Editing di testo

  • Esempio: aggiornare nome, pronomi e job title

$$

prompt = """
Update name to Maarten, pronouns to he/him, and job title to Senior Content Developer
in the following text:

Joanne is a Content Developer at DataCamp. Her favorite programming language is R,
which she uses for her statistical analyses.
"""
Lavorare con DeepSeek in Python

Editing di testo

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3",

messages=[{"role": "user", "content": prompt}]
) print(response.choices[0].message.content)
Ecco il testo aggiornato con le modifiche richieste:

Maarten è Senior Content Developer in DataCamp. Il suo linguaggio di programmazione preferito
è R, che usa per le sue analisi statistiche.

Fammi sapere se vuoi altre modifiche!
Lavorare con DeepSeek in Python

Riepilogo di testo

  • Esempio: sintesi di trascrizioni di chat con clienti

Team di supporto clienti

text = """
Customer: Hi, I'm trying to log into 
my account, but it keeps saying 
my password is incorrect. I'm sure 
I'm entering the right one.  

Support: I'm sorry to hear that! 
Have you tried resetting your password?  
...
"""
Lavorare con DeepSeek in Python

Riepilogo di testo

prompt = f"""Summarize the customer support chat 
             in three concise key points: {text}"""


response = client.chat.completions.create( model="deepseek-ai/DeepSeek-V3", messages=[{"role": "user", "content": prompt}] ) print(response.choices[0].message.content)
1. **Problema di accesso**: l'utente non riesce a entrare per password errata e link di reset mancante.  
2. **Suggerimento reset**: il supporto reinvia l'email di reset dopo averne verificato l'invio.  
3. **Assistenza rapida**: l'utente risolve accedendo con Google.
Lavorare con DeepSeek in Python

Controllare la lunghezza della risposta

  • max_tokens = 5
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V3",
  messages=[{"role":"user",
      "content":"Write a haiku about AI."}],
  max_tokens=5
)

**Silent circuits hum
  • max_tokens = 30
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3",
    messages=[{"role":"user",
      "content":"Write a haiku about AI."}],
    max_tokens=30
)

**Silent circuits hum,**  
**thoughts of light and logic bloom—**  
**minds beyond our own.**
Lavorare con DeepSeek in Python

Capire i token

$$

  • Token: unità di testo che aiutano l'IA a comprendere e interpretare il testo

$$

La frase "How can the OpenAI API deliver business value?" con ogni token evidenziato in un colore diverso.

1 https://lunary.ai/deepseek-tokenizer
Lavorare con DeepSeek in Python

Calcolare il costo

 

  • I costi API dipendono da piattaforma, modello e numero di token 💰

    • I modelli sono prezzati per costo/token
    • Token in input e output possono avere costi diversi
  • Aumentare max_tokens aumenta il costo 📈

Screenshot 2025-03-05 at 11.46.54.png

Lavorare con DeepSeek in Python

Calcolare il costo

prompt = f"""Summarize the customer support chat 
             in three concise key points: {text}"""

max_tokens = 500

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3",
    messages=[{"role": "user", "content": prompt}], 
    max_tokens=max_tokens
)
Lavorare con DeepSeek in Python

Calcolare il costo

# Define price per token
input_token_price = 1.25 / 1_000_000
output_token_price = 1.25 / 1_000_000

# Extract token usage input_tokens = response.usage.prompt_tokens
output_tokens = max_tokens
# Calculate cost cost = (input_tokens * input_token_price + output_tokens * output_token_price) print(f"Estimated cost: ${cost}")
Estimated cost: $0.00848
Lavorare con DeepSeek in Python

Ayo berlatih!

Lavorare con DeepSeek in Python

Preparing Video For Download...