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 8 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",
}
203 changes: 71 additions & 132 deletions specification/cognitiveservices/ContentSafety/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum AnalyzeImageOutputType {
FourSeverityLevels,
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The type of batch results storage mode.")
enum BatchResultsStorageMode {
@doc("Merge each result into one file.")
Expand All @@ -50,7 +50,7 @@ enum BatchResultsStorageMode {
IndividualResultFiles,
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The type of batch analysis task status.")
enum BatchTaskStatus {
@doc("The task has not started yet.")
Expand All @@ -66,21 +66,6 @@ enum BatchTaskStatus {
Succeeded,
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
enum ModelStatus {
Created,
Training,
Ready,
Failed,
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
enum GeneratePromptStatus {
Running,
Ready,
Failed,
}

@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 All @@ -102,20 +87,6 @@ model AnalyzeTextOptions {
@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The incidents to detect.")
incidents?: IncidentOptions;

@added(ContentSafety.Versions.v2024_01_30_Preview)
@doc("The customized categories will be analyzed. If they are not assigned, the analysis results for all available customized categories will be returned.")
customizedCategories?: CustomizedCategory[];
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@doc("Customized category for inference.")
model CustomizedCategory {
@doc("Category name")
categoryName: string;

@doc("Model ID for the category. If not provided, the latest available model will be used.")
modelId: string;
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
Expand All @@ -140,32 +111,9 @@ 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[];

@added(ContentSafety.Versions.v2024_01_30_Preview)
@doc("Analysis result for customized categories.")
customizedCategoriesAnalysis: TextCustomizedCategoryAnalysis[];
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@doc("Text customized category analysis result.")
model TextCustomizedCategoryAnalysis {
@doc("Customized category name")
categoryName: string;

@doc("customized category analysis")
customizedCategoriesAnalysis: TextCustomizedCategoryClassResult[];
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@doc("customized category analysis result")
model TextCustomizedCategoryClassResult {
id: int32;

@renamedFrom(Versions.v2024_01_30_Preview, "name")
className: string;
}

@doc("The result of blocklist match.")
Expand Down Expand Up @@ -247,51 +195,90 @@ model ImageCategoriesAnalysis {
severity?: int32;
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The image batch analysis request.")
model BatchAnalyzeImagesOptions {
@doc("The URL of the Azure Storage Blob containing all the images to be analyzed in the batch task.")
imagesBlobFolderUrl: url;
@doc("The blob parameters of images to be analyzed.")
images: BatchAnalyzeImages;

@doc("The URL of the Azure Storage Blob where the batch task results will be written.")
analysisResultsBlobFolderUrl: url;
@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\".")
@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.v2024_01_30_Preview)
@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/batchAnalyzeTasks")
@resource("image/batchAnalyses")
model ImageBatchTaskDetail {
@doc("The id of image batch analysis task.")
@key("taskId")
@visibility("read")
@key("operationId")
@visibility("read", "create", "query")
@maxLength(64)
taskId: string;
id: string;

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

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

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

@doc("The timestamp of when batch image analysis task was created.")
taskCreatedTime: utcDateTime;
@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 @@ -573,19 +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.")
@renamedFrom(Versions.v2024_01_30_Preview, "SubCategory")
model Class {
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;

@renamedFrom(Versions.v2024_01_30_Preview, "name")
className: string;

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

Expand All @@ -600,55 +588,19 @@ model TextCustomizedCategory {
@maxLength(64)
categoryName: string;

@doc("A predefined concept with its definition can be used directly in the subcategories.")
@added(Versions.v2023_10_30_Preview)
@removed(Versions.v2024_01_30_Preview)
@doc("Some pre defined concepts used in definition.")
preDefinedConcepts?: PreDefinedConcept[];

@doc("Subcategories are detailed classes of the category. It is required there is a class 'safe' with id=0.")
@renamedFrom(Versions.v2024_01_30_Preview, "subCategories")
classes: Class[];
@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.


@added(Versions.v2023_10_30_Preview)
@removed(Versions.v2024_01_30_Preview)
@doc("Text customizedCategories emphases.")
emphases?: string[];

@doc("Blob that stores the examples.")
@doc("Text url of example jsonl blob.")
exampleBlobUrl?: url;
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@doc("The response for async training triggering.")
model SubmitModelTrainingResponse {
...AcceptedResponse;

@header("operation-location")
@doc("The location of the status API for monitoring the triggered model.")
modelUrl: string;
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
model AsyncJobWarning {
code: string;
messgae: string;
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@resource("text/generatePromptTasks")
model GeneratePromptTaskDetail {
@doc("The id of image batch analysis task.")
@key("taskId")
@visibility("read")
@maxLength(64)
taskId: string;

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

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

#suppress "@azure-tools/typespec-azure-core/documentation-required" "MUST fix in next update"
@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("ImageWithText analyze category.")
Expand All @@ -659,20 +611,6 @@ enum ImageWithTextCategory {
Violence,
}

@added(ContentSafety.Versions.v2024_01_30_Preview)
@parentResource(TextCustomizedCategory)
@resource("models")
model TextTrainedModel {
@key
modelId: string;

status: ModelStatus;
createdTime: utcDateTime;
lastUpdateTime: utcDateTime;
warnings?: AsyncJobWarning[];
errors?: string[];
}

@added(ContentSafety.Versions.v2023_10_30_Preview)
@doc("The analysis request of the image with text.")
model AnalyzeImageWithTextOptions {
Expand Down Expand Up @@ -723,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
Loading
Loading