Skip to content

Commit

Permalink
Add content safety to smoke test (#1975)
Browse files Browse the repository at this point in the history
* add-content-safety-to-smoke-test

* manual fix some compile errors

* fix compile errors like options rename and body serialization

* fix smoke test in ci

* do not use project javascript and friendlyName for rlc

* fix rlc model project name and friendlyname

* resolve comments

* remove useless code

* use request options if conflicts
  • Loading branch information
qiaozha authored Aug 18, 2023
1 parent ad941f9 commit b38e9e2
Show file tree
Hide file tree
Showing 45 changed files with 2,955 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
"rules": {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"tsdoc/syntax": "warn"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Azure ContentSafety REST client library for JavaScript

Analyze harmful content

**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**

Key links:

- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/ai-content-safety)
- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure-rest/ai-content-safety)

## Getting started

### Currently supported environments

- LTS versions of Node.js

### Prerequisites

- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.

### Install the `@azure-rest/ai-content-safety` package

Install the Azure ContentSafety REST client REST client library for JavaScript with `npm`:

```bash
npm install @azure-rest/ai-content-safety
```

### Create and authenticate a `ContentSafetyClient`

To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
provide an instance of the desired credential type obtained from the
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.

To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)

After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
can be used to authenticate the client.

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

## Troubleshooting

### Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```javascript
const { setLogLevel } = require("@azure/logger");

setLogLevel("info");
```

For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$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" },
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./types/ai-content-safety.d.ts"
},
"messages": {
"tsdocMessageReporting": { "default": { "logLevel": "none" } },
"extractorMessageReporting": {
"ae-missing-release-tag": { "logLevel": "none" },
"ae-unresolved-link": { "logLevel": "none" }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"name": "@azure-rest/ai-content-safety",
"sdk-type": "client",
"author": "Microsoft Corporation",
"version": "1.0.0",
"description": "ContentSafety Service",
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"type": "module",
"main": "dist/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/ai-content-safety.d.ts",
"exports": {
".": {
"types": "./types/src/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist-esm/src/index.js"
},
"./api": {
"types": "./types/src/api/index.d.ts",
"import": "./dist-esm/src/api/index.js"
},
"./models": {
"types": "./types/src/models/index.d.ts",
"import": "./dist-esm/src/models/index.js"
}
},
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
"files": [
"dist/",
"dist-esm/",
"types/ai-content-safety.d.ts",
"README.md",
"LICENSE",
"review/*"
],
"engines": { "node": ">=14.0.0" },
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "echo skipped.",
"build:node": "echo skipped.",
"build:samples": "echo skipped.",
"build:test": "echo skipped.",
"build:debug": "echo skipped.",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
"clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
"execute:samples": "echo skipped",
"extract-api": "rimraf review && mkdirp ./review && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
"generate:client": "echo skipped",
"integration-test:browser": "echo skipped",
"integration-test:node": "echo skipped",
"integration-test": "echo skipped",
"lint:fix": "eslint package.json api-extractor.json src --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src --ext .ts",
"pack": "npm pack 2>&1",
"test:browser": "echo skipped",
"test:node": "echo skipped",
"test": "echo \"Error: no test specified\" && exit 1",
"unit-test": "echo skipped",
"unit-test:node": "echo skipped",
"unit-test:browser": "echo skipped",
"build": "npm run clean && tsc && rollup -c 2>&1 && npm run minify && mkdirp ./review && npm run extract-api",
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js"
},
"sideEffects": false,
"autoPublish": false,
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure-rest/core-client": "^1.1.4",
"@azure/core-rest-pipeline": "^1.12.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0",
"@azure/core-paging": "^1.5.0",
"@azure/core-util": "^1.4.0"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.31.1",
"autorest": "latest",
"@types/node": "^14.0.0",
"dotenv": "^16.0.0",
"eslint": "^8.0.0",
"mkdirp": "^2.1.2",
"prettier": "^2.5.1",
"rimraf": "^3.0.0",
"source-map-support": "^0.5.9",
"typescript": "~5.0.0",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-multi-entry": "^6.0.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"rollup": "^2.66.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"uglify-js": "^3.4.9"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
## API Report File for "@azure-rest/ai-content-safety"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

import { ClientOptions } from '@azure-rest/core-client';
import { KeyCredential } from '@azure/core-auth';
import { OperationOptions } from '@azure-rest/core-client';
import { TokenCredential } from '@azure/core-auth';

// @public (undocumented)
export interface AddOrUpdateBlockItemsRequestOptions extends OperationOptions {
}

// @public
export interface AddOrUpdateBlockItemsResult {
value?: TextBlockItem[];
}

// @public
export type AnalyzeImageOutputType = string;

// @public (undocumented)
export interface AnalyzeImageRequestOptions extends OperationOptions {
categories?: ImageCategory[];
outputType?: AnalyzeImageOutputType;
}

// @public
export interface AnalyzeImageResult {
analyzeResults: ImageAnalyzeSeverityResult[];
}

// @public
export type AnalyzeTextOutputType = string;

// @public (undocumented)
export interface AnalyzeTextRequestOptions extends OperationOptions {
blocklistNames?: string[];
breakByBlocklists?: boolean;
categories?: TextCategory[];
outputType?: AnalyzeTextOutputType;
}

// @public
export interface AnalyzeTextResult {
analyzeResults: TextAnalyzeSeverityResult[];
blocklistsMatchResults?: TextBlocklistMatchResult[];
}

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

// @public (undocumented)
export interface ContentSafetyClientOptions extends ClientOptions {
}

// @public (undocumented)
export interface CreateOrUpdateTextBlocklistOptions extends OperationOptions {
contentType?: string;
description?: string;
}

// @public (undocumented)
export interface DeleteTextBlocklistOptions extends OperationOptions {
}

// @public (undocumented)
export interface GetTextBlocklistItemOptions extends OperationOptions {
}

// @public (undocumented)
export interface GetTextBlocklistOptions extends OperationOptions {
}

// @public
export interface ImageAnalyzeSeverityResult {
category: ImageCategory;
severity?: number;
}

// @public
export type ImageCategory = string;

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

// @public (undocumented)
export interface ListTextBlocklistItemsOptions extends OperationOptions {
maxpagesize?: number;
skip?: number;
top?: number;
}

// @public (undocumented)
export interface ListTextBlocklistsOptions extends OperationOptions {
}

// @public
export interface PagedTextBlockItem {
nextLink?: string;
value: TextBlockItem[];
}

// @public
export interface PagedTextBlocklist {
nextLink?: string;
value: TextBlocklist[];
}

// @public (undocumented)
export interface RemoveBlockItemsRequestOptions extends OperationOptions {
}

// @public
export interface TextAnalyzeSeverityResult {
category: TextCategory;
severity?: number;
}

// @public
export interface TextBlockItem {
readonly blockItemId: string;
description?: string;
text: string;
}

// @public
export interface TextBlockItemInfo {
description?: string;
text: string;
}

// @public
export interface TextBlocklist {
readonly blocklistName: string;
description?: string;
}

// @public
export interface TextBlocklistMatchResult {
blockItemId: string;
blockItemText: string;
blocklistName: string;
}

// @public
export type TextCategory = string;

// (No @packageDocumentation comment for this package)

```
Loading

0 comments on commit b38e9e2

Please sign in to comment.