Truy vấn mô hình AI với Databricks

Databricks với Python SDK

Avi Steinberg

Senior Software Engineer

Foundation Models

Hình Foundation Model

  • Mạng nơ-ron lớn, tiền huấn luyện
  • Huấn luyện trên nhiều tập dữ liệu lớn, đa dạng
  • Lưu trữ trên Databricks hoặc bên ngoài Databricks
1 https://docs.databricks.com/aws/en/machine-learning/model-serving/foundation-model-overview
Databricks với Python SDK

Các mô hình chat completion phổ biến

Lưu trữ ngoài Databricks:

  • ChatGPT của OpenAI
  • Claude của Anthropic
  • Gemini của Google Cloud

OpenAI ChatGPT

Anthropic Claude

Google Gemini

Lưu trữ trên Databricks:

  • Meta Llama

$$

Databricks Meta Llama

Databricks với Python SDK

Databricks Meta Llama

  • Meta hợp tác với Databricks để lưu trữ Meta Llama trên Databricks
  • Mô hình ngôn ngữ lớn (LLM) do Meta xây dựng và huấn luyện
  • Hiệu năng cạnh tranh với 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 với Python SDK

Serving endpoints

  • Đã có sẵn cho Foundation Models được lưu trữ trên Databricks
  • Có thể tạo cho mô hình bên ngoài và mô hình tùy chỉnh
  • Có thể dùng Databricks SDK để truy vấn Foundation Models

Serving Endpoint

1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks với Python SDK

Serving endpoints API

  • Cho phép truy vấn mô hình AI bằng các yêu cầu API tới Serving Endpoint tương ứng
  • Truy cập qua thuộc tính serving_endpoints của WorkspaceClient
1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks với Python SDK

Vai trò tin nhắn chat

SYSTEM:

Hướng dẫn cách mô hình phản hồi truy vấn

USER:

Truy vấn người dùng gửi cho mô hình

Ví dụ prompt:

"Bạn là trợ lý lập trình Python hữu ích."

Ví dụ prompt:

"Vòng lặp for hoạt động thế nào trong Python?"

1 https://databricks-sdk-py.readthedocs.io/en/stable/dbdataclasses/serving.html#databricks.sdk.service.serving.ChatMessageRole
Databricks với Python SDK

Truy vấn mô hình chat với 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 với Python SDK

Ayo berlatih!

Databricks với Python SDK

Preparing Video For Download...