开始使用免费开始使用

查找并替换

查找替换工具已经存在数十年,但它们通常只能识别并替换完全匹配的词或短语。现在您拿到了一段关于汽车的文本,您将使用聊天补全模型把它改写为关于飞机的内容,并进行相应的上下文调整。

本练习是课程的一部分

在 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].____.____)
编辑并运行代码