Rezumarea și editarea textului

Lucrul cu DeepSeek în Python

James Chapman

AI Curriculum Lead, DataCamp

Recapitulare...

  • Q&A
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  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...
Lucrul cu DeepSeek în Python

Editarea textului

  • Exemplu: actualizarea numelui, a pronumelor și a titlului postului

$$

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.
"""
Lucrul cu DeepSeek în Python

Editarea textului

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

messages=[{"role": "user", "content": prompt}]
) print(response.choices[0].message.content)
Here's the updated text with the requested changes:

Maarten is a Senior Content Developer at DataCamp. His favorite programming language
is R, which he uses for his statistical analyses.

Let me know if you'd like any further adjustments!
Lucrul cu DeepSeek în Python

Rezumarea textului

  • Exemplu: rezumatul transcrierilor conversațiilor cu clienții

Echipă de asistență pentru clienți

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?  
...
"""
Lucrul cu DeepSeek în Python

Rezumarea textului

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


response = client.chat.completions.create( model="deepseek-ai/DeepSeek-V4.1-Flash", messages=[{"role": "user", "content": prompt}] ) print(response.choices[0].message.content)
1. **Login Issue**: Customer couldn't log in due to a password issue and missing reset link.  
2. **Password Reset Suggestion**: Support resent the reset email after confirming it was sent.  
3. **Prompt Assistance**: Customer resolved the issue by using Google sign-in.
Lucrul cu DeepSeek în Python

Controlul lungimii răspunsului

  • max_tokens = 5
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  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-V4.1-Flash",
    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.**
Lucrul cu DeepSeek în Python

Înțelegerea token-urilor

$$

  • Tokens: unități de text care ajută AI-ul să înțeleagă și să interpreteze textul

$$

Propoziția "How can the OpenAI API deliver business value?" cu fiecare token evidențiat într-o culoare diferită.

1 https://lunary.ai/deepseek-tokenizer
Lucrul cu DeepSeek în Python

Calcularea costului

 

  • Costurile de utilizare a API-ului depind de platformă, model și numărul de token-uri 💰

    • Modelele sunt tarifate pe baza cost/token-uri
    • Token-urile de intrare și de ieșire pot avea costuri diferite
  • Creșterea max_tokens crește costul 📈

Screenshot 2025-03-05 at 11.46.54.png

Lucrul cu DeepSeek în Python

Calcularea costului

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-V4.1-Flash",
    messages=[{"role": "user", "content": prompt}], 
    max_tokens=max_tokens
)
Lucrul cu DeepSeek în Python

Calcularea costului

# Define price per token
input_token_price = 2.1 / 1_000_000
output_token_price = 4.4 / 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.0153964
Lucrul cu DeepSeek în Python

Hai să exersăm!

Lucrul cu DeepSeek în Python

Preparing Video For Download...