Skip to content
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

Try not flatten payload #2020

Merged
merged 13 commits into from
Sep 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import { KeyCredential } from '@azure/core-auth';
import { OperationOptions } from '@azure-rest/core-client';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface AddOrUpdateBlockItemsOptions {
blockItems: TextBlockItemInfo[];
}

// @public (undocumented)
export interface AddOrUpdateBlockItemsOptions {
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
blockItems: TextBlockItemInfo[];
}

// @public (undocumented)
export interface AddOrUpdateBlockItemsRequestOptions extends OperationOptions {
}
Expand All @@ -18,6 +28,13 @@ export interface AddOrUpdateBlockItemsResult {
value?: TextBlockItem[];
}

// @public
export interface AnalyzeImageOptions {
categories?: ImageCategory[];
image: ImageData_2;
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
outputType?: AnalyzeImageOutputType;
}

// @public
export type AnalyzeImageOutputType = string;

Expand All @@ -32,6 +49,15 @@ export interface AnalyzeImageResult {
analyzeResults: ImageAnalyzeSeverityResult[];
}

// @public
export interface AnalyzeTextOptions {
blocklistNames?: string[];
breakByBlocklists?: boolean;
categories?: TextCategory[];
outputType?: AnalyzeTextOutputType;
text: string;
}

// @public
export type AnalyzeTextOutputType = string;

Expand All @@ -52,16 +78,16 @@ export interface AnalyzeTextResult {
// @public (undocumented)
export class ContentSafetyClient {
constructor(endpoint: string, credential: KeyCredential | TokenCredential, options?: ContentSafetyClientOptions);
addOrUpdateBlockItems(blockItems: TextBlockItemInfo[], blocklistName: string, options?: AddOrUpdateBlockItemsRequestOptions): Promise<AddOrUpdateBlockItemsResult>;
analyzeImage(image: ImageData_2, options?: AnalyzeImageRequestOptions): Promise<AnalyzeImageResult>;
analyzeText(text: string, options?: AnalyzeTextRequestOptions): Promise<AnalyzeTextResult>;
createOrUpdateTextBlocklist(blocklistName: string, options?: CreateOrUpdateTextBlocklistOptions): Promise<TextBlocklist>;
addOrUpdateBlockItems(blocklistName: string, body: AddOrUpdateBlockItemsOptions, options?: AddOrUpdateBlockItemsRequestOptions): Promise<AddOrUpdateBlockItemsResult>;
analyzeImage(body: AnalyzeImageOptions, options?: AnalyzeImageRequestOptions): Promise<AnalyzeImageResult>;
analyzeText(body: AnalyzeTextOptions, options?: AnalyzeTextRequestOptions): Promise<AnalyzeTextResult>;
createOrUpdateTextBlocklist(blocklistName: string, resource: TextBlocklist, options?: CreateOrUpdateTextBlocklistOptions): Promise<TextBlocklist>;
deleteTextBlocklist(blocklistName: string, options?: DeleteTextBlocklistOptions): Promise<void>;
getTextBlocklist(blocklistName: string, options?: GetTextBlocklistOptions): Promise<TextBlocklist>;
getTextBlocklistItem(blocklistName: string, blockItemId: string, options?: GetTextBlocklistItemOptions): Promise<TextBlockItem>;
listTextBlocklistItems(blocklistName: string, options?: ListTextBlocklistItemsOptions): Promise<PagedTextBlockItem>;
listTextBlocklists(options?: ListTextBlocklistsOptions): Promise<PagedTextBlocklist>;
removeBlockItems(blockItemIds: string[], blocklistName: string, options?: RemoveBlockItemsRequestOptions): Promise<void>;
removeBlockItems(blocklistName: string, body: RemoveBlockItemsOptions, options?: RemoveBlockItemsRequestOptions): Promise<void>;
}

// @public (undocumented)
Expand Down Expand Up @@ -125,6 +151,16 @@ export interface PagedTextBlocklist {
value: TextBlocklist[];
}

// @public
export interface RemoveBlockItemsOptions {
blockItemIds: string[];
}

// @public (undocumented)
export interface RemoveBlockItemsOptions {
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
blockItemIds: string[];
}

// @public (undocumented)
export interface RemoveBlockItemsRequestOptions extends OperationOptions {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import { TokenCredential, KeyCredential } from "@azure/core-auth";
import {
AnalyzeTextOptions,
AnalyzeTextResult,
ImageData,
AnalyzeImageOptions,
AnalyzeImageResult,
TextBlocklist,
TextBlockItemInfo,
AddOrUpdateBlockItemsOptions,
AddOrUpdateBlockItemsResult,
TextBlockItem,
RemoveBlockItemsOptions,
PagedTextBlocklist,
PagedTextBlockItem,
} from "./models/models.js";
Expand Down Expand Up @@ -57,18 +59,18 @@ export class ContentSafetyClient {

/** A sync API for harmful content analysis for text. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
analyzeText(
text: string,
body: AnalyzeTextOptions,
options: AnalyzeTextRequestOptions = { requestOptions: {} }
): Promise<AnalyzeTextResult> {
return analyzeText(this._client, text, options);
return analyzeText(this._client, body, options);
}

/** A sync API for harmful content analysis for image. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
analyzeImage(
image: ImageData,
body: AnalyzeImageOptions,
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
options: AnalyzeImageRequestOptions = { requestOptions: {} }
): Promise<AnalyzeImageResult> {
return analyzeImage(this._client, image, options);
return analyzeImage(this._client, body, options);
}

/** Returns text blocklist details. */
Expand All @@ -82,9 +84,15 @@ export class ContentSafetyClient {
/** Updates a text blocklist, if blocklistName does not exist, create a new blocklist. */
createOrUpdateTextBlocklist(
blocklistName: string,
resource: TextBlocklist,
options: CreateOrUpdateTextBlocklistOptions = { requestOptions: {} }
): Promise<TextBlocklist> {
return createOrUpdateTextBlocklist(this._client, blocklistName, options);
return createOrUpdateTextBlocklist(
this._client,
blocklistName,
resource,
options
);
}

/** Deletes a text blocklist. */
Expand All @@ -104,25 +112,20 @@ export class ContentSafetyClient {

/** Add or update blockItems to a text blocklist. You can add or update at most 100 BlockItems in one request. */
addOrUpdateBlockItems(
blockItems: TextBlockItemInfo[],
blocklistName: string,
body: AddOrUpdateBlockItemsOptions,
options: AddOrUpdateBlockItemsRequestOptions = { requestOptions: {} }
): Promise<AddOrUpdateBlockItemsResult> {
return addOrUpdateBlockItems(
this._client,
blockItems,
blocklistName,
options
);
return addOrUpdateBlockItems(this._client, blocklistName, body, options);
}

/** Remove blockItems from a text blocklist. You can remove at most 100 BlockItems in one request. */
removeBlockItems(
blockItemIds: string[],
blocklistName: string,
body: RemoveBlockItemsOptions,
options: RemoveBlockItemsRequestOptions = { requestOptions: {} }
): Promise<void> {
return removeBlockItems(this._client, blockItemIds, blocklistName, options);
return removeBlockItems(this._client, blocklistName, body, options);
}

/** Get blockItem By blockItemId from a text blocklist. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Licensed under the MIT license.

import {
AnalyzeTextOptions,
AnalyzeTextResult,
ImageData,
AnalyzeImageOptions,
AnalyzeImageResult,
TextBlocklist,
TextBlockItemInfo,
AddOrUpdateBlockItemsOptions,
AddOrUpdateBlockItemsResult,
TextBlockItem,
RemoveBlockItemsOptions,
PagedTextBlocklist,
PagedTextBlockItem,
} from "../models/models.js";
Expand Down Expand Up @@ -57,19 +59,19 @@ import {

export function _analyzeTextSend(
context: Client,
text: string,
body: AnalyzeTextOptions,
options: AnalyzeTextRequestOptions = { requestOptions: {} }
): StreamableMethod<AnalyzeText200Response | AnalyzeTextDefaultResponse> {
return context
.path("/text:analyze")
.post({
...operationOptionsToRequestParameters(options),
body: {
text: text,
categories: options?.categories,
blocklistNames: options?.blocklistNames,
breakByBlocklists: options?.breakByBlocklists,
outputType: options?.outputType,
text: body["text"],
categories: body["categories"],
blocklistNames: body["blocklistNames"],
breakByBlocklists: body["breakByBlocklists"],
outputType: body["outputType"],
},
});
}
Expand Down Expand Up @@ -99,16 +101,16 @@ export async function _analyzeTextDeserialize(
/** A sync API for harmful content analysis for text. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
export async function analyzeText(
context: Client,
text: string,
body: AnalyzeTextOptions,
options: AnalyzeTextRequestOptions = { requestOptions: {} }
): Promise<AnalyzeTextResult> {
const result = await _analyzeTextSend(context, text, options);
const result = await _analyzeTextSend(context, body, options);
return _analyzeTextDeserialize(result);
}

export function _analyzeImageSend(
context: Client,
image: ImageData,
body: AnalyzeImageOptions,
options: AnalyzeImageRequestOptions = { requestOptions: {} }
): StreamableMethod<AnalyzeImage200Response | AnalyzeImageDefaultResponse> {
return context
Expand All @@ -118,13 +120,13 @@ export function _analyzeImageSend(
body: {
image: {
content:
image["content"] !== undefined
? uint8ArrayToString(image["content"], "base64")
body.image["content"] !== undefined
? uint8ArrayToString(body.image["content"], "base64")
: undefined,
blobUrl: image["blobUrl"],
blobUrl: body.image["blobUrl"],
},
categories: options?.categories,
outputType: options?.outputType,
categories: body["categories"],
outputType: body["outputType"],
},
});
}
Expand All @@ -147,10 +149,10 @@ export async function _analyzeImageDeserialize(
/** A sync API for harmful content analysis for image. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
export async function analyzeImage(
context: Client,
image: ImageData,
body: AnalyzeImageOptions,
options: AnalyzeImageRequestOptions = { requestOptions: {} }
): Promise<AnalyzeImageResult> {
const result = await _analyzeImageSend(context, image, options);
const result = await _analyzeImageSend(context, body, options);
return _analyzeImageDeserialize(result);
}

Expand Down Expand Up @@ -192,6 +194,7 @@ export async function getTextBlocklist(
export function _createOrUpdateTextBlocklistSend(
context: Client,
blocklistName: string,
resource: TextBlocklist,
options: CreateOrUpdateTextBlocklistOptions = { requestOptions: {} }
): StreamableMethod<
| CreateOrUpdateTextBlocklist200Response
Expand All @@ -204,7 +207,7 @@ export function _createOrUpdateTextBlocklistSend(
...operationOptionsToRequestParameters(options),
contentType:
(options.contentType as any) ?? "application/merge-patch+json",
body: { description: options?.description },
body: { description: resource["description"] },
});
}

Expand All @@ -228,11 +231,13 @@ export async function _createOrUpdateTextBlocklistDeserialize(
export async function createOrUpdateTextBlocklist(
context: Client,
blocklistName: string,
resource: TextBlocklist,
options: CreateOrUpdateTextBlocklistOptions = { requestOptions: {} }
): Promise<TextBlocklist> {
const result = await _createOrUpdateTextBlocklistSend(
context,
blocklistName,
resource,
options
);
return _createOrUpdateTextBlocklistDeserialize(result);
Expand Down Expand Up @@ -312,8 +317,8 @@ export async function listTextBlocklists(

export function _addOrUpdateBlockItemsSend(
context: Client,
blockItems: TextBlockItemInfo[],
blocklistName: string,
body: AddOrUpdateBlockItemsOptions,
options: AddOrUpdateBlockItemsRequestOptions = { requestOptions: {} }
): StreamableMethod<
AddOrUpdateBlockItems200Response | AddOrUpdateBlockItemsDefaultResponse
Expand All @@ -326,7 +331,7 @@ export function _addOrUpdateBlockItemsSend(
.post({
...operationOptionsToRequestParameters(options),
body: {
blockItems: (blockItems ?? []).map((p) => ({
blockItems: (body["blockItems"] ?? []).map((p) => ({
description: p["description"],
text: p["text"],
})),
Expand Down Expand Up @@ -355,23 +360,23 @@ export async function _addOrUpdateBlockItemsDeserialize(
/** Add or update blockItems to a text blocklist. You can add or update at most 100 BlockItems in one request. */
export async function addOrUpdateBlockItems(
context: Client,
blockItems: TextBlockItemInfo[],
blocklistName: string,
body: AddOrUpdateBlockItemsOptions,
options: AddOrUpdateBlockItemsRequestOptions = { requestOptions: {} }
): Promise<AddOrUpdateBlockItemsResult> {
const result = await _addOrUpdateBlockItemsSend(
context,
blockItems,
blocklistName,
body,
options
);
return _addOrUpdateBlockItemsDeserialize(result);
}

export function _removeBlockItemsSend(
context: Client,
blockItemIds: string[],
blocklistName: string,
body: RemoveBlockItemsOptions,
options: RemoveBlockItemsRequestOptions = { requestOptions: {} }
): StreamableMethod<
RemoveBlockItems204Response | RemoveBlockItemsDefaultResponse
Expand All @@ -380,7 +385,7 @@ export function _removeBlockItemsSend(
.path("/text/blocklists/{blocklistName}:removeBlockItems", blocklistName)
.post({
...operationOptionsToRequestParameters(options),
body: { blockItemIds: blockItemIds },
body: { blockItemIds: body["blockItemIds"] },
});
}

Expand All @@ -397,14 +402,14 @@ export async function _removeBlockItemsDeserialize(
/** Remove blockItems from a text blocklist. You can remove at most 100 BlockItems in one request. */
export async function removeBlockItems(
context: Client,
blockItemIds: string[],
blocklistName: string,
body: RemoveBlockItemsOptions,
options: RemoveBlockItemsRequestOptions = { requestOptions: {} }
): Promise<void> {
const result = await _removeBlockItemsSend(
context,
blockItemIds,
blocklistName,
body,
options
);
return _removeBlockItemsDeserialize(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ export {
ContentSafetyClientOptions,
} from "./ContentSafetyClient.js";
export {
AnalyzeTextOptions,
TextCategory,
AnalyzeTextOutputType,
AnalyzeTextResult,
TextBlocklistMatchResult,
TextAnalyzeSeverityResult,
AnalyzeImageOptions,
ImageData,
ImageCategory,
AnalyzeImageOutputType,
AnalyzeImageResult,
ImageAnalyzeSeverityResult,
TextBlocklist,
AddOrUpdateBlockItemsOptions,
TextBlockItemInfo,
AddOrUpdateBlockItemsResult,
TextBlockItem,
RemoveBlockItemsOptions,
PagedTextBlocklist,
PagedTextBlockItem,
AnalyzeTextRequestOptions,
Expand Down
Loading
Loading