Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 16 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions sdk/contentsafety/ai-content-safety-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Release History

## 1.0.1 (Unreleased)
## 1.0.1 (2024-12-16)

### Features Added

### Breaking Changes

### Bugs Fixed

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

## 1.0.0 (2023-12-13)

Expand Down
9 changes: 9 additions & 0 deletions sdk/contentsafety/ai-content-safety-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -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",
},
},
]);
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -98,17 +96,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 = string;

// @public (undocumented)
export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters;
Expand Down Expand Up @@ -154,20 +148,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 = string;

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

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

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

// @public
Expand Down Expand Up @@ -259,7 +252,7 @@ export type DeleteTextBlocklistParameters = RequestParameters;
export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;

// @public
export type GetPage<TPage> = (pageLink: string, maxPageSize?: number) => Promise<{
export type GetPage<TPage> = (pageLink: string) => Promise<{
page: TPage;
nextPageLink?: string;
}>;
Expand Down Expand Up @@ -330,28 +323,28 @@ 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 = string;

// @public
export interface ImageDataOutput {
export type ImageCategoryOutput = string;

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

// @public (undocumented)
export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse;
export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse;

// @public (undocumented)
export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse;
export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse;

// @public (undocumented)
export function isUnexpected(response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse): response is GetTextBlocklistDefaultResponse;
Expand Down Expand Up @@ -453,10 +446,28 @@ export interface ListTextBlocklistsDefaultResponse extends HttpResponse {
export type ListTextBlocklistsParameters = RequestParameters;

// @public
export type PagedTextBlocklistItemOutput = Paged<TextBlocklistItemOutput>;
export interface PagedAsyncIterableIterator<TElement, TPage = TElement[], TPageSettings = PageSettings> {
[Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;
byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;
next(): Promise<IteratorResult<TElement>>;
}

// @public
export type PagedTextBlocklistOutput = Paged<TextBlocklistOutput>;
export interface PagedTextBlocklistItemOutput {
nextLink?: string;
value: Array<TextBlocklistItemOutput>;
}

// @public
export interface PagedTextBlocklistOutput {
nextLink?: string;
value: Array<TextBlocklistOutput>;
}

// @public
export interface PageSettings {
continuationToken?: string;
}

// @public
export function paginate<TResponse extends PathUncheckedResponse>(client: Client, initialResponse: TResponse, options?: PagingOptions<TResponse>): PagedAsyncIterableIterator<PaginateReturn<TResponse>>;
Expand Down Expand Up @@ -514,8 +525,8 @@ export interface RemoveTextBlocklistItemsOptions {

// @public (undocumented)
export interface Routes {
(path: "/text:analyze"): AnalyzeText;
(path: "/image:analyze"): AnalyzeImage;
(path: "/text:analyze"): AnalyzeText;
(path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist;
(path: "/text/blocklists"): ListTextBlocklists;
(path: "/text/blocklists/{blocklistName}:addOrUpdateBlocklistItems", blocklistName: string): AddOrUpdateBlocklistItems;
Expand Down Expand Up @@ -561,10 +572,16 @@ export type TextBlocklistResourceMergeAndPatch = Partial<TextBlocklist>;

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

// @public
export type TextCategory = string;

// @public
export type TextCategoryOutput = string;

// (No @packageDocumentation comment for this package)

```
24 changes: 12 additions & 12 deletions sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT License.

import type {
AnalyzeTextParameters,
AnalyzeImageParameters,
AnalyzeTextParameters,
GetTextBlocklistParameters,
CreateOrUpdateTextBlocklistParameters,
DeleteTextBlocklistParameters,
Expand All @@ -14,10 +14,10 @@ import type {
ListTextBlocklistItemsParameters,
} from "./parameters.js";
import type {
AnalyzeText200Response,
AnalyzeTextDefaultResponse,
AnalyzeImage200Response,
AnalyzeImageDefaultResponse,
AnalyzeText200Response,
AnalyzeTextDefaultResponse,
GetTextBlocklist200Response,
GetTextBlocklistDefaultResponse,
CreateOrUpdateTextBlocklist200Response,
Expand All @@ -38,20 +38,20 @@ import type {
} from "./responses.js";
import type { Client, StreamableMethod } from "@azure-rest/core-client";

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(
options: AnalyzeTextParameters,
): StreamableMethod<AnalyzeText200Response | AnalyzeTextDefaultResponse>;
}

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<AnalyzeImage200Response | AnalyzeImageDefaultResponse>;
}

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(
options: AnalyzeTextParameters,
): StreamableMethod<AnalyzeText200Response | AnalyzeTextDefaultResponse>;
}

export interface GetTextBlocklist {
/** Returns text blocklist details. */
get(
Expand Down Expand Up @@ -109,10 +109,10 @@ 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/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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ import { logger } from "./logger.js";
import type { TokenCredential, KeyCredential } from "@azure/core-auth";
import type { ContentSafetyClient } from "./clientDefinitions.js";

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

/**
* Initialize a new instance of `ContentSafetyClient`
* @param endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example:
* @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example:
* https://<resource-name>.cognitiveservices.azure.com).
* @param credentials - uniquely identify client credential
* @param options - the parameter for all optional parameters
*/
export default function createClient(
endpoint: string,
endpointParam: string,
credentials: TokenCredential | KeyCredential,
options: ClientOptions = {},
{ apiVersion = "2023-10-01", ...options }: ContentSafetyClientOptions = {},
): ContentSafetyClient {
const baseUrl = options.baseUrl ?? `${endpoint}/contentsafety`;
options.apiVersion = options.apiVersion ?? "2023-10-01";
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`;
const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.1`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
Expand All @@ -39,8 +44,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;
}
1 change: 0 additions & 1 deletion sdk/contentsafety/ai-content-safety-rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 9 additions & 9 deletions sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT License.

import type {
AnalyzeText200Response,
AnalyzeTextDefaultResponse,
AnalyzeImage200Response,
AnalyzeImageDefaultResponse,
AnalyzeText200Response,
AnalyzeTextDefaultResponse,
GetTextBlocklist200Response,
GetTextBlocklistDefaultResponse,
CreateOrUpdateTextBlocklist200Response,
Expand All @@ -26,8 +26,8 @@ import type {
} from "./responses.js";

const responseMap: Record<string, string[]> = {
"POST /text:analyze": ["200"],
"POST /image:analyze": ["200"],
"POST /text:analyze": ["200"],
"GET /text/blocklists/{blocklistName}": ["200"],
"PATCH /text/blocklists/{blocklistName}": ["200", "201"],
"DELETE /text/blocklists/{blocklistName}": ["204"],
Expand All @@ -38,12 +38,12 @@ const responseMap: Record<string, string[]> = {
"GET /text/blocklists/{blocklistName}/blocklistItems": ["200"],
};

export function isUnexpected(
response: AnalyzeText200Response | AnalyzeTextDefaultResponse,
): response is AnalyzeTextDefaultResponse;
export function isUnexpected(
response: AnalyzeImage200Response | AnalyzeImageDefaultResponse,
): response is AnalyzeImageDefaultResponse;
export function isUnexpected(
response: AnalyzeText200Response | AnalyzeTextDefaultResponse,
): response is AnalyzeTextDefaultResponse;
export function isUnexpected(
response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse,
): response is GetTextBlocklistDefaultResponse;
Expand Down Expand Up @@ -73,10 +73,10 @@ export function isUnexpected(
): response is ListTextBlocklistItemsDefaultResponse;
export function isUnexpected(
response:
| AnalyzeText200Response
| AnalyzeTextDefaultResponse
| AnalyzeImage200Response
| AnalyzeImageDefaultResponse
| AnalyzeText200Response
| AnalyzeTextDefaultResponse
| GetTextBlocklist200Response
| GetTextBlocklistDefaultResponse
| CreateOrUpdateTextBlocklist200Response
Expand All @@ -95,8 +95,8 @@ export function isUnexpected(
| ListTextBlocklistItems200Response
| ListTextBlocklistItemsDefaultResponse,
): response is
| AnalyzeTextDefaultResponse
| AnalyzeImageDefaultResponse
| AnalyzeTextDefaultResponse
| GetTextBlocklistDefaultResponse
| CreateOrUpdateTextBlocklistDefaultResponse
| DeleteTextBlocklistDefaultResponse
Expand Down
Loading
Loading