開始使用免費開始

尋找與取代

「尋找與取代」工具已經出現數十年,不過通常只能找到並取代完全相同的字詞或片語。你將拿到一段討論汽車的文字,並使用聊天補全模型把內容改寫為討論飛機,同時做出相對應且自然的文字更新。

本練習屬於課程

使用 Python 操作 DeepSeek

檢視課程

練習說明

  • 建立一個請求,將 prompt 傳送到 deepseek-ai/DeepSeek-V4.1-Flash,把一段關於汽車的文字改寫為關於飛機;使用最多 100 個 tokens。
  • 從 API 擷取並列印文字回應。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")

prompt="""Replace car with plane and adjust phrase:
A car is a vehicle that is typically powered by an internal combustion engine or an electric motor. It has four wheels, and is designed to carry passengers and/or cargo on roads or highways. Cars have become a ubiquitous part of modern society, and are used for a wide variety of purposes, such as commuting, travel, and transportation of goods. Cars are often associated with freedom, independence, and mobility."""

# Create a request to the chat model
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  messages=[{"role": "user", "____": ____}],
  ____
)

# Extract and print the response text
print(response.choices[0].____.____)
編輯並執行程式碼