From 37d9e121feaa6f15ed77d3666847d5f99ad96a92 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Fri, 8 Dec 2023 15:58:36 +0000 Subject: [PATCH] CodeGen from PR 25570 in Azure/azure-rest-api-specs Merge ec6e6866e442d9e6ab33fd3cef7ddc23afcb29b4 into d6665aaea57eb608c4142d729d747d75c77e3c14 --- .../ai-content-safety-rest/api-extractor.json | 25 +++- .../ai-content-safety-rest/package.json | 2 +- .../review/ai-content-safety.api.md | 120 ++++++++++++++++++ .../src/clientDefinitions.ts | 61 +++++++-- .../src/contentSafetyClient.ts | 15 ++- .../src/isUnexpected.ts | 57 +++++++-- .../ai-content-safety-rest/src/models.ts | 12 ++ .../src/outputModels.ts | 36 ++++++ .../src/paginateHelper.ts | 33 ++++- .../ai-content-safety-rest/src/parameters.ts | 35 ++++- .../ai-content-safety-rest/src/responses.ts | 40 +++++- .../ai-content-safety-rest/tsconfig.json | 17 ++- .../ai-content-safety-rest/tsp-location.yaml | 4 +- 13 files changed, 410 insertions(+), 47 deletions(-) diff --git a/sdk/contentsafety/ai-content-safety-rest/api-extractor.json b/sdk/contentsafety/ai-content-safety-rest/api-extractor.json index c3efb349c43a..13a4abc8baf1 100644 --- a/sdk/contentsafety/ai-content-safety-rest/api-extractor.json +++ b/sdk/contentsafety/ai-content-safety-rest/api-extractor.json @@ -1,18 +1,31 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", "mainEntryPointFilePath": "./types/src/index.d.ts", - "docModel": { "enabled": true }, - "apiReport": { "enabled": true, "reportFolder": "./review" }, + "docModel": { + "enabled": true + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, "dtsRollup": { "enabled": true, "untrimmedFilePath": "", "publicTrimmedFilePath": "./types/ai-content-safety.d.ts" }, "messages": { - "tsdocMessageReporting": { "default": { "logLevel": "none" } }, + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, "extractorMessageReporting": { - "ae-missing-release-tag": { "logLevel": "none" }, - "ae-unresolved-link": { "logLevel": "none" } + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } } } -} +} \ No newline at end of file diff --git a/sdk/contentsafety/ai-content-safety-rest/package.json b/sdk/contentsafety/ai-content-safety-rest/package.json index d675f7a9a0da..181adf566051 100644 --- a/sdk/contentsafety/ai-content-safety-rest/package.json +++ b/sdk/contentsafety/ai-content-safety-rest/package.json @@ -124,4 +124,4 @@ "disableDocsMs": true, "apiRefLink": "https://docs.microsoft.com/javascript/api/@azure-rest/ai-content-safety?view=azure-node-preview" } -} +} \ No newline at end of file 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..6e74902dcfad 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 @@ -151,6 +151,21 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse { status: string; } +// @public +export interface AnalyzeTextJailbreakOptions { + text: string; +} + +// @public +export interface AnalyzeTextJailbreakOptionsOutput { + text: string; +} + +// @public +export interface AnalyzeTextJailbreakResultOutput { + jailbreakAnalysis: JailbreakAnalysisResultOutput; +} + // @public export interface AnalyzeTextOptions { blocklistNames?: string[]; @@ -172,6 +187,21 @@ export interface AnalyzeTextOptionsOutput { // @public (undocumented) export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; +// @public +export interface AnalyzeTextProtectedMaterialOptions { + text: string; +} + +// @public +export interface AnalyzeTextProtectedMaterialOptionsOutput { + text: string; +} + +// @public +export interface AnalyzeTextProtectedMaterialResultOutput { + protectedMaterialAnalysis: ProtectedMaterialAnalysisResultOutput; +} + // @public export interface AnalyzeTextResultOutput { blocklistsMatch?: Array; @@ -255,6 +285,78 @@ export interface DeleteTextBlocklistDefaultResponse extends HttpResponse { // @public (undocumented) export type DeleteTextBlocklistParameters = RequestParameters; +// @public (undocumented) +export interface DetectTextJailbreak { + post(options: DetectTextJailbreakParameters): StreamableMethod; +} + +// @public +export interface DetectTextJailbreak200Response extends HttpResponse { + // (undocumented) + body: AnalyzeTextJailbreakResultOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface DetectTextJailbreakBodyParam { + body: AnalyzeTextJailbreakOptions; +} + +// @public (undocumented) +export interface DetectTextJailbreakDefaultHeaders { + "x-ms-error-code"?: string; +} + +// @public (undocumented) +export interface DetectTextJailbreakDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponse; + // (undocumented) + headers: RawHttpHeaders & DetectTextJailbreakDefaultHeaders; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type DetectTextJailbreakParameters = DetectTextJailbreakBodyParam & RequestParameters; + +// @public (undocumented) +export interface DetectTextProtectedMaterial { + post(options: DetectTextProtectedMaterialParameters): StreamableMethod; +} + +// @public +export interface DetectTextProtectedMaterial200Response extends HttpResponse { + // (undocumented) + body: AnalyzeTextProtectedMaterialResultOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialBodyParam { + body: AnalyzeTextProtectedMaterialOptions; +} + +// @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 (undocumented) +export type DetectTextProtectedMaterialParameters = DetectTextProtectedMaterialBodyParam & RequestParameters; + // @public export type GetArrayType = T extends Array ? TData : never; @@ -350,6 +452,12 @@ export interface ImageDataOutput { // @public (undocumented) export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse; +// @public (undocumented) +export function isUnexpected(response: DetectTextJailbreak200Response | DetectTextJailbreakDefaultResponse): response is DetectTextJailbreakDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse): response is DetectTextProtectedMaterialDefaultResponse; + // @public (undocumented) export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse; @@ -377,6 +485,11 @@ export function isUnexpected(response: GetTextBlocklistItem200Response | GetText // @public (undocumented) export function isUnexpected(response: ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse): response is ListTextBlocklistItemsDefaultResponse; +// @public +export interface JailbreakAnalysisResultOutput { + detected: boolean; +} + // @public (undocumented) export interface ListTextBlocklistItems { get(options?: ListTextBlocklistItemsParameters): StreamableMethod; @@ -473,6 +586,11 @@ export interface PagingOptions { customGetPage?: GetPage[]>; } +// @public +export interface ProtectedMaterialAnalysisResultOutput { + detected: boolean; +} + // @public (undocumented) export interface RemoveBlocklistItems { post(options: RemoveBlocklistItemsParameters): StreamableMethod; @@ -515,6 +633,8 @@ export interface RemoveTextBlocklistItemsOptions { // @public (undocumented) export interface Routes { (path: "/text:analyze"): AnalyzeText; + (path: "/text:detectJailbreak"): DetectTextJailbreak; + (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; (path: "/image:analyze"): AnalyzeImage; (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; (path: "/text/blocklists"): ListTextBlocklists; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts index 54338d1a135b..4ce580352c7f 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts @@ -3,6 +3,8 @@ import { AnalyzeTextParameters, + DetectTextJailbreakParameters, + DetectTextProtectedMaterialParameters, AnalyzeImageParameters, GetTextBlocklistParameters, CreateOrUpdateTextBlocklistParameters, @@ -16,6 +18,10 @@ import { import { AnalyzeText200Response, AnalyzeTextDefaultResponse, + DetectTextJailbreak200Response, + DetectTextJailbreakDefaultResponse, + DetectTextProtectedMaterial200Response, + DetectTextProtectedMaterialDefaultResponse, AnalyzeImage200Response, AnalyzeImageDefaultResponse, GetTextBlocklist200Response, @@ -45,6 +51,25 @@ export interface AnalyzeText { ): StreamableMethod; } +export interface DetectTextJailbreak { + /** A synchronous API for the analysis of text jailbreak. */ + post( + options: DetectTextJailbreakParameters + ): StreamableMethod< + DetectTextJailbreak200Response | DetectTextJailbreakDefaultResponse + >; +} + +export interface DetectTextProtectedMaterial { + /** A synchronous API for the analysis of protected material. */ + post( + options: DetectTextProtectedMaterialParameters + ): StreamableMethod< + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse + >; +} + 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( @@ -56,7 +81,9 @@ export interface GetTextBlocklist { /** Returns text blocklist details. */ get( options?: GetTextBlocklistParameters - ): StreamableMethod; + ): StreamableMethod< + GetTextBlocklist200Response | GetTextBlocklistDefaultResponse + >; /** Updates a text blocklist. If the blocklistName does not exist, a new blocklist will be created. */ patch( options: CreateOrUpdateTextBlocklistParameters @@ -68,14 +95,18 @@ export interface GetTextBlocklist { /** Deletes a text blocklist. */ delete( options?: DeleteTextBlocklistParameters - ): StreamableMethod; + ): StreamableMethod< + DeleteTextBlocklist204Response | DeleteTextBlocklistDefaultResponse + >; } export interface ListTextBlocklists { /** Get all text blocklists details. */ get( options?: ListTextBlocklistsParameters - ): StreamableMethod; + ): StreamableMethod< + ListTextBlocklists200Response | ListTextBlocklistsDefaultResponse + >; } export interface AddOrUpdateBlocklistItems { @@ -83,7 +114,8 @@ export interface AddOrUpdateBlocklistItems { post( options: AddOrUpdateBlocklistItemsParameters ): StreamableMethod< - AddOrUpdateBlocklistItems200Response | AddOrUpdateBlocklistItemsDefaultResponse + | AddOrUpdateBlocklistItems200Response + | AddOrUpdateBlocklistItemsDefaultResponse >; } @@ -91,30 +123,43 @@ export interface RemoveBlocklistItems { /** Remove blocklistItems from a text blocklist. You can remove at most 100 BlocklistItems in one request. */ post( options: RemoveBlocklistItemsParameters - ): StreamableMethod; + ): StreamableMethod< + RemoveBlocklistItems204Response | RemoveBlocklistItemsDefaultResponse + >; } export interface GetTextBlocklistItem { /** Get blocklistItem by blocklistName and blocklistItemId from a text blocklist. */ get( options?: GetTextBlocklistItemParameters - ): StreamableMethod; + ): StreamableMethod< + GetTextBlocklistItem200Response | GetTextBlocklistItemDefaultResponse + >; } export interface ListTextBlocklistItems { /** Get all blocklistItems in a text blocklist. */ get( options?: ListTextBlocklistItemsParameters - ): StreamableMethod; + ): StreamableMethod< + ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse + >; } export interface Routes { /** Resource for '/text:analyze' has methods for the following verbs: post */ (path: "/text:analyze"): AnalyzeText; + /** Resource for '/text:detectJailbreak' has methods for the following verbs: post */ + (path: "/text:detectJailbreak"): DetectTextJailbreak; + /** Resource for '/text:detectProtectedMaterial' has methods for the following verbs: post */ + (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; /** Resource for '/image:analyze' has methods for the following verbs: post */ (path: "/image:analyze"): AnalyzeImage; /** Resource for '/text/blocklists/\{blocklistName\}' has methods for the following verbs: get, patch, delete */ - (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; + ( + path: "/text/blocklists/{blocklistName}", + blocklistName: string + ): GetTextBlocklist; /** Resource for '/text/blocklists' has methods for the following verbs: get */ (path: "/text/blocklists"): ListTextBlocklists; /** Resource for '/text/blocklists/\{blocklistName\}:addOrUpdateBlocklistItems' has methods for the following verbs: post */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index 9fa600ed5b0a..56645db99f11 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -19,7 +19,7 @@ export default function createClient( options: ClientOptions = {} ): ContentSafetyClient { const baseUrl = options.baseUrl ?? `${endpoint}/contentsafety`; - options.apiVersion = options.apiVersion ?? "2023-10-01"; + options.apiVersion = options.apiVersion ?? "2023-10-15-preview"; const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -34,12 +34,19 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, credentials: { - scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"], - apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", + scopes: options.credentials?.scopes ?? [ + "https://cognitiveservices.azure.com/.default", + ], + apiKeyHeaderName: + options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient(baseUrl, credentials, options) as ContentSafetyClient; + const client = getClient( + baseUrl, + credentials, + options + ) as ContentSafetyClient; return client; } diff --git a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts index 15459984e6de..b179d201222f 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts @@ -4,6 +4,10 @@ import { AnalyzeText200Response, AnalyzeTextDefaultResponse, + DetectTextJailbreak200Response, + DetectTextJailbreakDefaultResponse, + DetectTextProtectedMaterial200Response, + DetectTextProtectedMaterialDefaultResponse, AnalyzeImage200Response, AnalyzeImageDefaultResponse, GetTextBlocklist200Response, @@ -27,6 +31,8 @@ import { const responseMap: Record = { "POST /text:analyze": ["200"], + "POST /text:detectJailbreak": ["200"], + "POST /text:detectProtectedMaterial": ["200"], "POST /image:analyze": ["200"], "GET /text/blocklists/{blocklistName}": ["200"], "PATCH /text/blocklists/{blocklistName}": ["200", "201"], @@ -34,13 +40,23 @@ const responseMap: Record = { "GET /text/blocklists": ["200"], "POST /text/blocklists/{blocklistName}:addOrUpdateBlocklistItems": ["200"], "POST /text/blocklists/{blocklistName}:removeBlocklistItems": ["204"], - "GET /text/blocklists/{blocklistName}/blocklistItems/{blocklistItemId}": ["200"], + "GET /text/blocklists/{blocklistName}/blocklistItems/{blocklistItemId}": [ + "200", + ], "GET /text/blocklists/{blocklistName}/blocklistItems": ["200"], }; export function isUnexpected( response: AnalyzeText200Response | AnalyzeTextDefaultResponse ): response is AnalyzeTextDefaultResponse; +export function isUnexpected( + response: DetectTextJailbreak200Response | DetectTextJailbreakDefaultResponse +): response is DetectTextJailbreakDefaultResponse; +export function isUnexpected( + response: + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse +): response is DetectTextProtectedMaterialDefaultResponse; export function isUnexpected( response: AnalyzeImage200Response | AnalyzeImageDefaultResponse ): response is AnalyzeImageDefaultResponse; @@ -60,21 +76,33 @@ export function isUnexpected( response: ListTextBlocklists200Response | ListTextBlocklistsDefaultResponse ): response is ListTextBlocklistsDefaultResponse; export function isUnexpected( - response: AddOrUpdateBlocklistItems200Response | AddOrUpdateBlocklistItemsDefaultResponse + response: + | AddOrUpdateBlocklistItems200Response + | AddOrUpdateBlocklistItemsDefaultResponse ): response is AddOrUpdateBlocklistItemsDefaultResponse; export function isUnexpected( - response: RemoveBlocklistItems204Response | RemoveBlocklistItemsDefaultResponse + response: + | RemoveBlocklistItems204Response + | RemoveBlocklistItemsDefaultResponse ): response is RemoveBlocklistItemsDefaultResponse; export function isUnexpected( - response: GetTextBlocklistItem200Response | GetTextBlocklistItemDefaultResponse + response: + | GetTextBlocklistItem200Response + | GetTextBlocklistItemDefaultResponse ): response is GetTextBlocklistItemDefaultResponse; export function isUnexpected( - response: ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse + response: + | ListTextBlocklistItems200Response + | ListTextBlocklistItemsDefaultResponse ): response is ListTextBlocklistItemsDefaultResponse; export function isUnexpected( response: | AnalyzeText200Response | AnalyzeTextDefaultResponse + | DetectTextJailbreak200Response + | DetectTextJailbreakDefaultResponse + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse | AnalyzeImage200Response | AnalyzeImageDefaultResponse | GetTextBlocklist200Response @@ -96,6 +124,8 @@ export function isUnexpected( | ListTextBlocklistItemsDefaultResponse ): response is | AnalyzeTextDefaultResponse + | DetectTextJailbreakDefaultResponse + | DetectTextProtectedMaterialDefaultResponse | AnalyzeImageDefaultResponse | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklistDefaultResponse @@ -137,17 +167,24 @@ function getParametrizedPathSuccess(method: string, path: string): string[] { // track if we have found a match to return the values found. let found = true; - for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) { - if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) { + for ( + let i = candidateParts.length - 1, j = pathParts.length - 1; + i >= 1 && j >= 1; + i--, j-- + ) { + if ( + candidateParts[i]?.startsWith("{") && + candidateParts[i]?.indexOf("}") !== -1 + ) { const start = candidateParts[i]!.indexOf("}") + 1, end = candidateParts[i]?.length; // If the current part of the candidate is a "template" part // Try to use the suffix of pattern to match the path // {guid} ==> $ // {guid}:export ==> :export$ - const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test( - pathParts[j] || "" - ); + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}` + ).test(pathParts[j] || ""); if (!isMatched) { found = false; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/models.ts b/sdk/contentsafety/ai-content-safety-rest/src/models.ts index f3368faf30b4..2b83ae26a190 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/models.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/models.ts @@ -19,6 +19,18 @@ export interface AnalyzeTextOptions { outputType?: string; } +/** The text jailbreak analysis request. */ +export interface AnalyzeTextJailbreakOptions { + /** The text needs to be analyzed if it attempt to jailbreak. We support a maximum of 1k Unicode characters (Unicode code points) in the text of one request. */ + text: string; +} + +/** The protected material analysis request. */ +export interface AnalyzeTextProtectedMaterialOptions { + /** The text needs to be analyzed. We support a maximum of 1k Unicode characters (Unicode code points) in the text of one request. */ + text: string; +} + /** The image analysis request. */ export interface AnalyzeImageOptions { /** The image needs to be analyzed. */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts index ac215a7b18fa..3f1d2b5499e1 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts @@ -51,6 +51,42 @@ export interface TextCategoriesAnalysisOutput { severity?: number; } +/** The text jailbreak analysis request. */ +export interface AnalyzeTextJailbreakOptionsOutput { + /** The text needs to be analyzed if it attempt to jailbreak. We support a maximum of 1k Unicode characters (Unicode code points) in the text of one request. */ + text: string; +} + +/** The text jailbreak analysis request. */ +export interface AnalyzeTextJailbreakResultOutput { + /** Analysis result for jailbreak. */ + jailbreakAnalysis: JailbreakAnalysisResultOutput; +} + +/** The text jailbreak analysis response. */ +export interface JailbreakAnalysisResultOutput { + /** Analysis result for jailbreak. */ + detected: boolean; +} + +/** The protected material analysis request. */ +export interface AnalyzeTextProtectedMaterialOptionsOutput { + /** The text needs to be analyzed. We support a maximum of 1k Unicode characters (Unicode code points) in the text of one request. */ + text: string; +} + +/** The protected material analysis response. */ +export interface AnalyzeTextProtectedMaterialResultOutput { + /** Analysis result for protected material. */ + protectedMaterialAnalysis: ProtectedMaterialAnalysisResultOutput; +} + +/** The text protected material analysis response. */ +export interface ProtectedMaterialAnalysisResultOutput { + /** Analysis result for protected material.. */ + detected: boolean; +} + /** The image analysis request. */ export interface AnalyzeImageOptionsOutput { /** The image needs to be analyzed. */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts b/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts index 477bace4a37f..1c9af35b1efd 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts @@ -1,8 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getPagedAsyncIterator, PagedAsyncIterableIterator, PagedResult } from "@azure/core-paging"; -import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; +import { + getPagedAsyncIterator, + PagedAsyncIterableIterator, + PagedResult, +} from "@azure/core-paging"; +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; /** * Helper type to extract the type of an array @@ -67,7 +75,9 @@ export function paginate( typeof customGetPage === "function" ? customGetPage : async (pageLink: string) => { - const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get(); + const result = firstRun + ? initialResponse + : await client.pathUnchecked(pageLink).get(); firstRun = false; checkPagingRequest(result); const nextLink = getNextLink(result.body, nextLinkName); @@ -93,7 +103,9 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; if (typeof nextLink !== "string" && typeof nextLink !== "undefined") { - throw new Error(`Body Property ${nextLinkName} should be a string or undefined`); + throw new Error( + `Body Property ${nextLinkName} should be a string or undefined` + ); } return nextLink; @@ -121,7 +133,18 @@ function getElements(body: unknown, itemName: string): T[] { * Checks if a request failed */ function checkPagingRequest(response: PathUncheckedResponse): void { - const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"]; + const Http2xxStatusCodes = [ + "200", + "201", + "202", + "203", + "204", + "205", + "206", + "207", + "208", + "226", + ]; if (!Http2xxStatusCodes.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts index 85a8b04c5d7f..4600cf57e1e8 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts @@ -4,6 +4,8 @@ import { RequestParameters } from "@azure-rest/core-client"; import { AnalyzeTextOptions, + AnalyzeTextJailbreakOptions, + AnalyzeTextProtectedMaterialOptions, AnalyzeImageOptions, TextBlocklist, AddOrUpdateTextBlocklistItemsOptions, @@ -17,6 +19,22 @@ export interface AnalyzeTextBodyParam { export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; +export interface DetectTextJailbreakBodyParam { + /** The text jailbreak analysis request. */ + body: AnalyzeTextJailbreakOptions; +} + +export type DetectTextJailbreakParameters = DetectTextJailbreakBodyParam & + RequestParameters; + +export interface DetectTextProtectedMaterialBodyParam { + /** The text protected material analysis request. */ + body: AnalyzeTextProtectedMaterialOptions; +} + +export type DetectTextProtectedMaterialParameters = + DetectTextProtectedMaterialBodyParam & RequestParameters; + export interface AnalyzeImageBodyParam { /** The image analysis request. */ body: AnalyzeImageOptions; @@ -37,9 +55,10 @@ export interface CreateOrUpdateTextBlocklistMediaTypesParam { contentType: "application/merge-patch+json"; } -export type CreateOrUpdateTextBlocklistParameters = CreateOrUpdateTextBlocklistMediaTypesParam & - CreateOrUpdateTextBlocklistBodyParam & - RequestParameters; +export type CreateOrUpdateTextBlocklistParameters = + CreateOrUpdateTextBlocklistMediaTypesParam & + CreateOrUpdateTextBlocklistBodyParam & + RequestParameters; export type DeleteTextBlocklistParameters = RequestParameters; export type ListTextBlocklistsParameters = RequestParameters; @@ -48,15 +67,16 @@ export interface AddOrUpdateBlocklistItemsBodyParam { body: AddOrUpdateTextBlocklistItemsOptions; } -export type AddOrUpdateBlocklistItemsParameters = AddOrUpdateBlocklistItemsBodyParam & - RequestParameters; +export type AddOrUpdateBlocklistItemsParameters = + AddOrUpdateBlocklistItemsBodyParam & RequestParameters; export interface RemoveBlocklistItemsBodyParam { /** Options for removing blocklist items. */ body: RemoveTextBlocklistItemsOptions; } -export type RemoveBlocklistItemsParameters = RemoveBlocklistItemsBodyParam & RequestParameters; +export type RemoveBlocklistItemsParameters = RemoveBlocklistItemsBodyParam & + RequestParameters; export type GetTextBlocklistItemParameters = RequestParameters; export interface ListTextBlocklistItemsQueryParamProperties { @@ -72,4 +92,5 @@ export interface ListTextBlocklistItemsQueryParam { queryParameters?: ListTextBlocklistItemsQueryParamProperties; } -export type ListTextBlocklistItemsParameters = ListTextBlocklistItemsQueryParam & RequestParameters; +export type ListTextBlocklistItemsParameters = + ListTextBlocklistItemsQueryParam & RequestParameters; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts index fb92d26ddc33..5821b02830b7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts @@ -5,6 +5,8 @@ import { RawHttpHeaders } from "@azure/core-rest-pipeline"; import { HttpResponse, ErrorResponse } from "@azure-rest/core-client"; import { AnalyzeTextResultOutput, + AnalyzeTextJailbreakResultOutput, + AnalyzeTextProtectedMaterialResultOutput, AnalyzeImageResultOutput, TextBlocklistOutput, PagedTextBlocklistOutput, @@ -30,6 +32,41 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse { headers: RawHttpHeaders & AnalyzeTextDefaultHeaders; } +/** The request has succeeded. */ +export interface DetectTextJailbreak200Response extends HttpResponse { + status: "200"; + body: AnalyzeTextJailbreakResultOutput; +} + +export interface DetectTextJailbreakDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DetectTextJailbreakDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DetectTextJailbreakDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DetectTextProtectedMaterial200Response extends HttpResponse { + status: "200"; + body: AnalyzeTextProtectedMaterialResultOutput; +} + +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 AnalyzeImage200Response extends HttpResponse { status: "200"; @@ -81,7 +118,8 @@ export interface CreateOrUpdateTextBlocklistDefaultHeaders { "x-ms-error-code"?: string; } -export interface CreateOrUpdateTextBlocklistDefaultResponse extends HttpResponse { +export interface CreateOrUpdateTextBlocklistDefaultResponse + extends HttpResponse { status: string; body: ErrorResponse; headers: RawHttpHeaders & CreateOrUpdateTextBlocklistDefaultHeaders; diff --git a/sdk/contentsafety/ai-content-safety-rest/tsconfig.json b/sdk/contentsafety/ai-content-safety-rest/tsconfig.json index ddbefcd7cd49..766326d1019f 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsconfig.json +++ b/sdk/contentsafety/ai-content-safety-rest/tsconfig.json @@ -3,10 +3,19 @@ "compilerOptions": { "outDir": "./dist-esm", "declarationDir": "./types", - "lib": ["es6", "dom"], + "lib": [ + "es6", + "dom" + ], "paths": { - "@azure-rest/ai-content-safety": ["./src/index"] + "@azure-rest/ai-content-safety": [ + "./src/index" + ] } }, - "include": ["src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] -} + "include": [ + "src/**/*.ts", + "./test/**/*.ts", + "samples-dev/**/*.ts" + ] +} \ No newline at end of file diff --git a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml index 9d47983f6b57..be958628e65a 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml +++ b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml @@ -1,3 +1,5 @@ +commit: f6df1620ee317ac5f4067a4255131b6384657baf directory: specification/cognitiveservices/ContentSafety repo: Azure/azure-rest-api-specs -commit: 164375e67a1bffb207bcf603772c289dbe42d7b5 +additionalDirectories: [] +