文字生成

使用 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

一個客服聊天機器人收到兩個語意相近的請求。

使用 Python 操作 DeepSeek

控制回應的隨機性

  • temperature:控制決定性,0(高度決定)到 2(非常隨機)
  • 啟用 reasoning 時會被靜默忽略 → 關閉後才可使用
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...