-
Notifications
You must be signed in to change notification settings - Fork 821
Add Databricks provider (AI Gateway / Foundation Model APIs) #1433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
prasadkona
wants to merge
2
commits into
anomalyco:dev
Choose a base branch
from
prasadkona:add-databricks-ai-gateway-provider
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * Shared types and helpers for Databricks AI Gateway discovery (system.ai FMA routes). | ||
| */ | ||
|
|
||
| import { WorkspaceClient } from "@databricks/sdk-experimental"; | ||
|
|
||
| export interface Destination { | ||
| name?: string; | ||
| type?: string; | ||
| } | ||
|
|
||
| export interface Endpoint { | ||
| name?: string; | ||
| ai_gateway_url?: string; | ||
| config?: { destinations?: Destination[] }; | ||
| } | ||
|
|
||
| export interface EndpointsResponse { | ||
| endpoints?: Endpoint[]; | ||
| } | ||
|
|
||
| export interface FilteredGatewayRoute { | ||
| gateway_name: string; | ||
| system_ai_destinations: string[]; | ||
| ai_gateway_url?: string; | ||
| } | ||
|
|
||
| export function isSystemAiFma(dest: Destination | undefined): boolean { | ||
| if (!dest) return false; | ||
| const t = dest.type ?? ""; | ||
| const name = dest.name ?? ""; | ||
| return t === "PAY_PER_TOKEN_FOUNDATION_MODEL" && name.startsWith("system.ai."); | ||
| } | ||
|
|
||
| export function filterEndpoints(endpoints: Endpoint[]): FilteredGatewayRoute[] { | ||
| const out: FilteredGatewayRoute[] = []; | ||
|
|
||
| for (const ep of endpoints) { | ||
| const name = ep.name ?? ""; | ||
| if (!name.startsWith("databricks-")) continue; | ||
| const dests = ep.config?.destinations ?? []; | ||
| const sysAi = dests | ||
| .filter(isSystemAiFma) | ||
| .map((d) => d.name!) | ||
| .filter(Boolean); | ||
| if (sysAi.length === 0) continue; | ||
| out.push({ | ||
| gateway_name: name, | ||
| system_ai_destinations: sysAi, | ||
| ai_gateway_url: ep.ai_gateway_url, | ||
| }); | ||
| } | ||
| out.sort((a, b) => a.gateway_name.localeCompare(b.gateway_name)); | ||
| return out; | ||
| } | ||
|
|
||
| export async function fetchFilteredGatewayRoutes( | ||
| client: WorkspaceClient, | ||
| ): Promise<FilteredGatewayRoute[]> { | ||
| const raw = (await client.apiClient.request( | ||
| { | ||
| path: "/api/ai-gateway/v2/endpoints", | ||
| method: "GET", | ||
| headers: new Headers(), | ||
| raw: false, | ||
| }, | ||
| undefined, | ||
| )) as EndpointsResponse; | ||
|
|
||
| return filterEndpoints(raw.endpoints ?? []); | ||
| } | ||
|
|
||
| /** OpenAI-compatible base URL for chat/embeddings (no trailing slash). */ | ||
| export function mlflowOpenAiBaseUrl(aiGatewayUrl: string): string { | ||
| const u = aiGatewayUrl.replace(/\/$/, ""); | ||
| return `${u}/mlflow/v1`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env bun | ||
| /** | ||
| * List Databricks AI Gateway routes aligned with Unity Catalog system.ai foundation models. | ||
| * | ||
| * Uses Databricks WorkspaceClient (JavaScript SDK; same auth patterns as ~/.databrickscfg, profiles, env). | ||
| * | ||
| * Usage (from repo root): | ||
| * bun run databricks:list-gateway -- --profile YOUR_PROFILE | ||
| * bun run databricks:list-gateway -- --profile YOUR_PROFILE --json | ||
| */ | ||
|
|
||
| import { WorkspaceClient } from "@databricks/sdk-experimental"; | ||
| import { fetchFilteredGatewayRoutes } from "./databricks-ai-gateway-shared.js"; | ||
|
|
||
| function parseArgs() { | ||
| const argv = process.argv.slice(2); | ||
| let profile = process.env.DATABRICKS_CONFIG_PROFILE; | ||
| let json = false; | ||
| for (let i = 0; i < argv.length; i++) { | ||
| const a = argv[i]; | ||
| if (a === "--profile" && argv[i + 1]) { | ||
| profile = argv[++i]; | ||
| continue; | ||
| } | ||
| if (a === "--json") { | ||
| json = true; | ||
| continue; | ||
| } | ||
| if (a === "--help" || a === "-h") { | ||
| console.log(`Usage: list-databricks-ai-gateway.ts [--profile NAME] [--json] | ||
|
|
||
| --profile Databricks config profile (~/.databrickscfg). Default: DATABRICKS_CONFIG_PROFILE or SDK default chain. | ||
| --json Print JSON array instead of TSV lines. | ||
| `); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| return { profile, json }; | ||
| } | ||
|
|
||
| async function main() { | ||
| const { profile, json } = parseArgs(); | ||
|
|
||
| const client = new WorkspaceClient(profile ? { profile } : {}); | ||
| const rows = await fetchFilteredGatewayRoutes(client); | ||
|
|
||
| if (json) { | ||
| console.log(JSON.stringify(rows, null, 2)); | ||
| return; | ||
| } | ||
|
|
||
| const hostUrl = (await client.apiClient.host).toString(); | ||
| console.log(`# host: ${hostUrl}`); | ||
| console.log(`# count: ${rows.length}\n`); | ||
| for (const r of rows) { | ||
| console.log(`${r.gateway_name}\t${r.system_ai_destinations.join(", ")}`); | ||
| } | ||
| } | ||
|
|
||
| main().catch((e) => { | ||
| console.error(e); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm unsure how
packages/coreis used, but we prob wouldn't want to add databricks as a dependency for the core package right? wouldn't this be installed for all customers? this additional dependency probably belongs in a provider-specific folder