Comece agoraComece grátis

Find and replace

Find-and-replace tools have been around for decades, but they are often limited to identifying and replacing exact words or phrases. You've been provided with a block of text discussing cars, and you'll use a chat completion model to update the text to discuss planes instead, updating the text appropriately.

Este exercicio faz parte do curso

Working with DeepSeek in Python

Ver curso

Instruções do exercicio

  • Create a request to send prompt to deepseek-ai/DeepSeek-V4-Pro, altering a passage of text about cars to planes; use a maximum of 100 tokens.
  • Extract and print the text response from the API.

exercicio interativo prático

Tente este exercicio completando este código de exemplo.

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].____.____)
Editar e Executar Código