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

[Cognitive Services - Azure AI Content Safety] - [Private Preview] - Add Image Batch Detection #27353

Merged
Merged
Show file tree
Hide file tree
Changes from 14 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
11 changes: 10 additions & 1 deletion cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,16 @@
"words": [
"throughputpool"
]
}
},
{
"filename": "**/specification/cognitiveservices/data-plane/ContentSafety/**/*.json",
"words": [
"Ungroundedness",
"ungroundedness",
"Selfharm",
"Withtext"
]
}
],
"enableFiletypes": [
"cadl"
Expand Down
3 changes: 0 additions & 3 deletions specification/cognitiveservices/ContentSafety/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,4 @@ enum Versions {

@useDependency(Azure.Core.Versions.v1_0_Preview_2)
v2023_10_30_Preview: "2023-10-30-preview",

@useDependency(Azure.Core.Versions.v1_0_Preview_2)
v2024_01_30_Preview: "2024-01-30-preview",
}
125 changes: 124 additions & 1 deletion specification/cognitiveservices/ContentSafety/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ enum AnalyzeImageOutputType {
FourSeverityLevels,
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The type of batch results storage mode.")
enum BatchResultsStorageMode {
@doc("Merge each result into one file.")
CollectiveResultFile,

@doc("Store each result in a single file.")
IndividualResultFiles,
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The type of batch analysis task status.")
enum BatchTaskStatus {
@doc("The task has not started yet.")
NotStarted,

@doc("The task is in progress.")
Running,

@doc("The task has failed.")
Failed,

@doc("The task has been succeeded.")
Succeeded,
}

@doc("The text analysis request.")
model AnalyzeTextOptions {
@doc("The text needs to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request.")
Expand Down Expand Up @@ -85,7 +111,7 @@ model AnalyzeTextResult {
@doc("The incident match details.")
incidentMatches?: IncidentMatch[];

@added(ContentSafety.Versions.v2024_01_30_Preview)
@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("Chunks in the original text detected as harmful content. Analysis result and scores are caused by these.")
citation?: string[];
}
Expand Down Expand Up @@ -169,6 +195,90 @@ model ImageCategoriesAnalysis {
severity?: int32;
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The image batch analysis request.")
model BatchAnalyzeImagesOptions {
@doc("The blob parameters of images to be analyzed.")
images: BatchAnalyzeImages;

@doc("The blob parameters of result files.")
analysisResults: BatchAnalyzeImagesResults;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very confusing name. Even I had to review this several times over again. You might consider not putting anything called "results" in a request model, or at least something like saveResultsLocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the name to "resultsBlob" as ChatGPT suggested. I did not use the word "location" because there is one "blobPrefixLocation" under this concept.


@doc("The storage mode for the batch task results, either 'CollectiveResultFile' or 'IndividualResultFiles'.")
resultsStorageMode?: BatchResultsStorageMode = BatchResultsStorageMode.CollectiveResultFile;

@doc("The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned.")
categories?: ImageCategory[];

@doc("This refers to the type of image analysis output. If no value is assigned, the default value will be 'FourSeverityLevels'.")
outputType?: AnalyzeImageOutputType = AnalyzeImageOutputType.FourSeverityLevels;

@doc("The incidents to detect.")
incidents?: IncidentOptions;
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The image batch analysis input.")
model BatchAnalyzeImages {
@doc("The URL to a blob prefix which represents a directory containing all the images to be analyzed in this batch task.")
blobPrefixLocation: url;

@doc("The delimiter character you desire to use in the location URL, typically '/'.")
delimiter: string;

@doc("An array of strings indicating file extensions of desired images within the logical folder.")
extensions: string[];

@doc("The last modified time (in RFC1123 format) of blobs. Only images that were modified before this time will be analyzed.")
lastModified?: utcDateTime;
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The image batch analysis output.")
model BatchAnalyzeImagesResults {
@doc("The URL to a blob prefix which represents a directory. The analysis result file(s) will be written to this directory.")
blobPrefixLocation: url;

@doc("The delimiter character you desire to use in the location URL, typically '/'.")
delimiter: string;
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("Image batch analyze task.")
@resource("image/batchAnalyses")
model ImageBatchTaskDetail {
@doc("The id of image batch analysis task.")
@key("operationId")
@visibility("read", "create", "query")
@maxLength(64)
id: string;

@doc("The kind of operation.")
kind: string;

@doc("The status of the batch image analysis task.")
status: BatchTaskStatus;

@doc("Batch task result.")
result: ImageBatchTaskResult;

@doc("Return error detail when the task failed.")
error?: Azure.Core.Foundations.Error;
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("Image batch task result.")
model ImageBatchTaskResult {
@doc("The timestamp of when batch image analysis task was created.")
createdTime: utcDateTime;

@doc("The progress of the batch image analysis task, represented as a percentage (0-100).")
progressPercentage: int32;

@doc("The blob parameters of result files.")
analysisResults: BatchAnalyzeImagesResults;
}

@doc("Text Blocklist.")
@resource("text/blocklists")
model TextBlocklist {
Expand Down Expand Up @@ -450,15 +560,20 @@ model AnnotateTextResult {
@added(Versions.v2023_10_30_Preview)
@doc("Pre-defined concept.")
model PreDefinedConcept {
@doc("The concept name.")
concept: string;
@doc("The concept description.")
description: string;
}

@added(Versions.v2023_10_30_Preview)
@doc("Label definition.")
model SubCategory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subcategory is a single word. This is not going to look good in a public-facing API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You even use it as such below in docs. Be consistent. Use single word casing everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out! Changed it to Subcategory

@doc("The id of subcategory.")
id: int32;
@doc("The name of subcategory.")
name: string;
@doc("The description of subcategory.")
statements: string[];
}

Expand All @@ -473,9 +588,16 @@ model TextCustomizedCategory {
@maxLength(64)
categoryName: string;

@doc("Some pre defined concepts used in definition.")
preDefinedConcepts?: PreDefinedConcept[];

@doc("Subcategories in the customized category.")
subCategories: SubCategory[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subCategories: SubCategory[];
subcategories: Subcategory[];

It's a single word.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


@doc("Text customizedCategories emphases.")
emphases?: string[];

@doc("Text url of example jsonl blob.")
exampleBlobUrl?: url;
}

Expand Down Expand Up @@ -539,6 +661,7 @@ enum Task {
QnA,
}

#suppress "@azure-tools/typespec-azure-core/casing-style" "MUST fix in next update"
@added(Versions.v2023_10_30_Preview)
@doc("Connection details for the GPT resource.")
model GptResource {
Expand Down
34 changes: 34 additions & 0 deletions specification/cognitiveservices/ContentSafety/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,40 @@ interface ImageOperations {
>;
}

interface ImageBatchOperations {
#suppress "@azure-tools/typespec-azure-core/no-rpc-path-params" "MUST fix in next update"
@added(ContentSafety.Versions.v2023_10_30_Preview)
@summary("Start Batch Analyze Images")
@doc("An asynchronous API for the batch analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence.")
@route("/image/batchAnalyses")
@put
batchAnalyzeImage is Azure.Core.RpcOperation<
{
@path
@doc("The unique operation id.")
operationId: string;

@body
@doc("The image batch analysis request.")
body: BatchAnalyzeImagesOptions;
},
ImageBatchTaskDetail
>;

@added(ContentSafety.Versions.v2023_10_30_Preview)
@summary("Get Image Batch Analysis task Status")
@doc("Check the status of a batch image analysis task.")
getBatchTaskStatus is Azure.Core.ResourceRead<ImageBatchTaskDetail>;

@added(ContentSafety.Versions.v2023_10_30_Preview)
@summary("List All Image Batch Analysis Tasks")
@doc("List all batch image analysis tasks.")
listBatchTasks is Azure.Core.ResourceList<
ImageBatchTaskDetail,
ListQueryParametersTrait<StandardListQueryParameters>
>;
}

interface BlockOps
extends Azure.Core.ResourceOperations<NoRepeatableRequests &
NoConditionalRequests &
Expand Down
Loading
Loading