テキスト生成

Python で DeepSeek を使いこなす

James Chapman

AI Curriculum Lead, DataCamp

出力はどのように生成されるのか?

  • 会話を完成させる可能性が最も高いテキスト
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash",

messages=[{"role": "user", "content": "Hi! I'm James and I'm a Curriculum Manager at DataCamp."}]
) print(response.choices[0].message.content)
Hi James! It's great to meet you. As a **Curriculum Manager at DataCamp**, you must
play a key role in shaping the learning experience for data science and analytics
students. How can I assist you today?
  • 応答は非決定的(本質的にランダム)です
Python で DeepSeek を使いこなす

意味的に類似した2つのリクエストを受け取るカスタマーサポートチャットボット

Python で DeepSeek を使いこなす

応答のランダム性を制御する

  • temperature: 決定性を制御するパラメータ。0(非常に決定的)から2(非常にランダム)まで
  • 推論が有効な場合は黙って無視される → 使用するには無効にする
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash",
    extra_body={"thinking": {"type": "disabled"}},
    messages=[{"role": "user",
             "content": "Hi! I'm James and I'm a Curriculum Manager at DataCamp."}],

temperature=2
) print(response.choices[0].message.content)
Hi James! Welcome to DataCamp - it's great to connect with someone who works on
shaping learning experiences for data skills. What does your role typically involve
as a Curriculum Manager at **DataCamp?** Perhaps one-on95 kWielpulses.Z.blog.from...
Python で DeepSeek を使いこなす

テキスト生成: マーケティング

prompt = "Generate a powerful tagline for a new electric vehicle 
that highlights innovation and sustainability."
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash",
    messages=[{"role": "user", "content": prompt}]
)

print(response.choices[0].message.content)
**"Drive the Future - Zero Emissions, Infinite Innovation."**  
This tagline captures the essence of cutting-edge technology and eco-conscious...
Python で DeepSeek を使いこなす

応答のクリーンアップ

prompt = "Generate a powerful tagline for a new electric vehicle 
that highlights innovation and sustainability. Return only the tagline
without formatting."

# Create a request to the chat model
# ...
"Drive the Future - Clean, Smart, Electric."
Python で DeepSeek を使いこなす

テキスト生成: 商品説明

prompt = """Write a compelling e-commmerce product description for the UltraFit
Smartwatch in paragraph form. Highlight its key features:

10-day battery life, 24/7 heart rate and sleep tracking, built-in GPS, water
resistance up to 50 meters, and lightweight design.

Use a persuasive and engaging tone to appeal to fitness enthusiasts and busy
professionals.
"""

response = client.chat.completions.create( model="deepseek-ai/DeepSeek-V4.1-Flash", messages=[{"role": "user", "content": prompt}])
Python で DeepSeek を使いこなす

テキスト生成: 商品説明

print(response.choices[0].message.content)
"The UltraFit Smartwatch is your all-in-one health and fitness companion. 
Stay on top of your wellness with 24/7 heart rate and sleep tracking, 
while the built-in GPS keeps you on course during runs. 
With a 10-day battery life, you can track your progress without constant recharging. 
Designed for both workouts and daily wear, its  lightweight build and 50-meter
water resistance make it the perfect smartwatch for an active lifestyle."
  • 繰り返しましょう! プロンプトに詳細を加えてリクエストを再実行しましょう
  • 次の動画 → モデルに例を提示する
Python で DeepSeek を使いこなす

練習しましょう!

Python で DeepSeek を使いこなす

Preparing Video For Download...