การสอบถาม AI โมเดลด้วย Databricks

Databricks กับ Python SDK

Avi Steinberg

Senior Software Engineer

Foundation Models

ภาพ Foundation Model

  • โครงข่ายประสาทเทียมขนาดใหญ่ที่ผ่านการฝึกมาแล้ว
  • ฝึกด้วยชุดข้อมูลขนาดใหญ่ที่หลากหลาย
  • โฮสต์บน Databricks หรือภายนอก Databricks
1 https://docs.databricks.com/aws/en/machine-learning/model-serving/foundation-model-overview
Databricks กับ Python SDK

โมเดล chat completion ยอดนิยม

โฮสต์ภายนอก Databricks:

  • OpenAI's ChatGPT
  • Anthropic's Claude
  • Google Cloud's Gemini

OpenAI ChatGPT

Anthropic Claude

Google Gemini

โฮสต์บน Databricks:

  • Meta Llama

$$

Databricks Meta Llama

Databricks กับ Python SDK

Databricks Meta Llama

  • Meta ร่วมมือกับ Databricks เพื่อโฮสต์ Meta Llama บน Databricks
  • Large Language Model (LLM) ที่สร้างและฝึกโดย Meta
  • ประสิทธิภาพเทียบเคียง OpenAI GPT

Databricks Meta Llama

1 1. https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/supported-models#meta-llama-3-3-70b-instruct 2. https://www.databricks.com/product/pricing/foundation-model-serving
Databricks กับ Python SDK

Serving endpoints

  • มีอยู่แล้วสำหรับ Foundation Models ที่โฮสต์บน Databricks
  • สร้างขึ้นเองได้สำหรับโมเดลภายนอกและโมเดลแบบกำหนดเอง
  • ใช้ Databricks SDK เพื่อสอบถาม Foundation Models ได้

Serving Endpoint

1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks กับ Python SDK

Serving endpoints API

  • ช่วยให้สอบถาม AI โมเดลได้โดยส่ง API request ไปยัง Serving Endpoint ที่เกี่ยวข้อง
  • เข้าถึงได้ผ่าน attribute serving_endpoints ของ WorkspaceClient
1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks กับ Python SDK

บทบาทของข้อความใน chat

SYSTEM:

คำสั่งกำหนดวิธีที่โมเดลตอบสนองต่อคำถาม

USER:

คำถามที่ผู้ใช้ส่งให้โมเดล

ตัวอย่าง prompt:

"You are a helpful python coding assistant."

ตัวอย่าง prompt:

"How do for loops work in Python?"

1 https://databricks-sdk-py.readthedocs.io/en/stable/dbdataclasses/serving.html#databricks.sdk.service.serving.ChatMessageRole
Databricks กับ Python SDK

การสอบถาม chat โมเดลด้วย Databricks

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import ChatMessage, ChatMessageRole
w = WorkspaceClient()
response = w.serving_endpoints.query(
    name="databricks-meta-llama-3-3-70b-instruct",
    messages=[
        ChatMessage(
            role=ChatMessageRole.SYSTEM, content="You are a helpful assistant."
        ),
        ChatMessage(role=ChatMessageRole.USER, content="<your-question>"),
    ],
    max_tokens=128)
print(f"RESPONSE:\n{response.choices[0].message.content}")
1 https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/supported-models#meta-llama-33-70b-instruct
Databricks กับ Python SDK

มาฝึกกันเถอะ!

Databricks กับ Python SDK

Preparing Video For Download...