Tóm tắt và chỉnh sửa văn bản

Làm việc với DeepSeek trong Python

James Chapman

AI Curriculum Lead, DataCamp

Tóm lược...

  • Hỏi & Đáp
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 có **31 ngày**.  

Đây là một trong bảy tháng theo lịch Gregorian có 31 ngày...
Làm việc với DeepSeek trong Python

Chỉnh sửa văn bản

  • Ví dụ: cập nhật tên, đại từ nhân xưng và chức danh công việc

$$

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.
"""
Làm việc với DeepSeek trong Python

Chỉnh sửa văn bản

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

messages=[{"role": "user", "content": prompt}]
) print(response.choices[0].message.content)
Dưới đây là văn bản đã được cập nhật theo yêu cầu:

Maarten là Senior Content Developer tại DataCamp. Ngôn ngữ lập trình yêu thích của anh ấy
là R, được anh ấy dùng cho các phân tích thống kê.

Hãy cho tôi biết nếu bạn muốn điều chỉnh thêm!
Làm việc với DeepSeek trong Python

Tóm tắt văn bản

  • Ví dụ: tóm tắt transcript chat với khách hàng

Nhóm hỗ trợ khách hàng

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?  
...
"""
Làm việc với DeepSeek trong Python

Tóm tắt văn bản

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. **Sự cố đăng nhập**: Khách hàng không đăng nhập được do vấn đề mật khẩu và thiếu liên kết đặt lại.  
2. **Gợi ý đặt lại mật khẩu**: Bộ phận hỗ trợ đã gửi lại email đặt lại sau khi xác nhận đã gửi.  
3. **Hỗ trợ kịp thời**: Khách hàng giải quyết bằng cách dùng đăng nhập Google.
Làm việc với DeepSeek trong Python

Kiểm soát độ dài phản hồi

  • 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
)

**Mạch lặng lẽ ngân
  • 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
)

**Mạch lặng lẽ ngân,**  
**ánh sáng, logic nảy mầm—**  
**trí vượt tầm ta.**
Làm việc với DeepSeek trong Python

Hiểu về token

$$

  • Token: đơn vị văn bản giúp AI hiểu và diễn giải nội dung

$$

Câu "How can the OpenAI API deliver business value?" với mỗi token được tô màu khác nhau.

1 https://lunary.ai/deepseek-tokenizer
Làm việc với DeepSeek trong Python

Tính chi phí

 

  • Chi phí dùng API phụ thuộc vào nền tảng, mô hình, và số token 💰

    • Mô hình được tính giá theo chi phí/token
    • Token đầu vào và đầu ra có thể có chi phí khác nhau
  • Tăng max_tokens sẽ tăng chi phí 📈

Screenshot 2025-03-05 at 11.46.54.png

Làm việc với DeepSeek trong Python

Tính chi phí

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
)
Làm việc với DeepSeek trong Python

Tính chi phí

# 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
Làm việc với DeepSeek trong Python

Cùng luyện tập nào!

Làm việc với DeepSeek trong Python

Preparing Video For Download...