Meringkas dan menyunting teks

Bekerja dengan DeepSeek di Python

James Chapman

AI Curriculum Lead, DataCamp

Ringkasan...

  • Tanya Jawab
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  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...
Bekerja dengan DeepSeek di Python

Penyuntingan teks

  • Contoh: memperbarui nama, kata ganti, dan jabatan

$$

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.
"""
Bekerja dengan DeepSeek di Python

Penyuntingan teks

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

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!
Bekerja dengan DeepSeek di Python

Peringkasan teks

  • Contoh: ringkasan transkrip chat pelanggan

Tim dukungan pelanggan

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?  
...
"""
Bekerja dengan DeepSeek di Python

Peringkasan teks

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


response = client.chat.completions.create( model="deepseek-ai/DeepSeek-V4-Pro", messages=[{"role": "user", "content": prompt}] ) print(response.choices[0].message.content)
1. **Masalah Login**: Pelanggan tidak bisa masuk karena masalah kata sandi dan tautan reset tidak diterima.  
2. **Saran Reset Kata Sandi**: Dukungan mengirim ulang email reset setelah konfirmasi pengiriman.  
3. **Bantuan Cepat**: Masalah teratasi dengan masuk menggunakan Google.
Bekerja dengan DeepSeek di Python

Mengontrol panjang respons

  • max_tokens = 5
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  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-Pro",
    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.**
Bekerja dengan DeepSeek di Python

Memahami token

$$

  • Token: unit teks yang membantu AI memahami dan menafsirkan teks

$$

Kalimat, "How can the OpenAI API deliver business value?" dengan tiap token disorot warna berbeda.

1 https://lunary.ai/deepseek-tokenizer
Bekerja dengan DeepSeek di Python

Menghitung biaya

 

  • Biaya penggunaan API bergantung pada platform, model, dan jumlah token 💰

    • Model dihargai per biaya/token
    • Token masukan dan keluaran dapat berbeda biaya
  • Menaikkan max_tokens meningkatkan biaya 📈

Screenshot 2025-03-05 at 11.46.54.png

Bekerja dengan DeepSeek di Python

Menghitung biaya

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-Pro",
    messages=[{"role": "user", "content": prompt}], 
    max_tokens=max_tokens
)
Bekerja dengan DeepSeek di Python

Menghitung biaya

# 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
Bekerja dengan DeepSeek di Python

Ayo berlatih!

Bekerja dengan DeepSeek di Python

Preparing Video For Download...