Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/dataclassification/src/v1/model.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export interface CatalogConfig {
| {
$case: 'includedSchemas';
/**
* Schemas to include in the scan. Empty list is not supported as it results in a no-op
* scan. If `included_schemas` is not set, all schemas are scanned.
* Schemas to include in the scan, each named relative to the parent catalog.
* If specified, only listed schemas will be scanned.
* Mutually exclusive with `excluded_schemas`: only one may be set per request.
* If neither `included_schemas` nor `excluded_schemas` is set, all schemas are scanned.
*/
includedSchemas: CatalogConfig_SchemaNames;
}
Expand All @@ -59,6 +61,7 @@ export interface CatalogConfig {
/** Wrapper message for a list of schema names. */
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
export interface CatalogConfig_SchemaNames {
/** Schema names, each relative to the parent catalog. Must not be empty. */
names?: string[] | undefined;
}

Expand Down
38 changes: 38 additions & 0 deletions packages/genie/src/v1/client.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import {
buildHttpRequest,
executeCall,
executeHttpCall,
sendAndCheckError,
marshalRequest,
parseResponse,
executeWait,
StillRunningError,
} from './utils';
import pkgJson from '../../package.json' with {type: 'json'};
import type {
DownloadMessageAttachmentVisualizationRequest,
DownloadMessageAttachmentVisualizationResponse,
GenieCreateConversationMessageRequest,
GenieCreateEvalRunRequest,
GenieCreateMessageCommentRequest,
Expand Down Expand Up @@ -158,6 +161,41 @@ export class GenieClient {
return resp;
}

/**
* Download a rendered image of a message visualization attachment.
* The response body is the raw PNG image, not a JSON payload.
* This is only available if the attachment is a visualization and the message status is `COMPLETED`.
*/
async downloadMessageAttachmentVisualization(
req: DownloadMessageAttachmentVisualizationRequest,
options?: CallOptions
): Promise<DownloadMessageAttachmentVisualizationResponse> {
const {host, workspaceId, httpClient} = await this.resolveConfig();
const url = `${host}/api/2.0/genie/${req.name ?? ''}/download-visualization`;
let resp: DownloadMessageAttachmentVisualizationResponse | undefined;
const call = async (callSignal?: AbortSignal): Promise<void> => {
const headers = new Headers();
if (workspaceId !== undefined) {
headers.set('X-Databricks-Workspace-Id', workspaceId);
}
headers.set('User-Agent', this.userAgent);
const httpReq = buildHttpRequest('GET', url, headers, callSignal);
const httpResp = await sendAndCheckError({
request: httpReq,
httpClient,
logger: this.logger,
});
resp = {
contents: httpResp.body ?? undefined,
};
};
await executeCall(call, options);
if (resp === undefined) {
throw new Error('operation completed without a result.');
}
return resp;
}

/**
* Create new message in a [conversation](:method:genie/startconversation).
* The AI response uses all previously created messages in the conversation to respond.
Expand Down
3 changes: 3 additions & 0 deletions packages/genie/src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type {
ColumnInfo,
ColumnMask,
DatabricksServiceExceptionProto,
DownloadMessageAttachmentVisualizationRequest,
DownloadMessageAttachmentVisualizationResponse,
ExternalLink,
GenieAttachment,
GenieConversation,
Expand Down Expand Up @@ -86,6 +88,7 @@ export type {
GenieSuggestedQuestionsAttachment,
GenieTrashSpaceRequest,
GenieUpdateSpaceRequest,
GenieVizAttachment,
ListValue,
MapStringValueEntry,
MessageError,
Expand Down
56 changes: 55 additions & 1 deletion packages/genie/src/v1/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,22 @@ export interface DatabricksServiceExceptionProto {
stackTrace?: string | undefined;
}

export interface DownloadMessageAttachmentVisualizationRequest {
/**
* The resource name of the attachment to render, in the format
* `spaces/{space_id}/conversations/{conversation_id}/messages/{message_id}/attachments/{attachment_id}`.
*/
name?: string | undefined;
}

export interface DownloadMessageAttachmentVisualizationResponse {
/**
* The rendered visualization as a PNG image. Returned as the raw HTTP
* response body rather than a JSON field.
*/
contents?: ReadableStream | undefined;
}

export interface ExternalLink {
/**
* A URL pointing to a
Expand Down Expand Up @@ -986,6 +1002,11 @@ export interface GenieAttachment {
/** Follow-up questions suggested by Genie */
suggestedQuestions: GenieSuggestedQuestionsAttachment;
}
| {
$case: 'viz';
/** Visualization generated by Genie, if requested via `enable_visualization` */
viz: GenieVizAttachment;
}
| undefined;
/** Attachment ID */
attachmentId?: string | undefined;
Expand Down Expand Up @@ -1024,6 +1045,8 @@ export interface GenieCreateConversationMessageRequest {
conversationId?: string | undefined;
/** User message content. */
content?: string | undefined;
/** Enable visualization generation. */
enableVisualization?: boolean | undefined;
}

export interface GenieCreateEvalRunRequest {
Expand Down Expand Up @@ -1567,6 +1590,8 @@ export interface GenieStartConversationRequest {
spaceId?: string | undefined;
/** The text of the message that starts the conversation. */
content?: string | undefined;
/** Enable visualization generation. */
enableVisualization?: boolean | undefined;
}

export interface GenieStartConversationResponse {
Expand Down Expand Up @@ -1613,6 +1638,17 @@ export interface GenieUpdateSpaceRequest {
parentPath?: string | undefined;
}

/**
* Visualization generated by Genie for a query result. Use the attachment ID
* with the download visualization API to retrieve the rendered image.
*/
export interface GenieVizAttachment {
/** Name of the visualization */
title?: string | undefined;
/** The ID of the query attachment the visualization was generated from */
queryAttachmentId?: string | undefined;
}

/**
* copied from proto3 / Google Well Known Types, source:
* https://github.com/protocolbuffers/protobuf/blob/450d24ca820750c5db5112a6f0b0c2efb9758021/src/google/protobuf/struct.proto
Expand Down Expand Up @@ -1986,6 +2022,7 @@ export const unmarshalGenieAttachmentSchema: z.ZodType<GenieAttachment> = z
suggested_questions: z
.lazy(() => unmarshalGenieSuggestedQuestionsAttachmentSchema)
.optional(),
viz: z.lazy(() => unmarshalGenieVizAttachmentSchema).optional(),
attachment_id: z.string().optional(),
})
.transform(d => ({
Expand All @@ -1999,7 +2036,9 @@ export const unmarshalGenieAttachmentSchema: z.ZodType<GenieAttachment> = z
$case: 'suggestedQuestions' as const,
suggestedQuestions: d.suggested_questions,
}
: undefined,
: d.viz !== undefined
? {$case: 'viz' as const, viz: d.viz}
: undefined,
attachmentId: d.attachment_id,
}));

Expand Down Expand Up @@ -2450,6 +2489,17 @@ export const unmarshalGenieSuggestedQuestionsAttachmentSchema: z.ZodType<GenieSu
questions: d.questions,
}));

export const unmarshalGenieVizAttachmentSchema: z.ZodType<GenieVizAttachment> =
z
.object({
title: z.string().optional(),
query_attachment_id: z.string().optional(),
})
.transform(d => ({
title: d.title,
queryAttachmentId: d.query_attachment_id,
}));

export const unmarshalListValueSchema: z.ZodType<ListValue> = z
.object({
values: z.array(z.lazy(() => unmarshalValueSchema)).optional(),
Expand Down Expand Up @@ -2684,11 +2734,13 @@ export const marshalGenieCreateConversationMessageRequestSchema: z.ZodType = z
spaceId: z.string().optional(),
conversationId: z.string().optional(),
content: z.string().optional(),
enableVisualization: z.boolean().optional(),
})
.transform(d => ({
space_id: d.spaceId,
conversation_id: d.conversationId,
content: d.content,
enable_visualization: d.enableVisualization,
}));

export const marshalGenieCreateEvalRunRequestSchema: z.ZodType = z
Expand Down Expand Up @@ -2793,10 +2845,12 @@ export const marshalGenieStartConversationRequestSchema: z.ZodType = z
.object({
spaceId: z.string().optional(),
content: z.string().optional(),
enableVisualization: z.boolean().optional(),
})
.transform(d => ({
space_id: d.spaceId,
content: d.content,
enable_visualization: d.enableVisualization,
}));

export const marshalGenieUpdateSpaceRequestSchema: z.ZodType = z
Expand Down
35 changes: 35 additions & 0 deletions packages/genie/src/v1/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,38 @@ export function flattenQueryParams(
throw new Error(`Unsupported query parameter type: ${typeof value}`);
}
}

/**
* Sends an HTTP request and checks for API errors. On non-2xx responses the
* body is buffered and parsed into an ApiError. On 2xx the raw HttpResponse
* is returned with the body stream untouched.
*/
export async function sendAndCheckError(
opts: HttpCallOptions
): Promise<HttpResponse> {
opts.logger.debug('HTTP request', {
method: opts.request.method,
url: opts.request.url,
});

let resp: HttpResponse;
try {
resp = await opts.httpClient.send(opts.request);
} catch (e: unknown) {
opts.logger.debug('HTTP request failed');
throw e;
}

opts.logger.debug('HTTP response', {statusCode: resp.statusCode});

if (resp.statusCode < 200 || resp.statusCode >= 300) {
const body = await readAll(resp.body);
const apiErr = ApiError.fromHttpError(resp.statusCode, resp.headers, body);
if (apiErr !== undefined) {
throw apiErr;
}
throw new Error(`unexpected HTTP status ${String(resp.statusCode)}`);
}

return resp;
}
2 changes: 2 additions & 0 deletions packages/modelserving/src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export type {
ServedModel,
ServedModelLite,
ServedModelState,
TelemetryConfig,
TelemetryInferenceTableConfig,
TrafficConfig,
UpdateInferenceEndpointNotificationsRequest,
UpdateInferenceEndpointNotificationsResponse,
Expand Down
Loading
Loading