การระบุโมเดล DeepSeek
OpenAI มีหลายโมเดลให้เลือกใช้ตามจุดประสงค์ที่แตกต่างกัน ในแบบฝึกหัดนี้ จะได้ระบุโมเดลและกำหนด role เพื่อจัดโครงสร้างคำขอ API
คลาส OpenAI ถูก import ให้แล้วจากไลบรารี openai
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การใช้งาน DeepSeek ใน Python
คำแนะนำการฝึกหัด
- ระบุโมเดล
deepseek-ai/DeepSeek-V4-Pro - กำหนด role ที่ถูกต้องในลิสต์
messages
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
response = client.chat.completions.create(
# Specify the model
model="____",
max_tokens=400,
messages=[
# Assign the correct role
{"role": "____",
"content": "Write a post to announce my new AI Engineer role on LinkedIn. Only output the post."}]
)
print(response.choices[0].message.content)