Найти и заменить
Инструменты поиска и замены существуют уже десятилетиями, но обычно они умеют находить и заменять только точные слова или фразы. Вам предоставлен фрагмент текста про автомобили, и с помощью модели чат-завершений вы измените его так, чтобы речь шла про самолёты, соответствующим образом адаптировав содержание.
Это упражнение является частью курса
Работа с DeepSeek на Python
Инструкции к упражнению
- Создайте запрос, отправив
promptмоделиdeepseek-ai/DeepSeek-V4.1-Flash, чтобы преобразовать отрывок текста про автомобили в текст про самолёты; используйте не более100токенов. - Извлеките и выведите текстовый ответ от 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].____.____)