开始使用免费开始使用

查找并替换

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

本练习是课程的一部分

在 Python 中使用 DeepSeek

查看课程

练习说明

  • 创建一次请求,将 prompt 发送到 deepseek-ai/DeepSeek-V4-Pro,把一段关于汽车的文本改写为关于飞机;最多使用 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-Pro",
  messages=[{"role": "user", "____": ____}],
  ____
)

# Extract and print the response text
print(response.choices[0].____.____)
编辑并运行代码