Interogarea modelelor AI cu Databricks

Databricks cu Python SDK

Avi Steinberg

Senior Software Engineer

Modele Foundation

Imagine model Foundation

  • Rețele neuronale mari, pre-antrenate
  • Antrenate pe seturi de date variate și extinse
  • Găzduite pe Databricks sau în afara acestuia
1 https://docs.databricks.com/aws/en/machine-learning/model-serving/foundation-model-overview
Databricks cu Python SDK

Modele populare de completare chat

Găzduite în afara Databricks:

  • ChatGPT de la OpenAI
  • Claude de la Anthropic
  • Gemini de la Google Cloud

OpenAI ChatGPT

Anthropic Claude

Google Gemini

Găzduite pe Databricks:

  • Meta Llama

$$

Databricks Meta Llama

Databricks cu Python SDK

Databricks Meta Llama

  • Meta a colaborat cu Databricks pentru a găzdui Meta Llama pe Databricks
  • Model de limbaj de mari dimensiuni (LLM), creat și antrenat de Meta
  • Performanțe competitive cu 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 cu Python SDK

Endpoint-uri de servire

  • Există deja pentru modelele Foundation găzduite pe Databricks
  • Pot fi create pentru modele externe și personalizate
  • Se poate utiliza Databricks SDK pentru a interoga modelele Foundation

Serving Endpoint

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

API pentru endpoint-uri de servire

  • Permite interogarea modelelor AI prin cereri API către endpoint-ul de servire corespunzător
  • Accesat prin atributul serving_endpoints al WorkspaceClient
1 https://docs.databricks.com/api/workspace/servingendpoints
Databricks cu Python SDK

Roluri în mesajele de chat

SYSTEM:

Instrucțiuni privind modul în care modelul trebuie să răspundă la interogări

USER:

Interogări trimise modelului de către utilizator

Exemplu de prompt:

"You are a helpful python coding assistant."

Exemplu de 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 cu Python SDK

Interogarea modelelor de chat cu 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 cu Python SDK

Să exersăm!

Databricks cu Python SDK

Preparing Video For Download...