텍스트 요약 및 편집

Python으로 DeepSeek 활용하기

James Chapman

AI Curriculum Lead, DataCamp

복습...

  • Q&A
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...
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-Pro",

messages=[{"role": "user", "content": prompt}]
) print(response.choices[0].message.content)
다음은 요청하신 변경 사항이 적용된 텍스트입니다:

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

추가 수정이 필요하시면 알려주세요!
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-Pro", messages=[{"role": "user", "content": prompt}] ) print(response.choices[0].message.content)
1. **로그인 문제**: 비밀번호 오류 및 재설정 링크 미수신으로 고객이 로그인하지 못함.  
2. **비밀번호 재설정 제안**: 상담원이 이메일 발송 여부를 확인 후 재설정 이메일을 재전송함.  
3. **문제 해결**: 고객이 Google 로그인을 통해 문제를 해결함.
Python으로 DeepSeek 활용하기

응답 길이 제어

  • 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.**
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-Pro",
    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...