From 2c07292ee1a1999dc31f3961e21cf818cb7f8748 Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:11:40 +0800 Subject: [PATCH 01/12] [data-plane] refresh ai-content-safety-rest sdk --- .../review/ai-content-safety.api.md | 51 ++++++++-------- .../src/contentSafetyClient.ts | 35 ++++++++--- .../ai-content-safety-rest/src/models.ts | 29 ++++----- .../src/outputModels.ts | 60 +++---------------- 4 files changed, 77 insertions(+), 98 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index 557b396ff4ed..46888a5c5b90 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -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; @@ -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; @@ -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 @@ -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; @@ -561,10 +556,16 @@ export type TextBlocklistResourceMergeAndPatch = Partial; // @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) ``` diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index fd46e945ce08..7d3f4bdbd536 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -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://.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}` @@ -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; } diff --git a/sdk/contentsafety/ai-content-safety-rest/src/models.ts b/sdk/contentsafety/ai-content-safety-rest/src/models.ts index f3368faf30b4..fcdadd91b127 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/models.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/models.ts @@ -6,17 +6,13 @@ 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; } /** The image analysis request. */ @@ -24,13 +20,9 @@ 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. */ @@ -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"; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts index ac215a7b18fa..5e60ed7c6271 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts @@ -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. */ @@ -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. */ @@ -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; } @@ -115,6 +67,10 @@ export interface AddOrUpdateTextBlocklistItemsResultOutput { blocklistItems: Array; } +/** 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; /** Paged collection of TextBlocklistItem items */ From 35efdccdae0df59039673c43a543b31e9d53d787 Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:09:23 +0800 Subject: [PATCH 02/12] Update CHANGELOG.md --- sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md b/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md index 1ce623dfeef0..6a7d507470f7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md +++ b/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md @@ -1,14 +1,9 @@ # Release History -## 1.0.1 (Unreleased) +## 1.0.1 (2024-09-09) ### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes +-refresh @azure-rest/ai-content-safety sdk ## 1.0.0 (2023-12-13) From c8348e698b0886e27343aa47572fe733d8bf23fe Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:29:49 +0800 Subject: [PATCH 03/12] update --- .../review/ai-content-safety.api.md | 135 ++++++++++++++++-- .../src/clientDefinitions.ts | 44 ++++-- .../src/contentSafetyClient.ts | 2 +- .../src/isUnexpected.ts | 34 +++-- .../ai-content-safety-rest/src/models.ts | 74 ++++++---- .../src/outputModels.ts | 74 +++++++--- .../ai-content-safety-rest/src/parameters.ts | 27 +++- .../ai-content-safety-rest/src/responses.ts | 48 ++++++- .../ai-content-safety-rest/tsp-location.yaml | 2 +- 9 files changed, 361 insertions(+), 79 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index 76b40f8204d6..db460a140ba8 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -104,7 +104,7 @@ export interface AnalyzeImageOptions { } // @public -export type AnalyzeImageOutputType = "FourSeverityLevels"; +export type AnalyzeImageOutputType = string; // @public (undocumented) export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters; @@ -157,7 +157,7 @@ export interface AnalyzeTextOptions { } // @public -export type AnalyzeTextOutputType = "FourSeverityLevels" | "EightSeverityLevels"; +export type AnalyzeTextOutputType = string; // @public (undocumented) export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; @@ -250,6 +250,57 @@ export interface DeleteTextBlocklistDefaultResponse extends HttpResponse { // @public (undocumented) export type DeleteTextBlocklistParameters = RequestParameters; +// @public (undocumented) +export interface DetectTextProtectedMaterial { + post(options: DetectTextProtectedMaterialParameters): StreamableMethod; +} + +// @public +export interface DetectTextProtectedMaterial200Response extends HttpResponse { + // (undocumented) + body: DetectTextProtectedMaterialResultOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialBodyParam { + body: DetectTextProtectedMaterialOptions; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialDefaultHeaders { + "x-ms-error-code"?: string; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponse; + // (undocumented) + headers: RawHttpHeaders & DetectTextProtectedMaterialDefaultHeaders; + // (undocumented) + status: string; +} + +// @public +export interface DetectTextProtectedMaterialOptions { + text: string; +} + +// @public (undocumented) +export type DetectTextProtectedMaterialParameters = DetectTextProtectedMaterialBodyParam & RequestParameters; + +// @public +export interface DetectTextProtectedMaterialResultOutput { + protectedMaterialAnalysis: TextProtectedMaterialAnalysisResultOutput; +} + +// @public +export interface DocumentInjectionAnalysisResultOutput { + attackDetected: boolean; +} + // @public export type GetArrayType = T extends Array ? TData : never; @@ -330,10 +381,10 @@ export interface ImageCategoriesAnalysisOutput { } // @public -export type ImageCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence"; +export type ImageCategory = string; // @public -export type ImageCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence"; +export type ImageCategoryOutput = string; // @public interface ImageData_2 { @@ -342,11 +393,17 @@ interface ImageData_2 { } export { ImageData_2 as ImageData } +// @public (undocumented) +export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse; + // @public (undocumented) export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse; // @public (undocumented) -export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse; +export function isUnexpected(response: ShieldPrompt200Response | ShieldPromptDefaultResponse): response is ShieldPromptDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse): response is DetectTextProtectedMaterialDefaultResponse; // @public (undocumented) export function isUnexpected(response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse): response is GetTextBlocklistDefaultResponse; @@ -509,8 +566,10 @@ export interface RemoveTextBlocklistItemsOptions { // @public (undocumented) export interface Routes { - (path: "/text:analyze"): AnalyzeText; (path: "/image:analyze"): AnalyzeImage; + (path: "/text:analyze"): AnalyzeText; + (path: "/text:shieldPrompt"): ShieldPrompt; + (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; (path: "/text/blocklists"): ListTextBlocklists; (path: "/text/blocklists/{blocklistName}:addOrUpdateBlocklistItems", blocklistName: string): AddOrUpdateBlocklistItems; @@ -519,6 +578,54 @@ export interface Routes { (path: "/text/blocklists/{blocklistName}/blocklistItems", blocklistName: string): ListTextBlocklistItems; } +// @public (undocumented) +export interface ShieldPrompt { + post(options: ShieldPromptParameters): StreamableMethod; +} + +// @public +export interface ShieldPrompt200Response extends HttpResponse { + // (undocumented) + body: ShieldPromptResultOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ShieldPromptBodyParam { + body: ShieldPromptOptions; +} + +// @public (undocumented) +export interface ShieldPromptDefaultHeaders { + "x-ms-error-code"?: string; +} + +// @public (undocumented) +export interface ShieldPromptDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponse; + // (undocumented) + headers: RawHttpHeaders & ShieldPromptDefaultHeaders; + // (undocumented) + status: string; +} + +// @public +export interface ShieldPromptOptions { + documents?: string[]; + userPrompt?: string; +} + +// @public (undocumented) +export type ShieldPromptParameters = ShieldPromptBodyParam & RequestParameters; + +// @public +export interface ShieldPromptResultOutput { + documentsAnalysis?: Array; + userPromptAnalysis?: UserPromptInjectionAnalysisResultOutput; +} + // @public export interface TextBlocklist { blocklistName: string; @@ -528,6 +635,7 @@ export interface TextBlocklist { // @public export interface TextBlocklistItem { description?: string; + isRegex?: boolean; text: string; } @@ -535,6 +643,7 @@ export interface TextBlocklistItem { export interface TextBlocklistItemOutput { readonly blocklistItemId: string; description?: string; + isRegex?: boolean; text: string; } @@ -561,10 +670,20 @@ export interface TextCategoriesAnalysisOutput { } // @public -export type TextCategory = "Hate" | "SelfHarm" | "Sexual" | "Violence"; +export type TextCategory = string; + +// @public +export type TextCategoryOutput = string; // @public -export type TextCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence"; +export interface TextProtectedMaterialAnalysisResultOutput { + detected: boolean; +} + +// @public +export interface UserPromptInjectionAnalysisResultOutput { + attackDetected: boolean; +} // (No @packageDocumentation comment for this package) diff --git a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts index 89e32d0c316d..33514796beab 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts @@ -2,8 +2,10 @@ // Licensed under the MIT License. import type { - AnalyzeTextParameters, AnalyzeImageParameters, + AnalyzeTextParameters, + ShieldPromptParameters, + DetectTextProtectedMaterialParameters, GetTextBlocklistParameters, CreateOrUpdateTextBlocklistParameters, DeleteTextBlocklistParameters, @@ -14,10 +16,14 @@ import type { ListTextBlocklistItemsParameters, } from "./parameters"; import type { - AnalyzeText200Response, - AnalyzeTextDefaultResponse, AnalyzeImage200Response, AnalyzeImageDefaultResponse, + AnalyzeText200Response, + AnalyzeTextDefaultResponse, + ShieldPrompt200Response, + ShieldPromptDefaultResponse, + DetectTextProtectedMaterial200Response, + DetectTextProtectedMaterialDefaultResponse, GetTextBlocklist200Response, GetTextBlocklistDefaultResponse, CreateOrUpdateTextBlocklist200Response, @@ -38,6 +44,13 @@ import type { } from "./responses"; import type { Client, StreamableMethod } from "@azure-rest/core-client"; +export interface AnalyzeImage { + /** A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence. */ + post( + options: AnalyzeImageParameters, + ): StreamableMethod; +} + export interface AnalyzeText { /** A synchronous API for the analysis of potentially harmful text content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence. */ post( @@ -45,11 +58,20 @@ export interface AnalyzeText { ): StreamableMethod; } -export interface AnalyzeImage { - /** A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence. */ +export interface ShieldPrompt { + /** A synchronous API for shielding prompt from direct and indirect injection attacks. */ post( - options: AnalyzeImageParameters, - ): StreamableMethod; + options: ShieldPromptParameters, + ): StreamableMethod; +} + +export interface DetectTextProtectedMaterial { + /** A synchronous API for detecting protected material in the given text. */ + post( + options: DetectTextProtectedMaterialParameters, + ): StreamableMethod< + DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse + >; } export interface GetTextBlocklist { @@ -109,10 +131,14 @@ export interface ListTextBlocklistItems { } export interface Routes { - /** Resource for '/text:analyze' has methods for the following verbs: post */ - (path: "/text:analyze"): AnalyzeText; /** Resource for '/image:analyze' has methods for the following verbs: post */ (path: "/image:analyze"): AnalyzeImage; + /** Resource for '/text:analyze' has methods for the following verbs: post */ + (path: "/text:analyze"): AnalyzeText; + /** Resource for '/text:shieldPrompt' has methods for the following verbs: post */ + (path: "/text:shieldPrompt"): ShieldPrompt; + /** Resource for '/text:detectProtectedMaterial' has methods for the following verbs: post */ + (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; /** Resource for '/text/blocklists/\{blocklistName\}' has methods for the following verbs: get, patch, delete */ (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; /** Resource for '/text/blocklists' has methods for the following verbs: get */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index 1f01c6d2b6cc..1c51526de077 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -23,7 +23,7 @@ export interface ContentSafetyClientOptions extends ClientOptions { export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - { apiVersion = "2023-10-01", ...options }: ContentSafetyClientOptions = {}, + { apiVersion = "2024-09-01", ...options }: ContentSafetyClientOptions = {}, ): ContentSafetyClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`; const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts index 860c320bc851..978d07a2781c 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts @@ -2,10 +2,14 @@ // Licensed under the MIT License. import type { - AnalyzeText200Response, - AnalyzeTextDefaultResponse, AnalyzeImage200Response, AnalyzeImageDefaultResponse, + AnalyzeText200Response, + AnalyzeTextDefaultResponse, + ShieldPrompt200Response, + ShieldPromptDefaultResponse, + DetectTextProtectedMaterial200Response, + DetectTextProtectedMaterialDefaultResponse, GetTextBlocklist200Response, GetTextBlocklistDefaultResponse, CreateOrUpdateTextBlocklist200Response, @@ -26,8 +30,10 @@ import type { } from "./responses"; const responseMap: Record = { - "POST /text:analyze": ["200"], "POST /image:analyze": ["200"], + "POST /text:analyze": ["200"], + "POST /text:shieldPrompt": ["200"], + "POST /text:detectProtectedMaterial": ["200"], "GET /text/blocklists/{blocklistName}": ["200"], "PATCH /text/blocklists/{blocklistName}": ["200", "201"], "DELETE /text/blocklists/{blocklistName}": ["204"], @@ -38,12 +44,18 @@ const responseMap: Record = { "GET /text/blocklists/{blocklistName}/blocklistItems": ["200"], }; +export function isUnexpected( + response: AnalyzeImage200Response | AnalyzeImageDefaultResponse, +): response is AnalyzeImageDefaultResponse; export function isUnexpected( response: AnalyzeText200Response | AnalyzeTextDefaultResponse, ): response is AnalyzeTextDefaultResponse; export function isUnexpected( - response: AnalyzeImage200Response | AnalyzeImageDefaultResponse, -): response is AnalyzeImageDefaultResponse; + response: ShieldPrompt200Response | ShieldPromptDefaultResponse, +): response is ShieldPromptDefaultResponse; +export function isUnexpected( + response: DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse, +): response is DetectTextProtectedMaterialDefaultResponse; export function isUnexpected( response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse, ): response is GetTextBlocklistDefaultResponse; @@ -73,10 +85,14 @@ export function isUnexpected( ): response is ListTextBlocklistItemsDefaultResponse; export function isUnexpected( response: - | AnalyzeText200Response - | AnalyzeTextDefaultResponse | AnalyzeImage200Response | AnalyzeImageDefaultResponse + | AnalyzeText200Response + | AnalyzeTextDefaultResponse + | ShieldPrompt200Response + | ShieldPromptDefaultResponse + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse | GetTextBlocklist200Response | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklist200Response @@ -95,8 +111,10 @@ export function isUnexpected( | ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse, ): response is - | AnalyzeTextDefaultResponse | AnalyzeImageDefaultResponse + | AnalyzeTextDefaultResponse + | ShieldPromptDefaultResponse + | DetectTextProtectedMaterialDefaultResponse | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklistDefaultResponse | DeleteTextBlocklistDefaultResponse diff --git a/sdk/contentsafety/ai-content-safety-rest/src/models.ts b/sdk/contentsafety/ai-content-safety-rest/src/models.ts index bd8ba27f422b..856f8236fd06 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/models.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/models.ts @@ -1,27 +1,17 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -/** The text analysis request. */ -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?: 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". */ - outputType?: AnalyzeTextOutputType; -} - /** The image analysis request. */ export interface AnalyzeImageOptions { - /** The image needs to be analyzed. */ + /** The image 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?: ImageCategory[]; - /** This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". */ + /** + * This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". + * + * Possible values: "FourSeverityLevels" + */ outputType?: AnalyzeImageOutputType; } @@ -33,6 +23,38 @@ export interface ImageData { blobUrl?: string; } +/** The text analysis request. */ +export interface AnalyzeTextOptions { + /** The text 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?: 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?: AnalyzeTextOutputType; +} + +/** The request of analyzing potential direct or indirect injection attacks. */ +export interface ShieldPromptOptions { + /** The user prompt to be analyzed, which may contain direct injection attacks. */ + userPrompt?: string; + /** The documents to be analyzed, which may contain direct or indirect injection attacks. */ + documents?: string[]; +} + +/** The request of detecting potential protected material present in the given text. */ +export interface DetectTextProtectedMaterialOptions { + /** The text to be analyzed, which may contain protected material. The characters will be counted in Unicode code points. */ + text: string; +} + /** Text Blocklist. */ export interface TextBlocklist { /** Text blocklist name. */ @@ -51,8 +73,10 @@ export interface AddOrUpdateTextBlocklistItemsOptions { export interface TextBlocklistItem { /** BlocklistItem description. */ description?: string; - /** BlocklistItem content. */ + /** BlocklistItem content. The length is counted using Unicode code point. */ text: string; + /** An optional properties indicating whether this item is to be matched as a regular expression. */ + isRegex?: boolean; } /** The request to remove blocklistItems from a text blocklist. */ @@ -61,11 +85,11 @@ export interface RemoveTextBlocklistItemsOptions { 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"; +/** Alias for ImageCategory */ +export type ImageCategory = string; +/** Alias for AnalyzeImageOutputType */ +export type AnalyzeImageOutputType = string; +/** Alias for TextCategory */ +export type TextCategory = string; +/** Alias for AnalyzeTextOutputType */ +export type AnalyzeTextOutputType = string; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts index e235e8b72a4c..e1b8a09e156a 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts @@ -3,6 +3,24 @@ import type { Paged } from "@azure/core-paging"; +/** The image analysis response. */ +export interface AnalyzeImageResultOutput { + /** Analysis result for categories. */ + categoriesAnalysis: Array; +} + +/** Image analysis result. */ +export interface ImageCategoriesAnalysisOutput { + /** + * The image analysis category. + * + * Possible values: "Hate", "SelfHarm", "Sexual", "Violence" + */ + 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; +} + /** The text analysis response. */ export interface AnalyzeTextResultOutput { /** The blocklist match details. */ @@ -23,24 +41,46 @@ export interface TextBlocklistMatchOutput { /** Text analysis result. */ export interface TextCategoriesAnalysisOutput { - /** The text analysis category. */ + /** + * The text analysis category. + * + * Possible values: "Hate", "SelfHarm", "Sexual", "Violence" + */ 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 response. */ -export interface AnalyzeImageResultOutput { - /** Analysis result for categories. */ - categoriesAnalysis: Array; +/** The combined analysis results of potential direct or indirect injection attacks. */ +export interface ShieldPromptResultOutput { + /** Direct injection attacks analysis result for the given user prompt. */ + userPromptAnalysis?: UserPromptInjectionAnalysisResultOutput; + /** Direct and indirect injection attacks analysis result for the given documents. */ + documentsAnalysis?: Array; } -/** Image analysis result. */ -export interface ImageCategoriesAnalysisOutput { - /** 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; +/** The individual analysis result of potential injection attacks in the given user prompt. */ +export interface UserPromptInjectionAnalysisResultOutput { + /** Whether a potential injection attack is detected or not. */ + attackDetected: boolean; +} + +/** The individual analysis result of potential injection attacks in the given documents. */ +export interface DocumentInjectionAnalysisResultOutput { + /** Whether a potential injection attack is detected or not. */ + attackDetected: boolean; +} + +/** The combined detection results of potential protected material. */ +export interface DetectTextProtectedMaterialResultOutput { + /** Analysis result for the given text. */ + protectedMaterialAnalysis: TextProtectedMaterialAnalysisResultOutput; +} + +/** The individual detection result of potential protected material. */ +export interface TextProtectedMaterialAnalysisResultOutput { + /** Whether potential protected material is detected or not. */ + detected: boolean; } /** Text Blocklist. */ @@ -57,8 +97,10 @@ export interface TextBlocklistItemOutput { readonly blocklistItemId: string; /** BlocklistItem description. */ description?: string; - /** BlocklistItem content. */ + /** BlocklistItem content. The length is counted using Unicode code point. */ text: string; + /** An optional properties indicating whether this item is to be matched as a regular expression. */ + isRegex?: boolean; } /** The response of adding blocklistItems to the text blocklist. */ @@ -67,10 +109,10 @@ export interface AddOrUpdateTextBlocklistItemsResultOutput { blocklistItems: Array; } -/** Text analyze category. */ -export type TextCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence"; -/** Image analyze category. */ -export type ImageCategoryOutput = "Hate" | "SelfHarm" | "Sexual" | "Violence"; +/** Alias for ImageCategoryOutput */ +export type ImageCategoryOutput = string; +/** Alias for TextCategoryOutput */ +export type TextCategoryOutput = string; /** Paged collection of TextBlocklist items */ export type PagedTextBlocklistOutput = Paged; /** Paged collection of TextBlocklistItem items */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts index b14ff16dd770..aff8ba3cde9f 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts @@ -3,13 +3,22 @@ import type { RequestParameters } from "@azure-rest/core-client"; import type { - AnalyzeTextOptions, AnalyzeImageOptions, + AnalyzeTextOptions, + ShieldPromptOptions, + DetectTextProtectedMaterialOptions, TextBlocklist, AddOrUpdateTextBlocklistItemsOptions, RemoveTextBlocklistItemsOptions, } from "./models"; +export interface AnalyzeImageBodyParam { + /** The image analysis request. */ + body: AnalyzeImageOptions; +} + +export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters; + export interface AnalyzeTextBodyParam { /** The text analysis request. */ body: AnalyzeTextOptions; @@ -17,12 +26,20 @@ export interface AnalyzeTextBodyParam { export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; -export interface AnalyzeImageBodyParam { - /** The image analysis request. */ - body: AnalyzeImageOptions; +export interface ShieldPromptBodyParam { + /** The request body to be detected, which may contain direct or indirect injection attacks. */ + body: ShieldPromptOptions; } -export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters; +export type ShieldPromptParameters = ShieldPromptBodyParam & RequestParameters; + +export interface DetectTextProtectedMaterialBodyParam { + /** The request body to be detected, which may contain protected material. */ + body: DetectTextProtectedMaterialOptions; +} + +export type DetectTextProtectedMaterialParameters = DetectTextProtectedMaterialBodyParam & + RequestParameters; export type GetTextBlocklistParameters = RequestParameters; /** The resource instance. */ export type TextBlocklistResourceMergeAndPatch = Partial; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts index bbf9b343850d..79af3e4b2da8 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts @@ -4,8 +4,10 @@ import type { RawHttpHeaders } from "@azure/core-rest-pipeline"; import type { HttpResponse, ErrorResponse } from "@azure-rest/core-client"; import type { - AnalyzeTextResultOutput, AnalyzeImageResultOutput, + AnalyzeTextResultOutput, + ShieldPromptResultOutput, + DetectTextProtectedMaterialResultOutput, TextBlocklistOutput, PagedTextBlocklistOutput, AddOrUpdateTextBlocklistItemsResultOutput, @@ -13,6 +15,23 @@ import type { PagedTextBlocklistItemOutput, } from "./outputModels"; +/** The request has succeeded. */ +export interface AnalyzeImage200Response extends HttpResponse { + status: "200"; + body: AnalyzeImageResultOutput; +} + +export interface AnalyzeImageDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface AnalyzeImageDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & AnalyzeImageDefaultHeaders; +} + /** The request has succeeded. */ export interface AnalyzeText200Response extends HttpResponse { status: "200"; @@ -31,20 +50,37 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse { } /** The request has succeeded. */ -export interface AnalyzeImage200Response extends HttpResponse { +export interface ShieldPrompt200Response extends HttpResponse { status: "200"; - body: AnalyzeImageResultOutput; + body: ShieldPromptResultOutput; } -export interface AnalyzeImageDefaultHeaders { +export interface ShieldPromptDefaultHeaders { /** String error code indicating what went wrong. */ "x-ms-error-code"?: string; } -export interface AnalyzeImageDefaultResponse extends HttpResponse { +export interface ShieldPromptDefaultResponse extends HttpResponse { status: string; body: ErrorResponse; - headers: RawHttpHeaders & AnalyzeImageDefaultHeaders; + headers: RawHttpHeaders & ShieldPromptDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DetectTextProtectedMaterial200Response extends HttpResponse { + status: "200"; + body: DetectTextProtectedMaterialResultOutput; +} + +export interface DetectTextProtectedMaterialDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DetectTextProtectedMaterialDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DetectTextProtectedMaterialDefaultHeaders; } /** The request has succeeded. */ diff --git a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml index 9d47983f6b57..a028dec380d3 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml +++ b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/cognitiveservices/ContentSafety repo: Azure/azure-rest-api-specs -commit: 164375e67a1bffb207bcf603772c289dbe42d7b5 +commit: e6fde2ac19d0202f0e72217a3e0f9edb63dba273 From 62333ee4afee4f1eabf300f436bb33a1b775b35e Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:08:13 +0800 Subject: [PATCH 04/12] update --- .../review/ai-content-safety.api.md | 26 +++- .../src/outputModels.ts | 22 ++- .../src/paginateHelper.ts | 146 +++++++++++++++++- .../test/public/contentSafety.spec.ts | 2 +- 4 files changed, 178 insertions(+), 18 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index db460a140ba8..0a095d390d1d 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -9,8 +9,6 @@ import type { ClientOptions } from '@azure-rest/core-client'; import type { ErrorResponse } from '@azure-rest/core-client'; import type { HttpResponse } from '@azure-rest/core-client'; import type { KeyCredential } from '@azure/core-auth'; -import type { Paged } from '@azure/core-paging'; -import type { PagedAsyncIterableIterator } from '@azure/core-paging'; import type { PathUncheckedResponse } from '@azure-rest/core-client'; import type { RawHttpHeaders } from '@azure/core-rest-pipeline'; import type { RequestParameters } from '@azure-rest/core-client'; @@ -305,7 +303,7 @@ export interface DocumentInjectionAnalysisResultOutput { export type GetArrayType = T extends Array ? TData : never; // @public -export type GetPage = (pageLink: string, maxPageSize?: number) => Promise<{ +export type GetPage = (pageLink: string) => Promise<{ page: TPage; nextPageLink?: string; }>; @@ -505,10 +503,28 @@ export interface ListTextBlocklistsDefaultResponse extends HttpResponse { export type ListTextBlocklistsParameters = RequestParameters; // @public -export type PagedTextBlocklistItemOutput = Paged; +export interface PagedAsyncIterableIterator { + [Symbol.asyncIterator](): PagedAsyncIterableIterator; + byPage: (settings?: TPageSettings) => AsyncIterableIterator; + next(): Promise>; +} + +// @public +export interface PagedTextBlocklistItemOutput { + nextLink?: string; + value: Array; +} // @public -export type PagedTextBlocklistOutput = Paged; +export interface PagedTextBlocklistOutput { + nextLink?: string; + value: Array; +} + +// @public +export interface PageSettings { + continuationToken?: string; +} // @public export function paginate(client: Client, initialResponse: TResponse, options?: PagingOptions): PagedAsyncIterableIterator>; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts index e1b8a09e156a..a217df5fa2a8 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { Paged } from "@azure/core-paging"; - /** The image analysis response. */ export interface AnalyzeImageResultOutput { /** Analysis result for categories. */ @@ -91,6 +89,14 @@ export interface TextBlocklistOutput { description?: string; } +/** Paged collection of TextBlocklist items */ +export interface PagedTextBlocklistOutput { + /** The TextBlocklist items on this page */ + value: Array; + /** The link to the next page of items */ + nextLink?: string; +} + /** Item in a TextBlocklist. */ export interface TextBlocklistItemOutput { /** The service will generate a BlocklistItemId, which will be a UUID. */ @@ -109,11 +115,15 @@ export interface AddOrUpdateTextBlocklistItemsResultOutput { blocklistItems: Array; } +/** Paged collection of TextBlocklistItem items */ +export interface PagedTextBlocklistItemOutput { + /** The TextBlocklistItem items on this page */ + value: Array; + /** The link to the next page of items */ + nextLink?: string; +} + /** Alias for ImageCategoryOutput */ export type ImageCategoryOutput = string; /** Alias for TextCategoryOutput */ export type TextCategoryOutput = string; -/** Paged collection of TextBlocklist items */ -export type PagedTextBlocklistOutput = Paged; -/** Paged collection of TextBlocklistItem items */ -export type PagedTextBlocklistItemOutput = Paged; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts b/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts index 5d541b4e406d..9ea946d9d6c5 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts @@ -1,11 +1,148 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { PagedAsyncIterableIterator, PagedResult } from "@azure/core-paging"; -import { getPagedAsyncIterator } from "@azure/core-paging"; import type { Client, PathUncheckedResponse } from "@azure-rest/core-client"; import { createRestError } from "@azure-rest/core-client"; +/** + * returns an async iterator that iterates over results. It also has a `byPage` + * method that returns pages of items at once. + * + * @param pagedResult - an object that specifies how to get pages. + * @returns a paged async iterator that iterates over results. + */ +function getPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings = PageSettings, + TLink = string, +>( + pagedResult: PagedResult, +): PagedAsyncIterableIterator { + const iter = getItemAsyncIterator(pagedResult); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: + pagedResult?.byPage ?? + (((settings?: PageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken as unknown as TLink | undefined, + }); + }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator), + }; +} + +async function* getItemAsyncIterator( + pagedResult: PagedResult, +): AsyncIterableIterator { + const pages = getPageAsyncIterator(pagedResult); + const firstVal = await pages.next(); + // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is + if (!Array.isArray(firstVal.value)) { + // can extract elements from this page + const { toElements } = pagedResult; + if (toElements) { + yield* toElements(firstVal.value) as TElement[]; + for await (const page of pages) { + yield* toElements(page) as TElement[]; + } + } else { + yield firstVal.value; + // `pages` is of type `AsyncIterableIterator` but TPage = TElement in this case + yield* pages as unknown as AsyncIterableIterator; + } + } else { + yield* firstVal.value; + for await (const page of pages) { + // pages is of type `AsyncIterableIterator` so `page` is of type `TPage`. In this branch, + // it must be the case that `TPage = TElement[]` + yield* page as unknown as TElement[]; + } + } +} + +async function* getPageAsyncIterator( + pagedResult: PagedResult, + options: { + pageLink?: TLink; + } = {}, +): AsyncIterableIterator { + const { pageLink } = options; + let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink); + if (!response) { + return; + } + yield response.page; + while (response.nextPageLink) { + response = await pagedResult.getPage(response.nextPageLink); + if (!response) { + return; + } + yield response.page; + } +} + +/** + * An interface that tracks the settings for paged iteration + */ +export interface PageSettings { + /** + * The token that keeps track of where to continue the iterator + */ + continuationToken?: string; +} + +/** + * An interface that allows async iterable iteration both to completion and by page. + */ +export interface PagedAsyncIterableIterator< + TElement, + TPage = TElement[], + TPageSettings = PageSettings, +> { + /** + * The next method, part of the iteration protocol + */ + next(): Promise>; + /** + * The connection to the async iterator, part of the iteration protocol + */ + [Symbol.asyncIterator](): PagedAsyncIterableIterator; + /** + * Return an AsyncIterableIterator that works a page at a time + */ + byPage: (settings?: TPageSettings) => AsyncIterableIterator; +} + +/** + * An interface that describes how to communicate with the service. + */ +interface PagedResult { + /** + * Link to the first page of results. + */ + firstPageLink: TLink; + /** + * A method that returns a page of results. + */ + getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>; + /** + * a function to implement the `byPage` method on the paged async iterator. + */ + byPage?: (settings?: TPageSettings) => AsyncIterableIterator; + + /** + * A function to extract elements from a page. + */ + toElements?: (page: TPage) => unknown[]; +} + /** * Helper type to extract the type of an array */ @@ -14,10 +151,7 @@ export type GetArrayType = T extends Array ? TData : never; /** * The type of a custom function that defines how to get a page and a link to the next one if any. */ -export type GetPage = ( - pageLink: string, - maxPageSize?: number, -) => Promise<{ +export type GetPage = (pageLink: string) => Promise<{ page: TPage; nextPageLink?: string; }>; diff --git a/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts b/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts index 11f2a29e819f..818c229b4c06 100644 --- a/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts +++ b/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts @@ -8,7 +8,7 @@ import { createRecorder, createClient } from "./utils/recordedClient"; import type { Context } from "mocha"; import type { ContentSafetyClient, TextBlocklistItemOutput } from "../../src"; import { isUnexpected, paginate } from "../../src"; -import type { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; +import type { PagedAsyncIterableIterator, PageSettings } from "../../src/paginateHelper"; import fs from "fs"; import path from "path"; import { isBrowser } from "@azure/core-util"; From 4779a69831d82b2631552c85d1a54b42142e57ba Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:37:40 +0800 Subject: [PATCH 05/12] update --- .../review/ai-content-safety.api.md | 119 ------------------ .../src/clientDefinitions.ts | 26 ---- .../src/contentSafetyClient.ts | 7 +- .../src/isUnexpected.ts | 18 --- .../ai-content-safety-rest/src/models.ts | 16 --- .../src/outputModels.ts | 34 ----- .../ai-content-safety-rest/src/parameters.ts | 17 --- .../ai-content-safety-rest/src/responses.ts | 36 ------ .../ai-content-safety-rest/tsp-location.yaml | 3 +- 9 files changed, 5 insertions(+), 271 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index 0a095d390d1d..ca99a20a89f7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -248,57 +248,6 @@ export interface DeleteTextBlocklistDefaultResponse extends HttpResponse { // @public (undocumented) export type DeleteTextBlocklistParameters = RequestParameters; -// @public (undocumented) -export interface DetectTextProtectedMaterial { - post(options: DetectTextProtectedMaterialParameters): StreamableMethod; -} - -// @public -export interface DetectTextProtectedMaterial200Response extends HttpResponse { - // (undocumented) - body: DetectTextProtectedMaterialResultOutput; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface DetectTextProtectedMaterialBodyParam { - body: DetectTextProtectedMaterialOptions; -} - -// @public (undocumented) -export interface DetectTextProtectedMaterialDefaultHeaders { - "x-ms-error-code"?: string; -} - -// @public (undocumented) -export interface DetectTextProtectedMaterialDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponse; - // (undocumented) - headers: RawHttpHeaders & DetectTextProtectedMaterialDefaultHeaders; - // (undocumented) - status: string; -} - -// @public -export interface DetectTextProtectedMaterialOptions { - text: string; -} - -// @public (undocumented) -export type DetectTextProtectedMaterialParameters = DetectTextProtectedMaterialBodyParam & RequestParameters; - -// @public -export interface DetectTextProtectedMaterialResultOutput { - protectedMaterialAnalysis: TextProtectedMaterialAnalysisResultOutput; -} - -// @public -export interface DocumentInjectionAnalysisResultOutput { - attackDetected: boolean; -} - // @public export type GetArrayType = T extends Array ? TData : never; @@ -397,12 +346,6 @@ export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDef // @public (undocumented) export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse; -// @public (undocumented) -export function isUnexpected(response: ShieldPrompt200Response | ShieldPromptDefaultResponse): response is ShieldPromptDefaultResponse; - -// @public (undocumented) -export function isUnexpected(response: DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse): response is DetectTextProtectedMaterialDefaultResponse; - // @public (undocumented) export function isUnexpected(response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse): response is GetTextBlocklistDefaultResponse; @@ -584,8 +527,6 @@ export interface RemoveTextBlocklistItemsOptions { export interface Routes { (path: "/image:analyze"): AnalyzeImage; (path: "/text:analyze"): AnalyzeText; - (path: "/text:shieldPrompt"): ShieldPrompt; - (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; (path: "/text/blocklists"): ListTextBlocklists; (path: "/text/blocklists/{blocklistName}:addOrUpdateBlocklistItems", blocklistName: string): AddOrUpdateBlocklistItems; @@ -594,54 +535,6 @@ export interface Routes { (path: "/text/blocklists/{blocklistName}/blocklistItems", blocklistName: string): ListTextBlocklistItems; } -// @public (undocumented) -export interface ShieldPrompt { - post(options: ShieldPromptParameters): StreamableMethod; -} - -// @public -export interface ShieldPrompt200Response extends HttpResponse { - // (undocumented) - body: ShieldPromptResultOutput; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface ShieldPromptBodyParam { - body: ShieldPromptOptions; -} - -// @public (undocumented) -export interface ShieldPromptDefaultHeaders { - "x-ms-error-code"?: string; -} - -// @public (undocumented) -export interface ShieldPromptDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponse; - // (undocumented) - headers: RawHttpHeaders & ShieldPromptDefaultHeaders; - // (undocumented) - status: string; -} - -// @public -export interface ShieldPromptOptions { - documents?: string[]; - userPrompt?: string; -} - -// @public (undocumented) -export type ShieldPromptParameters = ShieldPromptBodyParam & RequestParameters; - -// @public -export interface ShieldPromptResultOutput { - documentsAnalysis?: Array; - userPromptAnalysis?: UserPromptInjectionAnalysisResultOutput; -} - // @public export interface TextBlocklist { blocklistName: string; @@ -651,7 +544,6 @@ export interface TextBlocklist { // @public export interface TextBlocklistItem { description?: string; - isRegex?: boolean; text: string; } @@ -659,7 +551,6 @@ export interface TextBlocklistItem { export interface TextBlocklistItemOutput { readonly blocklistItemId: string; description?: string; - isRegex?: boolean; text: string; } @@ -691,16 +582,6 @@ export type TextCategory = string; // @public export type TextCategoryOutput = string; -// @public -export interface TextProtectedMaterialAnalysisResultOutput { - detected: boolean; -} - -// @public -export interface UserPromptInjectionAnalysisResultOutput { - attackDetected: boolean; -} - // (No @packageDocumentation comment for this package) ``` diff --git a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts index 33514796beab..833d64691d3d 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts @@ -4,8 +4,6 @@ import type { AnalyzeImageParameters, AnalyzeTextParameters, - ShieldPromptParameters, - DetectTextProtectedMaterialParameters, GetTextBlocklistParameters, CreateOrUpdateTextBlocklistParameters, DeleteTextBlocklistParameters, @@ -20,10 +18,6 @@ import type { AnalyzeImageDefaultResponse, AnalyzeText200Response, AnalyzeTextDefaultResponse, - ShieldPrompt200Response, - ShieldPromptDefaultResponse, - DetectTextProtectedMaterial200Response, - DetectTextProtectedMaterialDefaultResponse, GetTextBlocklist200Response, GetTextBlocklistDefaultResponse, CreateOrUpdateTextBlocklist200Response, @@ -58,22 +52,6 @@ export interface AnalyzeText { ): StreamableMethod; } -export interface ShieldPrompt { - /** A synchronous API for shielding prompt from direct and indirect injection attacks. */ - post( - options: ShieldPromptParameters, - ): StreamableMethod; -} - -export interface DetectTextProtectedMaterial { - /** A synchronous API for detecting protected material in the given text. */ - post( - options: DetectTextProtectedMaterialParameters, - ): StreamableMethod< - DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse - >; -} - export interface GetTextBlocklist { /** Returns text blocklist details. */ get( @@ -135,10 +113,6 @@ export interface Routes { (path: "/image:analyze"): AnalyzeImage; /** Resource for '/text:analyze' has methods for the following verbs: post */ (path: "/text:analyze"): AnalyzeText; - /** Resource for '/text:shieldPrompt' has methods for the following verbs: post */ - (path: "/text:shieldPrompt"): ShieldPrompt; - /** Resource for '/text:detectProtectedMaterial' has methods for the following verbs: post */ - (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; /** Resource for '/text/blocklists/\{blocklistName\}' has methods for the following verbs: get, patch, delete */ (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; /** Resource for '/text/blocklists' has methods for the following verbs: get */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index 1c51526de077..03c260d5f9d7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -23,7 +23,7 @@ export interface ContentSafetyClientOptions extends ClientOptions { export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - { apiVersion = "2024-09-01", ...options }: ContentSafetyClientOptions = {}, + { apiVersion = "2023-10-01", ...options }: ContentSafetyClientOptions = {}, ): ContentSafetyClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`; const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`; @@ -54,9 +54,8 @@ export default function createClient( // 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}`; + req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; } return next(req); diff --git a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts index 978d07a2781c..2c1b3275c606 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts @@ -6,10 +6,6 @@ import type { AnalyzeImageDefaultResponse, AnalyzeText200Response, AnalyzeTextDefaultResponse, - ShieldPrompt200Response, - ShieldPromptDefaultResponse, - DetectTextProtectedMaterial200Response, - DetectTextProtectedMaterialDefaultResponse, GetTextBlocklist200Response, GetTextBlocklistDefaultResponse, CreateOrUpdateTextBlocklist200Response, @@ -32,8 +28,6 @@ import type { const responseMap: Record = { "POST /image:analyze": ["200"], "POST /text:analyze": ["200"], - "POST /text:shieldPrompt": ["200"], - "POST /text:detectProtectedMaterial": ["200"], "GET /text/blocklists/{blocklistName}": ["200"], "PATCH /text/blocklists/{blocklistName}": ["200", "201"], "DELETE /text/blocklists/{blocklistName}": ["204"], @@ -50,12 +44,6 @@ export function isUnexpected( export function isUnexpected( response: AnalyzeText200Response | AnalyzeTextDefaultResponse, ): response is AnalyzeTextDefaultResponse; -export function isUnexpected( - response: ShieldPrompt200Response | ShieldPromptDefaultResponse, -): response is ShieldPromptDefaultResponse; -export function isUnexpected( - response: DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse, -): response is DetectTextProtectedMaterialDefaultResponse; export function isUnexpected( response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse, ): response is GetTextBlocklistDefaultResponse; @@ -89,10 +77,6 @@ export function isUnexpected( | AnalyzeImageDefaultResponse | AnalyzeText200Response | AnalyzeTextDefaultResponse - | ShieldPrompt200Response - | ShieldPromptDefaultResponse - | DetectTextProtectedMaterial200Response - | DetectTextProtectedMaterialDefaultResponse | GetTextBlocklist200Response | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklist200Response @@ -113,8 +97,6 @@ export function isUnexpected( ): response is | AnalyzeImageDefaultResponse | AnalyzeTextDefaultResponse - | ShieldPromptDefaultResponse - | DetectTextProtectedMaterialDefaultResponse | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklistDefaultResponse | DeleteTextBlocklistDefaultResponse diff --git a/sdk/contentsafety/ai-content-safety-rest/src/models.ts b/sdk/contentsafety/ai-content-safety-rest/src/models.ts index 856f8236fd06..017c38a6216a 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/models.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/models.ts @@ -41,20 +41,6 @@ export interface AnalyzeTextOptions { outputType?: AnalyzeTextOutputType; } -/** The request of analyzing potential direct or indirect injection attacks. */ -export interface ShieldPromptOptions { - /** The user prompt to be analyzed, which may contain direct injection attacks. */ - userPrompt?: string; - /** The documents to be analyzed, which may contain direct or indirect injection attacks. */ - documents?: string[]; -} - -/** The request of detecting potential protected material present in the given text. */ -export interface DetectTextProtectedMaterialOptions { - /** The text to be analyzed, which may contain protected material. The characters will be counted in Unicode code points. */ - text: string; -} - /** Text Blocklist. */ export interface TextBlocklist { /** Text blocklist name. */ @@ -75,8 +61,6 @@ export interface TextBlocklistItem { description?: string; /** BlocklistItem content. The length is counted using Unicode code point. */ text: string; - /** An optional properties indicating whether this item is to be matched as a regular expression. */ - isRegex?: boolean; } /** The request to remove blocklistItems from a text blocklist. */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts index a217df5fa2a8..190ff141f733 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts @@ -49,38 +49,6 @@ export interface TextCategoriesAnalysisOutput { severity?: number; } -/** The combined analysis results of potential direct or indirect injection attacks. */ -export interface ShieldPromptResultOutput { - /** Direct injection attacks analysis result for the given user prompt. */ - userPromptAnalysis?: UserPromptInjectionAnalysisResultOutput; - /** Direct and indirect injection attacks analysis result for the given documents. */ - documentsAnalysis?: Array; -} - -/** The individual analysis result of potential injection attacks in the given user prompt. */ -export interface UserPromptInjectionAnalysisResultOutput { - /** Whether a potential injection attack is detected or not. */ - attackDetected: boolean; -} - -/** The individual analysis result of potential injection attacks in the given documents. */ -export interface DocumentInjectionAnalysisResultOutput { - /** Whether a potential injection attack is detected or not. */ - attackDetected: boolean; -} - -/** The combined detection results of potential protected material. */ -export interface DetectTextProtectedMaterialResultOutput { - /** Analysis result for the given text. */ - protectedMaterialAnalysis: TextProtectedMaterialAnalysisResultOutput; -} - -/** The individual detection result of potential protected material. */ -export interface TextProtectedMaterialAnalysisResultOutput { - /** Whether potential protected material is detected or not. */ - detected: boolean; -} - /** Text Blocklist. */ export interface TextBlocklistOutput { /** Text blocklist name. */ @@ -105,8 +73,6 @@ export interface TextBlocklistItemOutput { description?: string; /** BlocklistItem content. The length is counted using Unicode code point. */ text: string; - /** An optional properties indicating whether this item is to be matched as a regular expression. */ - isRegex?: boolean; } /** The response of adding blocklistItems to the text blocklist. */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts index aff8ba3cde9f..53908a907ace 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts @@ -5,8 +5,6 @@ import type { RequestParameters } from "@azure-rest/core-client"; import type { AnalyzeImageOptions, AnalyzeTextOptions, - ShieldPromptOptions, - DetectTextProtectedMaterialOptions, TextBlocklist, AddOrUpdateTextBlocklistItemsOptions, RemoveTextBlocklistItemsOptions, @@ -25,21 +23,6 @@ export interface AnalyzeTextBodyParam { } export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; - -export interface ShieldPromptBodyParam { - /** The request body to be detected, which may contain direct or indirect injection attacks. */ - body: ShieldPromptOptions; -} - -export type ShieldPromptParameters = ShieldPromptBodyParam & RequestParameters; - -export interface DetectTextProtectedMaterialBodyParam { - /** The request body to be detected, which may contain protected material. */ - body: DetectTextProtectedMaterialOptions; -} - -export type DetectTextProtectedMaterialParameters = DetectTextProtectedMaterialBodyParam & - RequestParameters; export type GetTextBlocklistParameters = RequestParameters; /** The resource instance. */ export type TextBlocklistResourceMergeAndPatch = Partial; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts index 79af3e4b2da8..a2a13593fb7e 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts @@ -6,8 +6,6 @@ import type { HttpResponse, ErrorResponse } from "@azure-rest/core-client"; import type { AnalyzeImageResultOutput, AnalyzeTextResultOutput, - ShieldPromptResultOutput, - DetectTextProtectedMaterialResultOutput, TextBlocklistOutput, PagedTextBlocklistOutput, AddOrUpdateTextBlocklistItemsResultOutput, @@ -49,40 +47,6 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse { headers: RawHttpHeaders & AnalyzeTextDefaultHeaders; } -/** The request has succeeded. */ -export interface ShieldPrompt200Response extends HttpResponse { - status: "200"; - body: ShieldPromptResultOutput; -} - -export interface ShieldPromptDefaultHeaders { - /** String error code indicating what went wrong. */ - "x-ms-error-code"?: string; -} - -export interface ShieldPromptDefaultResponse extends HttpResponse { - status: string; - body: ErrorResponse; - headers: RawHttpHeaders & ShieldPromptDefaultHeaders; -} - -/** The request has succeeded. */ -export interface DetectTextProtectedMaterial200Response extends HttpResponse { - status: "200"; - body: DetectTextProtectedMaterialResultOutput; -} - -export interface DetectTextProtectedMaterialDefaultHeaders { - /** String error code indicating what went wrong. */ - "x-ms-error-code"?: string; -} - -export interface DetectTextProtectedMaterialDefaultResponse extends HttpResponse { - status: string; - body: ErrorResponse; - headers: RawHttpHeaders & DetectTextProtectedMaterialDefaultHeaders; -} - /** The request has succeeded. */ export interface GetTextBlocklist200Response extends HttpResponse { status: "200"; diff --git a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml index a028dec380d3..684145dd80d6 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml +++ b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml @@ -1,3 +1,4 @@ directory: specification/cognitiveservices/ContentSafety +commit: d85dc63616d14d9790b224d46aad024e3461955b repo: Azure/azure-rest-api-specs -commit: e6fde2ac19d0202f0e72217a3e0f9edb63dba273 +additionalDirectories: From 5ee70da9ddd4f8eaff44882be15fde2ea484f268 Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:56:37 +0800 Subject: [PATCH 06/12] update --- sdk/contentsafety/ai-content-safety-rest/package.json | 1 - .../ai-content-safety-rest/src/contentSafetyClient.ts | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/package.json b/sdk/contentsafety/ai-content-safety-rest/package.json index 56631a7e041d..0d70fffe6de7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/package.json +++ b/sdk/contentsafety/ai-content-safety-rest/package.json @@ -63,7 +63,6 @@ "dependencies": { "@azure-rest/core-client": "^1.1.4", "@azure/core-auth": "^1.3.0", - "@azure/core-paging": "^1.5.0", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.0", "tslib": "^2.2.0" diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index 03c260d5f9d7..1f01c6d2b6cc 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -54,8 +54,9 @@ export default function createClient( // 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}`; + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; } return next(req); From 3a50bcbbe8b4a7b2242a4e32d2dacd224e63235b Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:59:31 +0800 Subject: [PATCH 07/12] update --- .../review/ai-content-safety.api.md | 20 +++++++++---------- .../ai-content-safety-rest/src/index.ts | 1 - .../test/public/contentSafety.spec.ts | 2 +- .../ai-content-safety-rest/tsp-location.yaml | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index ca99a20a89f7..f2dcce20cfe1 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -4,16 +4,16 @@ ```ts -import type { Client } from '@azure-rest/core-client'; -import type { ClientOptions } from '@azure-rest/core-client'; -import type { ErrorResponse } from '@azure-rest/core-client'; -import type { HttpResponse } from '@azure-rest/core-client'; -import type { KeyCredential } from '@azure/core-auth'; -import type { PathUncheckedResponse } from '@azure-rest/core-client'; -import type { RawHttpHeaders } from '@azure/core-rest-pipeline'; -import type { RequestParameters } from '@azure-rest/core-client'; -import type { StreamableMethod } from '@azure-rest/core-client'; -import type { TokenCredential } from '@azure/core-auth'; +import { Client } from '@azure-rest/core-client'; +import { ClientOptions } from '@azure-rest/core-client'; +import { ErrorResponse } from '@azure-rest/core-client'; +import { HttpResponse } from '@azure-rest/core-client'; +import { KeyCredential } from '@azure/core-auth'; +import { PathUncheckedResponse } from '@azure-rest/core-client'; +import { RawHttpHeaders } from '@azure/core-rest-pipeline'; +import { RequestParameters } from '@azure-rest/core-client'; +import { StreamableMethod } from '@azure-rest/core-client'; +import { TokenCredential } from '@azure/core-auth'; // @public (undocumented) export interface AddOrUpdateBlocklistItems { diff --git a/sdk/contentsafety/ai-content-safety-rest/src/index.ts b/sdk/contentsafety/ai-content-safety-rest/src/index.ts index 445b49c6bfe9..b0791e7a658a 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/index.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/index.ts @@ -12,5 +12,4 @@ export * from "./models.js"; export * from "./outputModels.js"; export * from "./paginateHelper.js"; -// eslint-disable-next-line @azure/azure-sdk/ts-modules-only-named export default ContentSafetyClient; diff --git a/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts b/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts index 090333d01cae..29bff673d55b 100644 --- a/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts +++ b/sdk/contentsafety/ai-content-safety-rest/test/public/contentSafety.spec.ts @@ -192,7 +192,7 @@ describe("Content Safety Client Test", () => { const items: TextBlocklistItemOutput[] = []; for await (const item of < PagedAsyncIterableIterator - >iter) { + >iter) { items.push(item); } assert.equal(items[1].blocklistItemId, blockItemId); diff --git a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml index 684145dd80d6..a607d2e6fafe 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml +++ b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml @@ -1,4 +1,4 @@ directory: specification/cognitiveservices/ContentSafety commit: d85dc63616d14d9790b224d46aad024e3461955b -repo: Azure/azure-rest-api-specs -additionalDirectories: +repo: ../azure-rest-api-specs +additionalDirectories: From 6551defa7966bd5bb3f1329dc02d7b9141d781ec Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:08:19 +0800 Subject: [PATCH 08/12] Update ai-content-safety.api.md --- .../review/ai-content-safety.api.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index f2dcce20cfe1..ca99a20a89f7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -4,16 +4,16 @@ ```ts -import { Client } from '@azure-rest/core-client'; -import { ClientOptions } from '@azure-rest/core-client'; -import { ErrorResponse } from '@azure-rest/core-client'; -import { HttpResponse } from '@azure-rest/core-client'; -import { KeyCredential } from '@azure/core-auth'; -import { PathUncheckedResponse } from '@azure-rest/core-client'; -import { RawHttpHeaders } from '@azure/core-rest-pipeline'; -import { RequestParameters } from '@azure-rest/core-client'; -import { StreamableMethod } from '@azure-rest/core-client'; -import { TokenCredential } from '@azure/core-auth'; +import type { Client } from '@azure-rest/core-client'; +import type { ClientOptions } from '@azure-rest/core-client'; +import type { ErrorResponse } from '@azure-rest/core-client'; +import type { HttpResponse } from '@azure-rest/core-client'; +import type { KeyCredential } from '@azure/core-auth'; +import type { PathUncheckedResponse } from '@azure-rest/core-client'; +import type { RawHttpHeaders } from '@azure/core-rest-pipeline'; +import type { RequestParameters } from '@azure-rest/core-client'; +import type { StreamableMethod } from '@azure-rest/core-client'; +import type { TokenCredential } from '@azure/core-auth'; // @public (undocumented) export interface AddOrUpdateBlocklistItems { From 034e82ad8bb8781fda6f935bb9580cbbcb45899a Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:17:04 +0800 Subject: [PATCH 09/12] Update contentSafetyClient.ts --- .../ai-content-safety-rest/src/contentSafetyClient.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index 7c06a9ea69b4..3173e1a7b5d3 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -26,7 +26,7 @@ export default function createClient( { apiVersion = "2023-10-01", ...options }: ContentSafetyClientOptions = {}, ): ContentSafetyClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`; - const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`; + const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` @@ -54,9 +54,8 @@ export default function createClient( // 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}`; + req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; } return next(req); From 551c5756250416a54f4025a833a2a4684c271181 Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:18:06 +0800 Subject: [PATCH 10/12] Update contentSafetyClient.ts --- .../ai-content-safety-rest/src/contentSafetyClient.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index 3173e1a7b5d3..a85c0491bcdb 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -54,8 +54,9 @@ export default function createClient( // 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}`; + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; } return next(req); From 725102ada05ba4f68e6bc538f8b315e8c9807e03 Mon Sep 17 00:00:00 2001 From: ZiWei Chen <98569699+kazrael2119@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:04:59 +0800 Subject: [PATCH 11/12] Update sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md --- sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md b/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md index 6a7d507470f7..1cfafaacb724 100644 --- a/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md +++ b/sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.1 (2024-09-09) +## 1.0.1 (2024-12-16) ### Features Added -refresh @azure-rest/ai-content-safety sdk From 6285f34af03baf65e813dcefc1c35aa859118f2c Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:16:47 +0800 Subject: [PATCH 12/12] Create eslint.config.mjs --- .../ai-content-safety-rest/eslint.config.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sdk/contentsafety/ai-content-safety-rest/eslint.config.mjs diff --git a/sdk/contentsafety/ai-content-safety-rest/eslint.config.mjs b/sdk/contentsafety/ai-content-safety-rest/eslint.config.mjs new file mode 100644 index 000000000000..b57e15e8e044 --- /dev/null +++ b/sdk/contentsafety/ai-content-safety-rest/eslint.config.mjs @@ -0,0 +1,9 @@ +import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; + +export default azsdkEslint.config([ + { + rules: { + "@azure/azure-sdk/ts-modules-only-named": "warn", + }, + }, +]);