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

[data-plane] refresh ai-content-safety-rest sdk #30925

Merged
merged 16 commits into from
Dec 20, 2024
Merged
9 changes: 2 additions & 7 deletions sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Release History

## 1.0.1 (Unreleased)
## 1.0.1 (2024-09-09)
kazrael2119 marked this conversation as resolved.
Show resolved Hide resolved

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
-refresh @azure-rest/ai-content-safety sdk

## 1.0.0 (2023-12-13)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ export interface AnalyzeImageDefaultResponse extends HttpResponse {

// @public
export interface AnalyzeImageOptions {
categories?: string[];
categories?: ImageCategory[];
image: ImageData_2;
outputType?: string;
outputType?: AnalyzeImageOutputType;
}

// @public
export interface AnalyzeImageOptionsOutput {
categories?: string[];
image: ImageDataOutput;
outputType?: string;
}
export type AnalyzeImageOutputType = "FourSeverityLevels";

// @public (undocumented)
export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters;
Expand Down Expand Up @@ -154,20 +150,14 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse {
// @public
export interface AnalyzeTextOptions {
blocklistNames?: string[];
categories?: string[];
categories?: TextCategory[];
haltOnBlocklistHit?: boolean;
outputType?: string;
outputType?: AnalyzeTextOutputType;
text: string;
}

// @public
export interface AnalyzeTextOptionsOutput {
blocklistNames?: string[];
categories?: string[];
haltOnBlocklistHit?: boolean;
outputType?: string;
text: string;
}
export type AnalyzeTextOutputType = "FourSeverityLevels" | "EightSeverityLevels";

// @public (undocumented)
export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters;
Expand All @@ -184,7 +174,12 @@ export type ContentSafetyClient = Client & {
};

// @public
function createClient(endpoint: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): ContentSafetyClient;
export interface ContentSafetyClientOptions extends ClientOptions {
apiVersion?: string;
}

// @public
function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, { apiVersion, ...options }?: ContentSafetyClientOptions): ContentSafetyClient;
export default createClient;

// @public
Expand Down Expand Up @@ -330,22 +325,22 @@ export type GetTextBlocklistParameters = RequestParameters;

// @public
export interface ImageCategoriesAnalysisOutput {
category: string;
category: ImageCategoryOutput;
severity?: number;
}

// @public
interface ImageData_2 {
blobUrl?: string;
content?: string;
}
export { ImageData_2 as ImageData }
export type ImageCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence";

// @public
export interface ImageDataOutput {
export type ImageCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence";

// @public
interface ImageData_2 {
blobUrl?: string;
content?: string;
}
export { ImageData_2 as ImageData }

// @public (undocumented)
export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse;
Expand Down Expand Up @@ -561,10 +556,16 @@ export type TextBlocklistResourceMergeAndPatch = Partial<TextBlocklist>;

// @public
export interface TextCategoriesAnalysisOutput {
category: string;
category: TextCategoryOutput;
severity?: number;
}

// @public
export type TextCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence";

// @public
export type TextCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence";

// (No @packageDocumentation comment for this package)

```
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ import { logger } from "./logger";
import { TokenCredential, KeyCredential } from "@azure/core-auth";
import { ContentSafetyClient } from "./clientDefinitions";

/** The optional parameters for the client */
export interface ContentSafetyClientOptions extends ClientOptions {
/** The api version option of the client */
apiVersion?: string;
}

/**
* Initialize a new instance of `ContentSafetyClient`
* @param endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example:
* @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example:
* https://<resource-name>.cognitiveservices.azure.com).
* @param credentials - uniquely identify client credential
* @param options - the parameter for all optional parameters
*/
export default function createClient(
endpoint: string,
endpointParam: string,
credentials: TokenCredential | KeyCredential,
options: ClientOptions = {},
{ apiVersion = "2023-10-01", ...options }: ContentSafetyClientOptions = {},
): ContentSafetyClient {
const baseUrl = options.baseUrl ?? `${endpoint}/contentsafety`;
options.apiVersion = options.apiVersion ?? "2023-10-01";
const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.1`;
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`;
const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
Expand All @@ -38,8 +43,24 @@ export default function createClient(
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
},
};
const client = getClient(endpointUrl, credentials, options) as ContentSafetyClient;

const client = getClient(baseUrl, credentials, options) as ContentSafetyClient;
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
client.pipeline.addPolicy({
name: "ClientApiVersionPolicy",
sendRequest: (req, next) => {
// Use the apiVersion defined in request url directly
// Append one if there is no apiVersion and we have one at client options
const url = new URL(req.url);
if (!url.searchParams.get("api-version") && apiVersion) {
req.url = `${req.url}${
Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"
}api-version=${apiVersion}`;
}

return next(req);
},
});

return client;
}
29 changes: 15 additions & 14 deletions sdk/contentsafety/ai-content-safety-rest/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,23 @@ export interface AnalyzeTextOptions {
/** The text needs to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request. */
text: string;
/** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */
categories?: string[];
categories?: TextCategory[];
/** The names of blocklists. */
blocklistNames?: string[];
/** When set to true, further analyses of harmful content will not be performed in cases where blocklists are hit. When set to false, all analyses of harmful content will be performed, whether or not blocklists are hit. */
haltOnBlocklistHit?: boolean;
/**
* This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels".
*
* Possible values: FourSeverityLevels, EightSeverityLevels
*/
outputType?: string;
/** This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels". */
outputType?: AnalyzeTextOutputType;
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
}

/** The image analysis request. */
export interface AnalyzeImageOptions {
/** The image needs to be analyzed. */
image: ImageData;
/** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */
categories?: string[];
/**
* This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels".
*
* Possible values: FourSeverityLevels
*/
outputType?: string;
categories?: ImageCategory[];
/** This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". */
outputType?: AnalyzeImageOutputType;
}

/** The image can be either base64 encoded bytes or a blob URL. You can choose only one of these options. If both are provided, the request will be refused. The maximum image size is 2048 x 2048 pixels and should not exceed 4 MB, while the minimum image size is 50 x 50 pixels. */
Expand Down Expand Up @@ -68,3 +60,12 @@ export interface RemoveTextBlocklistItemsOptions {
/** Array of blocklistItemIds to remove. */
blocklistItemIds: string[];
}

/** Text analyze category. */
export type TextCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence";
/** The type of text analysis output. */
export type AnalyzeTextOutputType = "FourSeverityLevels" | "EightSeverityLevels";
/** Image analyze category. */
export type ImageCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence";
/** The type of image analysis output. */
export type AnalyzeImageOutputType = "FourSeverityLevels";
60 changes: 8 additions & 52 deletions sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@

import { Paged } from "@azure/core-paging";

/** The text analysis request. */
export interface AnalyzeTextOptionsOutput {
/** The text needs to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request. */
text: string;
/** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */
categories?: string[];
/** The names of blocklists. */
blocklistNames?: string[];
/** When set to true, further analyses of harmful content will not be performed in cases where blocklists are hit. When set to false, all analyses of harmful content will be performed, whether or not blocklists are hit. */
haltOnBlocklistHit?: boolean;
/**
* This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels".
*
* Possible values: FourSeverityLevels, EightSeverityLevels
*/
outputType?: string;
}

/** The text analysis response. */
export interface AnalyzeTextResultOutput {
/** The blocklist match details. */
Expand All @@ -41,38 +23,12 @@ export interface TextBlocklistMatchOutput {

/** Text analysis result. */
export interface TextCategoriesAnalysisOutput {
/**
* The text analysis category.
*
* Possible values: Hate, SelfHarm, Sexual, Violence
*/
category: string;
/** The text analysis category. */
category: TextCategoryOutput;
/** The value increases with the severity of the input content. The value of this field is determined by the output type specified in the request. The output type could be ‘FourSeverityLevels’ or ‘EightSeverity Levels’, and the output value can be 0, 2, 4, 6 or 0, 1, 2, 3, 4, 5, 6, or 7. */
severity?: number;
}

/** The image analysis request. */
export interface AnalyzeImageOptionsOutput {
/** The image needs to be analyzed. */
image: ImageDataOutput;
/** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */
categories?: string[];
/**
* This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels".
*
* Possible values: FourSeverityLevels
*/
outputType?: string;
}

/** The image can be either base64 encoded bytes or a blob URL. You can choose only one of these options. If both are provided, the request will be refused. The maximum image size is 2048 x 2048 pixels and should not exceed 4 MB, while the minimum image size is 50 x 50 pixels. */
export interface ImageDataOutput {
/** The Base64 encoding of the image. */
content?: string;
/** The blob url of the image. */
blobUrl?: string;
}

/** The image analysis response. */
export interface AnalyzeImageResultOutput {
/** Analysis result for categories. */
Expand All @@ -81,12 +37,8 @@ export interface AnalyzeImageResultOutput {

/** Image analysis result. */
export interface ImageCategoriesAnalysisOutput {
/**
* The image analysis category.
*
* Possible values: Hate, SelfHarm, Sexual, Violence
*/
category: string;
/** The image analysis category. */
category: ImageCategoryOutput;
/** The value increases with the severity of the input content. The value of this field is determined by the output type specified in the request. The output type could be ‘FourSeverityLevels’, and the output value can be 0, 2, 4, 6. */
severity?: number;
}
Expand Down Expand Up @@ -115,6 +67,10 @@ export interface AddOrUpdateTextBlocklistItemsResultOutput {
blocklistItems: Array<TextBlocklistItemOutput>;
}

/** Text analyze category. */
export type TextCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence";
/** Image analyze category. */
export type ImageCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence";
/** Paged collection of TextBlocklist items */
export type PagedTextBlocklistOutput = Paged<TextBlocklistOutput>;
/** Paged collection of TextBlocklistItem items */
Expand Down