모델 서비스 조회

Important

이 기능은 베타 버전으로 제공됩니다. 계정 관리자는 계정 콘솔 미리 보기 페이지에서 이 기능에 대한 액세스를 제어할 수 있습니다. Azure Databricks 미리 보기 관리를 참조하세요.

이 페이지에서는 지원되는 API를 사용하여 Unity 카탈로그에서 모델 서비스를 쿼리하는 방법을 설명합니다.

Requirements

지원되는 API 및 통합

Unity AI Gateway는 다음 API 및 통합을 지원합니다.

를 사용하여 모델 서비스 쿼리 ai_query

이 함수를 ai_query 사용하여 SQL 또는 Python 직접 Azure Databricks 제공된 모델 서비스를 쿼리할 수 있습니다. 이렇게 하면 일괄 처리 유추 워크로드에 대한 사용량 추적 정보를 캡처할 수 있습니다.

메모

  • ai_queryUnity AI Gateway에 대한 지원은 Azure Databricks 제공된 모델 서비스(예: databricks-gpt-5-4 또는databricks-claude-sonnet-4)에만 사용할 수 있습니다. Unity AI Gateway에서 만드는 모델 서비스는 아직 지원되지 않습니다.
  • 사용량 추적만 일괄 처리 유추 워크로드에 적용 ai_query 됩니다. 속도 제한, 가드레일, 유추 테이블 및 대체와 같은 다른 Unity AI 게이트웨이 기능은 적용되지 않습니다.

시작하려면:

  1. 계정에 대한 Unity AI Gateway 미리 보기를 사용하도록 설정합니다. Azure Databricks 미리 보기 관리를 참조하세요.
  2. 다음을 사용하여 ai_queryAzure Databricks 제공 모델 서비스를 쿼리합니다.
SELECT ai_query(
  'databricks-gpt-5-4',
  'Summarize the following text: ' || text_column
) AS summary
FROM my_table
LIMIT 10

ai_query Azure Databricks 제공된 모델 서비스에 대한 요청은 사용량 추적 시스템 테이블(system.ai_gateway.usage)에서 캡처됩니다. 이러한 요청은 기본 제공 사용 대시보드에도 표시됩니다.

전체 ai_query 구문 및 매개 변수 참조는 함수를 참조 ai_query 하세요. 모범 사례 및 지원되는 모델은 사용 ai_query을(를) 참조하세요.

통합 API를 사용하여 모델 서비스 쿼리

통합 API는 Azure Databricks에서 모델을 쿼리하는 OpenAI 호환 인터페이스를 제공합니다. 통합 API를 사용하여 코드를 변경하지 않고도 서로 다른 공급자의 모델 간에 원활하게 전환할 수 있습니다.

MLflow 채팅 완료 API

MLflow 채팅 완료 API

Python

from openai import OpenAI
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = OpenAI(
  api_key=DATABRICKS_TOKEN,
  base_url="https://<workspace-url>/ai-gateway/mlflow/v1"
)

chat_completion = client.chat.completions.create(
  messages=[
    {"role": "user", "content": "Hello!"},
    {"role": "assistant", "content": "Hello! How can I assist you today?"},
    {"role": "user", "content": "What is Databricks?"},
  ],
  model="<model-service>",
  max_tokens=256
)

print(chat_completion.choices[0].message.content)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-service>",
    "max_tokens": 256,
    "messages": [
      {"role": "user", "content": "Hello!"},
      {"role": "assistant", "content": "Hello! How can I assist you today?"},
      {"role": "user", "content": "What is Databricks?"}
    ]
  }' \
  https://<workspace-url>/ai-gateway/mlflow/v1/chat/completions

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

MLflow Embeddings API

MLflow Embeddings API

Python

from openai import OpenAI
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = OpenAI(
  api_key=DATABRICKS_TOKEN,
  base_url="https://<workspace-url>/ai-gateway/mlflow/v1"
)

embeddings = client.embeddings.create(
  input="What is Databricks?",
  model="<model-service>"
)

print(embeddings.data[0].embedding)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-service>",
    "input": "What is Databricks?"
  }' \
  https://<workspace-url>/ai-gateway/mlflow/v1/embeddings

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

감독자 API

감독자 API

감독자 API(/mlflow/v1/responses)는 베타에서 에이전트를 빌드하기 위한 OpenResponses 호환 공급자 중립적 API입니다. 계정 관리자는 미리 보기 페이지에서 액세스를 사용하도록 설정할 수 있습니다. Azure Databricks 미리 보기 관리를 참조하세요. 코드를 변경하지 않고 공급자 전체에서 에이전트 사용 사례에 가장 적합한 모델을 선택합니다.

Python

from openai import OpenAI
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = OpenAI(
  api_key=DATABRICKS_TOKEN,
  base_url="https://<workspace-url>/ai-gateway/mlflow/v1"
)

response = client.responses.create(
  model="<model-service>",
  input=[{"role": "user", "content": "What is Databricks?"}]
)

print(response.output_text)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-service>",
    "input": [
      {"role": "user", "content": "What is Databricks?"}
    ]
  }' \
  https://<workspace-url>/ai-gateway/mlflow/v1/responses

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

네이티브 API를 사용하여 모델 서비스 쿼리

네이티브 API는 Azure Databricks에서 모델을 쿼리하는 공급자별 인터페이스를 제공합니다. 네이티브 API를 사용하여 최신 공급자별 기능에 액세스합니다.

OpenAI 응답 API

OpenAI 응답 API

Python

from openai import OpenAI
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = OpenAI(
  api_key=DATABRICKS_TOKEN,
  base_url="https://<workspace-url>/ai-gateway/openai/v1"
)

response = client.responses.create(
  model="<model-service>",
  max_output_tokens=256,
  input=[
    {
      "role": "user",
      "content": [{"type": "input_text", "text": "Hello!"}]
    },
    {
      "role": "assistant",
      "content": [{"type": "output_text", "text": "Hello! How can I assist you today?"}]
    },
    {
      "role": "user",
      "content": [{"type": "input_text", "text": "What is Databricks?"}]
    }
  ]
)

print(response.output)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-service>",
    "max_output_tokens": 256,
    "input": [
      {
        "role": "user",
        "content": [{"type": "input_text", "text": "Hello!"}]
      },
      {
        "role": "assistant",
        "content": [{"type": "output_text", "text": "Hello! How can I assist you today?"}]
      },
      {
        "role": "user",
        "content": [{"type": "input_text", "text": "What is Databricks?"}]
      }
    ]
  }' \
  https://<workspace-url>/ai-gateway/openai/v1/responses

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

Anthropic 메시지 API

인류 메시지 API

Python

import anthropic
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = anthropic.Anthropic(
  api_key="unused",
  base_url="https://<workspace-url>/ai-gateway/anthropic",
  default_headers={
    "Authorization": f"Bearer {DATABRICKS_TOKEN}",
  },
)

message = client.messages.create(
  model="<model-service>",
  max_tokens=256,
  messages=[
    {"role": "user", "content": "Hello!"},
    {"role": "assistant", "content": "Hello! How can I assist you today?"},
    {"role": "user", "content": "What is Databricks?"},
  ],
)

print(message.content[0].text)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-service>",
    "max_tokens": 256,
    "messages": [
      {"role": "user", "content": "Hello!"},
      {"role": "assistant", "content": "Hello! How can I assist you today?"},
      {"role": "user", "content": "What is Databricks?"}
    ]
  }' \
  https://<workspace-url>/ai-gateway/anthropic/v1/messages

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

Google Gemini API

Google Gemini API

Python

from google import genai
from google.genai import types
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = genai.Client(
  api_key="databricks",
  http_options=types.HttpOptions(
    base_url="https://<workspace-url>/ai-gateway/gemini",
    headers={
      "Authorization": f"Bearer {DATABRICKS_TOKEN}",
    },
  ),
)

response = client.models.generate_content(
  model="<model-service>",
  contents=[
    types.Content(
      role="user",
      parts=[types.Part(text="Hello!")],
    ),
    types.Content(
      role="model",
      parts=[types.Part(text="Hello! How can I assist you today?")],
    ),
    types.Content(
      role="user",
      parts=[types.Part(text="What is Databricks?")],
    ),
  ],
  config=types.GenerateContentConfig(
    max_output_tokens=256,
  ),
)

print(response.text)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Hello!"}]
      },
      {
        "role": "model",
        "parts": [{"text": "Hello! How can I assist you today?"}]
      },
      {
        "role": "user",
        "parts": [{"text": "What is Databricks?"}]
      }
    ],
    "generationConfig": {
      "maxOutputTokens": 256
    }
  }' \
  https://<workspace-url>/ai-gateway/gemini/v1beta/models/<model-service>:generateContent

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

사용량 추적에 대한 태그 요청

HTTP 헤더를 사용하여 개별 요청에 사용자 지정 키-값 태그를 Databricks-Ai-Gateway-Request-Tags 연결할 수 있습니다. 요청 태그는 request_tags 시스템 테이블과 유추 테이블의 열에 기록 되므로 프로젝트, 팀, 환경 또는 기타 차원별로 비용, 특성 사용량 및 필터 분석을 추적할 수 있습니다.

헤더 값은 문자열 값에 문자열 키를 매핑하는 JSON 개체여야 합니다. 다음은 그 예입니다.

{ "project": "chatbot", "team": "ml-platform", "environment": "production" }

extra_headers 매개 변수(Python)를 사용하거나 헤더를 직접 전달(REST API)하여 태그를 요청에 연결합니다.

Python(OpenAI SDK)

from openai import OpenAI
import json
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = OpenAI(
  api_key=DATABRICKS_TOKEN,
  base_url="https://<workspace-url>/ai-gateway/mlflow/v1"
)

request_tags = {"project": "chatbot", "team": "ml-platform"}

chat_completion = client.chat.completions.create(
  messages=[
    {"role": "user", "content": "What is Databricks?"},
  ],
  model="<model-service>",
  max_tokens=256,
  extra_headers={
    "Databricks-Ai-Gateway-Request-Tags": json.dumps(request_tags)
  }
)

Python(Anthropic SDK)

import anthropic
import json
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

request_tags = {"project": "chatbot", "team": "ml-platform"}

client = anthropic.Anthropic(
  api_key="unused",
  base_url="https://<workspace-url>/ai-gateway/anthropic",
  default_headers={
    "Authorization": f"Bearer {DATABRICKS_TOKEN}",
    "Databricks-Ai-Gateway-Request-Tags": json.dumps(request_tags),
  },
)

message = client.messages.create(
  model="<model-service>",
  max_tokens=256,
  messages=[
    {"role": "user", "content": "What is Databricks?"},
  ],
)

REST API

curl \
  -u token:$DATABRICKS_TOKEN \
  -X POST \
  -H "Content-Type: application/json" \
  -H 'Databricks-Ai-Gateway-Request-Tags: {"project": "chatbot", "team": "ml-platform"}' \
  -d '{
    "model": "<model-service>",
    "max_tokens": 256,
    "messages": [
      {"role": "user", "content": "What is Databricks?"}
    ]
  }' \
  https://<workspace-url>/ai-gateway/mlflow/v1/chat/completions

<workspace-url>를 Azure Databricks 워크스페이스 URL로 바꾸고 <model-service>를 모델 서비스의 정규화된 전체 이름으로 바꾸세요.

다음 단계