Tìm và thay thế
Công cụ tìm và thay thế đã tồn tại hàng thập kỷ, nhưng chúng thường chỉ giới hạn ở việc nhận diện và thay thế đúng từng từ hoặc cụm từ. Bạn được cung cấp một khối văn bản nói về ô tô, và bạn sẽ dùng một mô hình chat completion để cập nhật văn bản này sang chủ đề máy bay, đ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 bằng Python
Hướng dẫn bài tập
- Tạo một yêu cầu để gửi
promptđếndeepseek-ai/DeepSeek-V3, chuyển một đoạn văn bản về ô tô thành về máy bay; dùng tối đa100tokens. - Trích xuất và in 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-V3",
messages=[{"role": "user", "____": ____}],
____
)
# Extract and print the response text
print(response.choices[0].____.____)