Bắt đầu ngayBắt đầu miễn phí

Tìm và thay thế

Công cụ tìm-và-thay thế đã có từ nhiều thập kỷ, nhưng thường chỉ giới hạn ở việc nhận diện và thay thế đúng các từ hoặc cụm từ khớp hoàn toàn. Bạn được cung cấp một đoạn văn nói về ô tô, và bạn sẽ dùng một mô hình chat completion để cập nhật đoạn văn đó sang nói về máy bay, đồng thời điều chỉnh nội dung cho phù hợp.

Bài tập này là một phần của khóa học

Làm việc với DeepSeek trong Python

Xem khóa học

Hướng dẫn bài tập

  • Tạo một yêu cầu để gửi prompt đến deepseek-ai/DeepSeek-V4.1-Flash, chuyển đổi một đoạn văn về ô tô thành về máy bay; sử dụng tối đa 100 tokens.
  • Trích xuất và in ra văn bản phản hồi từ API.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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].____.____)
Chỉnh sửa và Chạy Mã