텍스트 요약 및 편집

Python으로 DeepSeek 활용하기

James Chapman

AI Curriculum Lead, DataCamp

복습...

  • 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...
Python으로 DeepSeek 활용하기

텍스트 편집

  • 예시: 이름, 대명사, 직함 업데이트

$$

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.
"""
Python으로 DeepSeek 활용하기

텍스트 편집

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!
Python으로 DeepSeek 활용하기

텍스트 요약

  • 예시: 고객 채팅 기록 요약

고객 지원팀

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?  
...
"""
Python으로 DeepSeek 활용하기

텍스트 요약

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.
Python으로 DeepSeek 활용하기

응답 길이 제어

  • 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.**
Python으로 DeepSeek 활용하기

토큰 이해하기

$$

  • 토큰: AI가 텍스트를 이해하고 해석하도록 돕는 텍스트 단위

$$

문장 "How can the OpenAI API deliver business value?"에서 각 토큰이 서로 다른 색으로 강조 표시된 모습

1 https://lunary.ai/deepseek-tokenizer
Python으로 DeepSeek 활용하기

비용 계산하기

 

  • API 사용 비용은 플랫폼, 모델, 토큰 수에 따라 달라집니다 💰

    • 모델은 비용/토큰 기준으로 가격이 책정됩니다
    • 입력 토큰과 출력 토큰의 비용이 다를 수 있습니다
  • max_tokens를 늘리면 비용이 증가합니다 📈

Screenshot 2025-03-05 at 11.46.54.png

Python으로 DeepSeek 활용하기

비용 계산하기

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
)
Python으로 DeepSeek 활용하기

비용 계산하기

# 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
Python으로 DeepSeek 활용하기

연습해 봅시다!

Python으로 DeepSeek 활용하기

Preparing Video For Download...