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

การสรุปข้อความ

อยากแปลงบทกวีให้กลายเป็นสรุปสั้น ๆ ไหม? มาลองทำกัน! คุณมีข้อความเต็มของบทกวีที่เก็บไว้ในตัวแปร string ชื่อ raven_text ซึ่งจะนำไปส่งให้ Chat AI model เพื่อให้สรุปบทกวีในจำนวนคำที่กำหนด

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

Databricks กับ Python SDK

ดูคอร์ส

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

  • ขอให้ AI agent สรุปบทกวีเรื่อง "The Raven" ของ Edgar Allan Poe
  • กำหนดชื่อโมเดลเป็น Meta Llama 3 ซึ่งบันทึกไว้ในตัวแปร ai_model แล้ว
  • สร้างข้อความที่ต้องการส่งไปยัง AI model โดยใส่ตัวแปร raven_text ด้วย
  • ใช้ chat message role ที่เหมาะสมสำหรับการส่งคำถามไปยัง AI model

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

w = WorkspaceClient()

ai_model = "databricks-meta-llama-3-3-70b-instruct"

# Summarize the poem
response = w.serving_endpoints.query(
  # Set model name
  name=____,  
  messages=[
    	# Create a chat message to send to the model
        ____(
          	# Specify the role for sending the query
            role=ChatMessageRole.____, content=f"Summarize this poem by Edgar Allan Poe: {____} in 3 bullet points"
        ),
    ],
  max_tokens=200)

print(f"RESPONSE:\n{response.choices[0].message.content}")
แก้ไขและรันโค้ด