Cari dan ganti
Alat cari-dan-ganti sudah ada selama beberapa dekade, tetapi biasanya hanya mampu mengenali dan mengganti kata atau frasa yang persis sama. Anda diberikan satu blok teks yang membahas mobil, dan Anda akan menggunakan model chat completion untuk memperbarui teks tersebut agar membahas pesawat, dengan penyesuaian yang tepat pada teksnya.
Latihan ini adalah bagian dari kursus
Bekerja dengan DeepSeek di Python
Petunjuk latihan
- Buat permintaan untuk mengirim
promptkedeepseek-ai/DeepSeek-V3, mengubah sebuah paragraf tentang mobil menjadi tentang pesawat; gunakan maksimum100token. - Ekstrak dan cetak teks respons dari API.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
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].____.____)