เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ค้นหาและแทนที่

เครื่องมือค้นหาและแทนที่มีมาหลายทศวรรษแล้ว แต่มักจำกัดอยู่แค่การระบุและแทนที่คำหรือวลีที่ตรงกันเท่านั้น ในแบบฝึกหัดนี้ได้เตรียมข้อความที่พูดถึงรถยนต์ไว้ให้แล้ว และจะใช้โมเดล chat completion เพื่ออัปเดตข้อความนั้นให้พูดถึงเครื่องบินแทน พร้อมปรับเนื้อหาให้เหมาะสม

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การใช้งาน DeepSeek ใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้างคำขอเพื่อส่ง prompt ไปยัง deepseek-ai/DeepSeek-V4-Pro โดยแก้ไขข้อความเกี่ยวกับรถยนต์ให้เป็นเรื่องของเครื่องบินแทน และกำหนดจำนวนโทเคนสูงสุดที่ 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-Pro",
  messages=[{"role": "user", "____": ____}],
  ____
)

# Extract and print the response text
print(response.choices[0].____.____)
แก้ไขและรันโค้ด