AI-modellen bevragen met Databricks

Databricks met de Python SDK

Avi Steinberg

Senior Software Engineer

Foundation Models

Afbeelding Foundation Model

  • Grote, voorgetrainde neurale netwerken
  • Getraind op diverse, grote datasets
  • Gehost op of buiten Databricks
1 https://docs.databricks.com/aws/en/machine-learning/model-serving/foundation-model-overview
Databricks met de Python SDK

Populaire chat-completionmodellen

Gehost buiten Databricks:

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

OpenAI ChatGPT

Anthropic Claude

Google Gemini

Gehost op Databricks:

  • Meta Llama

$$

Databricks Meta Llama

Databricks met de Python SDK

Databricks Meta Llama

  • Meta werkt met Databricks om Meta Llama te hosten op Databricks
  • Large Language Model (LLM), gebouwd en getraind door Meta
  • Concurreert qua performance met 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 met de Python SDK

Serving endpoints

  • Bestaan al voor Foundation-modellen die op Databricks gehost worden
  • Kunnen gemaakt worden voor externe en eigen modellen
  • Met de Databricks SDK kun je Foundation Models bevragen

Serving Endpoint

1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks met de Python SDK

Serving endpoints API

  • Laat je AI-modellen bevragen via API-verzoeken naar de bijbehorende Serving Endpoint
  • Toegang via het attribuut serving_endpoints van de WorkspaceClient
1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks met de Python SDK

Chatberichtenrollen

SYSTEM:

Instructies voor hoe het model moet antwoorden

USER:

Vragen die de gebruiker naar het model stuurt

Voorbeeldprompt:

"You are a helpful python coding assistant."

Voorbeeldprompt:

"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 met de Python SDK

Chatmodellen bevragen met 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 met de Python SDK

Laten we oefenen!

Databricks met de Python SDK

Preparing Video For Download...