Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Von Bedeutung
Dieses Feature befindet sich in der Betaversion. Kontoadministratoren können den Zugriff auf dieses Feature über die Seite " Vorschau" der Kontokonsole steuern. Siehe Manage Azure Databricks Previews.
Auf dieser Seite wird beschrieben, wie Sie Unity AI Gateway-Endpunkte mithilfe unterstützter APIs abfragen.
Anforderungen
- Unity AI Gateway Preview für Ihr Konto aktiviert. Siehe Manage Azure Databricks Previews.
- Ein Azure Databricks-Arbeitsbereich in einer von Unity AI Gateway unterstützten Region.
- Unity-Katalog für Ihren Arbeitsbereich aktiviert. Weitere Informationen finden Sie unter Aktivieren eines Arbeitsbereichs für Unity Catalog.
Unterstützte APIs und Integrationen
Unity AI Gateway unterstützt die folgenden APIs und Integrationen:
- Unified APIs: OpenAI-kompatible Schnittstellen zu Abfragemodellen auf Azure Databricks. Wechseln Sie nahtlos zwischen Modellen von verschiedenen Anbietern, ohne zu ändern, wie Sie jedes Modell abfragen.
- Systemeigene APIs: Anbieterspezifische Schnittstellen für den Zugriff auf die neuesten Modell- und anbieterspezifischen Features.
- Coding-Agenten: Integrieren Sie Ihre Coding-Agenten in das Unity AI Gateway, um Ihren KI-unterstützten Entwicklungsarbeitsabläufen zentrale Governance und Überwachung hinzuzufügen. Siehe Integration mit Coding-Agenten.
- AI Agents auf Databricks-Apps: Erstellen und Bereitstellen von AI Agents auf Databricks-Apps, die LLM-Datenverkehr über Unity AI Gateway weiterleiten. Siehe Schritt 4. Steuern Sie die LLM-Nutzung von Ihren Agents auf Databricks-Apps mit Unity AI Gateway.
Abfrageendpunkte mit einheitlichen APIs
Einheitliche APIs bieten eine openAI-kompatible Schnittstelle für Abfragemodelle auf Azure Databricks. Verwenden Sie einheitliche APIs, um nahtlos zwischen Modellen von verschiedenen Anbietern zu wechseln, ohne Ihren Code zu ändern.
MLflow-Chatabschluss-API
MLflow-Chatabschluss-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="<ai-gateway-endpoint>",
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": "<ai-gateway-endpoint>",
"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
Ersetzen Sie <workspace-url> durch Ihre AZURE DATABRICKS Arbeitsbereichs-URL und <ai-gateway-endpoint> durch ihren Unity AI Gateway-Endpunktnamen.
MLflow Embeddings-API
Die 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="<ai-gateway-endpoint>"
)
print(embeddings.data[0].embedding)
REST API
curl \
-u token:$DATABRICKS_TOKEN \
-X POST \
-H "Content-Type: application/json" \
-d '{
"model": "<ai-gateway-endpoint>",
"input": "What is Databricks?"
}' \
https://<workspace-url>/ai-gateway/mlflow/v1/embeddings
Ersetzen Sie <workspace-url> durch Ihre AZURE DATABRICKS Arbeitsbereichs-URL und <ai-gateway-endpoint> durch ihren Unity AI Gateway-Endpunktnamen.
Supervisor-API
Supervisor-API
Die Supervisor-API (/mlflow/v1/responses) ist eine openResponses-kompatible, anbieteragnostische API zum Erstellen von Agents in Beta. Kontoadministratoren können den Zugriff über die Vorschauseite aktivieren. Siehe Manage Azure Databricks Previews. Wählen Sie das beste Modell für Ihren Agent-Anwendungsfall für Anbieter aus, ohne Ihren Code zu ändern.
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="<ai-gateway-endpoint>",
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": "<ai-gateway-endpoint>",
"input": [
{"role": "user", "content": "What is Databricks?"}
]
}' \
https://<workspace-url>/ai-gateway/mlflow/v1/responses
Ersetzen Sie <workspace-url> durch Ihre AZURE DATABRICKS Arbeitsbereichs-URL und <ai-gateway-endpoint> durch ihren Unity AI Gateway-Endpunktnamen.
Abfragen von Endpunkten mit systemeigenen APIs
Systemeigene APIs bieten anbieterspezifische Schnittstellen für Abfragemodelle auf Azure Databricks. Verwenden Sie systemeigene APIs, um auf die neuesten anbieterspezifischen Features zuzugreifen.
OpenAI-Antwort-API
OpenAI-Antworten-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="<ai-gateway-endpoint>",
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": "<ai-gateway-endpoint>",
"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
Ersetzen Sie <workspace-url> durch Ihre AZURE DATABRICKS Arbeitsbereichs-URL und <ai-gateway-endpoint> durch ihren Unity AI Gateway-Endpunktnamen.
Anthropic Nachrichten-API
Anthropische Nachrichten-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="<ai-gateway-endpoint>",
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": "<ai-gateway-endpoint>",
"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
Ersetzen Sie <workspace-url> durch Ihre AZURE DATABRICKS Arbeitsbereichs-URL und <ai-gateway-endpoint> durch ihren Unity AI Gateway-Endpunktnamen.
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="<ai-gateway-endpoint>",
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/<ai-gateway-endpoint>:generateContent
Ersetzen Sie <workspace-url> durch Ihre AZURE DATABRICKS Arbeitsbereichs-URL und <ai-gateway-endpoint> durch ihren Unity AI Gateway-Endpunktnamen.
Nächste Schritte
- Unity AI Gateway für Agents und LLMs
- Konfigurieren von Unity AI Gateway-Endpunkten
- Integration mit Programmieragenten
-
Supervisor-API (Beta) – Ausführen von Multi-Turn-Agent-Workflows mit gehosteten Tools über
/mlflow/v1/responses
Schritt 4. Verwalten Sie die Nutzung von LLM für Ihre Agents in Databricks-Apps über das Unity AI Gateway. — Weiterleiten von LLM-Anrufen von Agents auf Databricks-Apps über Unity AI Gateway