From accd92d04c7eb4ed99e338650816011ffc7d5a5a Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 11 Jan 2024 12:38:02 +0000 Subject: [PATCH] CodeGen from PR 27352 in Azure/azure-rest-api-specs Merge 8775b51e07d68b16c555f9251ca87e141d58fd65 into ea28180c6ce9027df36568307f235868d581144c --- .../Azure.AI.ContentSafety.netstandard2.0.cs | 68 +++- .../AnalyzeImageOptions.Serialization.cs | 5 + .../src/Generated/AnalyzeImageOptions.cs | 6 +- .../AnalyzeImageResult.Serialization.cs | 18 +- .../src/Generated/AnalyzeImageResult.cs | 7 +- ...alyzeTextJailbreakOptions.Serialization.cs | 31 ++ .../Generated/AnalyzeTextJailbreakOptions.cs | 29 ++ ...nalyzeTextJailbreakResult.Serialization.cs | 41 +++ .../Generated/AnalyzeTextJailbreakResult.cs | 29 ++ .../AnalyzeTextOptions.Serialization.cs | 5 + .../src/Generated/AnalyzeTextOptions.cs | 6 +- ...tProtectedMaterialOptions.Serialization.cs | 31 ++ .../AnalyzeTextProtectedMaterialOptions.cs | 29 ++ ...xtProtectedMaterialResult.Serialization.cs | 41 +++ .../AnalyzeTextProtectedMaterialResult.cs | 29 ++ .../AnalyzeTextResult.Serialization.cs | 32 +- .../src/Generated/AnalyzeTextResult.cs | 12 +- .../src/Generated/ContentSafetyClient.cs | 254 +++++++++++++++ .../Generated/ContentSafetyClientOptions.cs | 11 +- .../Generated/ContentSafetyModelFactory.cs | 72 ++++- .../Generated/Docs/ContentSafetyClient.xml | 274 ++++++++++++++++ .../Generated/IncidentMatch.Serialization.cs | 41 +++ .../src/Generated/IncidentMatch.cs | 29 ++ .../IncidentOptions.Serialization.cs | 44 +++ .../src/Generated/IncidentOptions.cs | 36 +++ .../JailbreakAnalysisResult.Serialization.cs | 41 +++ .../src/Generated/JailbreakAnalysisResult.cs | 23 ++ ...tedMaterialAnalysisResult.Serialization.cs | 41 +++ .../ProtectedMaterialAnalysisResult.cs | 23 ++ .../Samples/Samples_ContentSafetyClient.cs | 298 ++++++++++++++++++ .../Azure.AI.ContentSafety/tsp-location.yaml | 4 +- 31 files changed, 1594 insertions(+), 16 deletions(-) create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.Serialization.cs create mode 100644 sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.cs diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/api/Azure.AI.ContentSafety.netstandard2.0.cs b/sdk/contentsafety/Azure.AI.ContentSafety/api/Azure.AI.ContentSafety.netstandard2.0.cs index c387b933b594..9f05f51e20dd 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/api/Azure.AI.ContentSafety.netstandard2.0.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/api/Azure.AI.ContentSafety.netstandard2.0.cs @@ -15,6 +15,7 @@ public partial class AnalyzeImageOptions public AnalyzeImageOptions(Azure.AI.ContentSafety.ContentSafetyImageData image) { } public System.Collections.Generic.IList Categories { get { throw null; } } public Azure.AI.ContentSafety.ContentSafetyImageData Image { get { throw null; } } + public Azure.AI.ContentSafety.IncidentOptions Incidents { get { throw null; } set { } } public Azure.AI.ContentSafety.AnalyzeImageOutputType? OutputType { get { throw null; } set { } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] @@ -38,6 +39,17 @@ public partial class AnalyzeImageResult { internal AnalyzeImageResult() { } public System.Collections.Generic.IReadOnlyList CategoriesAnalysis { get { throw null; } } + public System.Collections.Generic.IReadOnlyList IncidentMatches { get { throw null; } } + } + public partial class AnalyzeTextJailbreakOptions + { + public AnalyzeTextJailbreakOptions(string text) { } + public string Text { get { throw null; } } + } + public partial class AnalyzeTextJailbreakResult + { + internal AnalyzeTextJailbreakResult() { } + public Azure.AI.ContentSafety.JailbreakAnalysisResult JailbreakAnalysis { get { throw null; } } } public partial class AnalyzeTextOptions { @@ -45,6 +57,7 @@ public AnalyzeTextOptions(string text) { } public System.Collections.Generic.IList BlocklistNames { get { throw null; } } public System.Collections.Generic.IList Categories { get { throw null; } } public bool? HaltOnBlocklistHit { get { throw null; } set { } } + public Azure.AI.ContentSafety.IncidentOptions Incidents { get { throw null; } set { } } public Azure.AI.ContentSafety.AnalyzeTextOutputType? OutputType { get { throw null; } set { } } public string Text { get { throw null; } } } @@ -66,11 +79,23 @@ public AnalyzeTextOptions(string text) { } public static bool operator !=(Azure.AI.ContentSafety.AnalyzeTextOutputType left, Azure.AI.ContentSafety.AnalyzeTextOutputType right) { throw null; } public override string ToString() { throw null; } } + public partial class AnalyzeTextProtectedMaterialOptions + { + public AnalyzeTextProtectedMaterialOptions(string text) { } + public string Text { get { throw null; } } + } + public partial class AnalyzeTextProtectedMaterialResult + { + internal AnalyzeTextProtectedMaterialResult() { } + public Azure.AI.ContentSafety.ProtectedMaterialAnalysisResult ProtectedMaterialAnalysis { get { throw null; } } + } public partial class AnalyzeTextResult { internal AnalyzeTextResult() { } public System.Collections.Generic.IReadOnlyList BlocklistsMatch { get { throw null; } } public System.Collections.Generic.IReadOnlyList CategoriesAnalysis { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Citation { get { throw null; } } + public System.Collections.Generic.IReadOnlyList IncidentMatches { get { throw null; } } } public partial class BlocklistClient { @@ -131,13 +156,24 @@ public ContentSafetyClient(System.Uri endpoint, Azure.Core.TokenCredential crede public virtual System.Threading.Tasks.Task> AnalyzeTextAsync(Azure.AI.ContentSafety.AnalyzeTextOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task AnalyzeTextAsync(Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } public virtual System.Threading.Tasks.Task> AnalyzeTextAsync(string text, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DetectTextJailbreak(Azure.AI.ContentSafety.AnalyzeTextJailbreakOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DetectTextJailbreak(Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } + public virtual System.Threading.Tasks.Task> DetectTextJailbreakAsync(Azure.AI.ContentSafety.AnalyzeTextJailbreakOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DetectTextJailbreakAsync(Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } + public virtual Azure.Response DetectTextProtectedMaterial(Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DetectTextProtectedMaterial(Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } + public virtual System.Threading.Tasks.Task> DetectTextProtectedMaterialAsync(Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DetectTextProtectedMaterialAsync(Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } } public partial class ContentSafetyClientOptions : Azure.Core.ClientOptions { - public ContentSafetyClientOptions(Azure.AI.ContentSafety.ContentSafetyClientOptions.ServiceVersion version = Azure.AI.ContentSafety.ContentSafetyClientOptions.ServiceVersion.V2023_10_01) { } + public ContentSafetyClientOptions(Azure.AI.ContentSafety.ContentSafetyClientOptions.ServiceVersion version = Azure.AI.ContentSafety.ContentSafetyClientOptions.ServiceVersion.V2024_01_30_Preview) { } public enum ServiceVersion { V2023_10_01 = 1, + V2023_10_15_Preview = 2, + V2023_10_30_Preview = 3, + V2024_01_30_Preview = 4, } } public partial class ContentSafetyImageData @@ -149,9 +185,14 @@ public ContentSafetyImageData(System.Uri blobUri) { } public static partial class ContentSafetyModelFactory { public static Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsResult AddOrUpdateTextBlocklistItemsResult(System.Collections.Generic.IEnumerable blocklistItems = null) { throw null; } - public static Azure.AI.ContentSafety.AnalyzeImageResult AnalyzeImageResult(System.Collections.Generic.IEnumerable categoriesAnalysis = null) { throw null; } - public static Azure.AI.ContentSafety.AnalyzeTextResult AnalyzeTextResult(System.Collections.Generic.IEnumerable blocklistsMatch = null, System.Collections.Generic.IEnumerable categoriesAnalysis = null) { throw null; } + public static Azure.AI.ContentSafety.AnalyzeImageResult AnalyzeImageResult(System.Collections.Generic.IEnumerable categoriesAnalysis = null, System.Collections.Generic.IEnumerable incidentMatches = null) { throw null; } + public static Azure.AI.ContentSafety.AnalyzeTextJailbreakResult AnalyzeTextJailbreakResult(Azure.AI.ContentSafety.JailbreakAnalysisResult jailbreakAnalysis = null) { throw null; } + public static Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialResult AnalyzeTextProtectedMaterialResult(Azure.AI.ContentSafety.ProtectedMaterialAnalysisResult protectedMaterialAnalysis = null) { throw null; } + public static Azure.AI.ContentSafety.AnalyzeTextResult AnalyzeTextResult(System.Collections.Generic.IEnumerable blocklistsMatch = null, System.Collections.Generic.IEnumerable categoriesAnalysis = null, System.Collections.Generic.IEnumerable incidentMatches = null, System.Collections.Generic.IEnumerable citation = null) { throw null; } public static Azure.AI.ContentSafety.ImageCategoriesAnalysis ImageCategoriesAnalysis(Azure.AI.ContentSafety.ImageCategory category = default(Azure.AI.ContentSafety.ImageCategory), int? severity = default(int?)) { throw null; } + public static Azure.AI.ContentSafety.IncidentMatch IncidentMatch(string incidentName = null) { throw null; } + public static Azure.AI.ContentSafety.JailbreakAnalysisResult JailbreakAnalysisResult(bool detected = false) { throw null; } + public static Azure.AI.ContentSafety.ProtectedMaterialAnalysisResult ProtectedMaterialAnalysisResult(bool detected = false) { throw null; } public static Azure.AI.ContentSafety.TextBlocklist TextBlocklist(string name = null, string description = null) { throw null; } public static Azure.AI.ContentSafety.TextBlocklistItem TextBlocklistItem(string blocklistItemId = null, string description = null, string text = null) { throw null; } public static Azure.AI.ContentSafety.TextBlocklistMatch TextBlocklistMatch(string blocklistName = null, string blocklistItemId = null, string blocklistItemText = null) { throw null; } @@ -183,6 +224,27 @@ internal ImageCategoriesAnalysis() { } public static bool operator !=(Azure.AI.ContentSafety.ImageCategory left, Azure.AI.ContentSafety.ImageCategory right) { throw null; } public override string ToString() { throw null; } } + public partial class IncidentMatch + { + internal IncidentMatch() { } + public string IncidentName { get { throw null; } } + } + public partial class IncidentOptions + { + public IncidentOptions() { } + public bool? HaltOnIncidentHit { get { throw null; } set { } } + public System.Collections.Generic.IList IncidentNames { get { throw null; } } + } + public partial class JailbreakAnalysisResult + { + internal JailbreakAnalysisResult() { } + public bool Detected { get { throw null; } } + } + public partial class ProtectedMaterialAnalysisResult + { + internal ProtectedMaterialAnalysisResult() { } + public bool Detected { get { throw null; } } + } public partial class RemoveTextBlocklistItemsOptions { public RemoveTextBlocklistItemsOptions(System.Collections.Generic.IEnumerable blocklistItemIds) { } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.Serialization.cs index 257e8ce31a12..41b751497a9d 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.Serialization.cs @@ -32,6 +32,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("outputType"u8); writer.WriteStringValue(OutputType.Value.ToString()); } + if (Optional.IsDefined(Incidents)) + { + writer.WritePropertyName("incidents"u8); + writer.WriteObjectValue(Incidents); + } writer.WriteEndObject(); } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs index 212cab170c2d..0ea8f2b8c459 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs @@ -29,11 +29,13 @@ public AnalyzeImageOptions(ContentSafetyImageData image) /// The image needs to be analyzed. /// The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. /// This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". - internal AnalyzeImageOptions(ContentSafetyImageData image, IList categories, AnalyzeImageOutputType? outputType) + /// The incidents to detect. + internal AnalyzeImageOptions(ContentSafetyImageData image, IList categories, AnalyzeImageOutputType? outputType, IncidentOptions incidents) { Image = image; Categories = categories; OutputType = outputType; + Incidents = incidents; } /// The image needs to be analyzed. @@ -42,5 +44,7 @@ internal AnalyzeImageOptions(ContentSafetyImageData image, IList public IList Categories { get; } /// This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". public AnalyzeImageOutputType? OutputType { get; set; } + /// The incidents to detect. + public IncidentOptions Incidents { get; set; } } } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.Serialization.cs index fbbf35d2cfa0..d0adaee9fe92 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.Serialization.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.ContentSafety { @@ -20,6 +21,7 @@ internal static AnalyzeImageResult DeserializeAnalyzeImageResult(JsonElement ele return null; } IReadOnlyList categoriesAnalysis = default; + Optional> incidentMatches = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("categoriesAnalysis"u8)) @@ -32,8 +34,22 @@ internal static AnalyzeImageResult DeserializeAnalyzeImageResult(JsonElement ele categoriesAnalysis = array; continue; } + if (property.NameEquals("incidentMatches"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(IncidentMatch.DeserializeIncidentMatch(item)); + } + incidentMatches = array; + continue; + } } - return new AnalyzeImageResult(categoriesAnalysis); + return new AnalyzeImageResult(categoriesAnalysis, Optional.ToList(incidentMatches)); } /// Deserializes the model from a raw response. diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs index 48b5db1e94c2..017da3eaf265 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs @@ -23,16 +23,21 @@ internal AnalyzeImageResult(IEnumerable categoriesAnaly Argument.AssertNotNull(categoriesAnalysis, nameof(categoriesAnalysis)); CategoriesAnalysis = categoriesAnalysis.ToList(); + IncidentMatches = new ChangeTrackingList(); } /// Initializes a new instance of . /// Analysis result for categories. - internal AnalyzeImageResult(IReadOnlyList categoriesAnalysis) + /// The incident match details. + internal AnalyzeImageResult(IReadOnlyList categoriesAnalysis, IReadOnlyList incidentMatches) { CategoriesAnalysis = categoriesAnalysis; + IncidentMatches = incidentMatches; } /// Analysis result for categories. public IReadOnlyList CategoriesAnalysis { get; } + /// The incident match details. + public IReadOnlyList IncidentMatches { get; } } } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.Serialization.cs new file mode 100644 index 000000000000..483e549b722e --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.Serialization.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextJailbreakOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.cs new file mode 100644 index 000000000000..fe48e130513b --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The text jailbreak analysis request. + public partial class AnalyzeTextJailbreakOptions + { + /// Initializes a new instance of . + /// 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. + /// is null. + public AnalyzeTextJailbreakOptions(string text) + { + Argument.AssertNotNull(text, nameof(text)); + + Text = text; + } + + /// 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. + public string Text { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.Serialization.cs new file mode 100644 index 000000000000..ab714eaee01f --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextJailbreakResult + { + internal static AnalyzeTextJailbreakResult DeserializeAnalyzeTextJailbreakResult(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + JailbreakAnalysisResult jailbreakAnalysis = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("jailbreakAnalysis"u8)) + { + jailbreakAnalysis = JailbreakAnalysisResult.DeserializeJailbreakAnalysisResult(property.Value); + continue; + } + } + return new AnalyzeTextJailbreakResult(jailbreakAnalysis); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AnalyzeTextJailbreakResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAnalyzeTextJailbreakResult(document.RootElement); + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.cs new file mode 100644 index 000000000000..dcd0a7c64df6 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The text jailbreak analysis request. + public partial class AnalyzeTextJailbreakResult + { + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// is null. + internal AnalyzeTextJailbreakResult(JailbreakAnalysisResult jailbreakAnalysis) + { + Argument.AssertNotNull(jailbreakAnalysis, nameof(jailbreakAnalysis)); + + JailbreakAnalysis = jailbreakAnalysis; + } + + /// Analysis result for jailbreak. + public JailbreakAnalysisResult JailbreakAnalysis { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.Serialization.cs index 226104604056..3672d90dc249 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.Serialization.cs @@ -47,6 +47,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("outputType"u8); writer.WriteStringValue(OutputType.Value.ToString()); } + if (Optional.IsDefined(Incidents)) + { + writer.WritePropertyName("incidents"u8); + writer.WriteObjectValue(Incidents); + } writer.WriteEndObject(); } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs index 8702a2d7361f..500e3c226bf8 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs @@ -32,13 +32,15 @@ public AnalyzeTextOptions(string text) /// The names of blocklists. /// When set to true, further analyses of harmful content will not be performed in cases where blocklists are hit. When set to false, all analyses of harmful content will be performed, whether or not blocklists are hit. /// This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels". - internal AnalyzeTextOptions(string text, IList categories, IList blocklistNames, bool? haltOnBlocklistHit, AnalyzeTextOutputType? outputType) + /// The incidents to detect. + internal AnalyzeTextOptions(string text, IList categories, IList blocklistNames, bool? haltOnBlocklistHit, AnalyzeTextOutputType? outputType, IncidentOptions incidents) { Text = text; Categories = categories; BlocklistNames = blocklistNames; HaltOnBlocklistHit = haltOnBlocklistHit; OutputType = outputType; + Incidents = incidents; } /// The text needs to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request. @@ -51,5 +53,7 @@ internal AnalyzeTextOptions(string text, IList categories, IList This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels". public AnalyzeTextOutputType? OutputType { get; set; } + /// The incidents to detect. + public IncidentOptions Incidents { get; set; } } } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.Serialization.cs new file mode 100644 index 000000000000..c919eaaf055e --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.Serialization.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextProtectedMaterialOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.cs new file mode 100644 index 000000000000..8a355fbcd8c7 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The protected material analysis request. + public partial class AnalyzeTextProtectedMaterialOptions + { + /// Initializes a new instance of . + /// The text needs to be analyzed. We support a maximum of 1k Unicode characters (Unicode code points) in the text of one request. + /// is null. + public AnalyzeTextProtectedMaterialOptions(string text) + { + Argument.AssertNotNull(text, nameof(text)); + + Text = text; + } + + /// The text needs to be analyzed. We support a maximum of 1k Unicode characters (Unicode code points) in the text of one request. + public string Text { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.Serialization.cs new file mode 100644 index 000000000000..d621fc8a226a --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextProtectedMaterialResult + { + internal static AnalyzeTextProtectedMaterialResult DeserializeAnalyzeTextProtectedMaterialResult(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ProtectedMaterialAnalysisResult protectedMaterialAnalysis = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("protectedMaterialAnalysis"u8)) + { + protectedMaterialAnalysis = ProtectedMaterialAnalysisResult.DeserializeProtectedMaterialAnalysisResult(property.Value); + continue; + } + } + return new AnalyzeTextProtectedMaterialResult(protectedMaterialAnalysis); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AnalyzeTextProtectedMaterialResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAnalyzeTextProtectedMaterialResult(document.RootElement); + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.cs new file mode 100644 index 000000000000..adeb39a94019 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The protected material analysis response. + public partial class AnalyzeTextProtectedMaterialResult + { + /// Initializes a new instance of . + /// Analysis result for protected material. + /// is null. + internal AnalyzeTextProtectedMaterialResult(ProtectedMaterialAnalysisResult protectedMaterialAnalysis) + { + Argument.AssertNotNull(protectedMaterialAnalysis, nameof(protectedMaterialAnalysis)); + + ProtectedMaterialAnalysis = protectedMaterialAnalysis; + } + + /// Analysis result for protected material. + public ProtectedMaterialAnalysisResult ProtectedMaterialAnalysis { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.Serialization.cs index 7c12bf024cdc..d398b65ffb12 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.Serialization.cs @@ -22,6 +22,8 @@ internal static AnalyzeTextResult DeserializeAnalyzeTextResult(JsonElement eleme } Optional> blocklistsMatch = default; IReadOnlyList categoriesAnalysis = default; + Optional> incidentMatches = default; + Optional> citation = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("blocklistsMatch"u8)) @@ -48,8 +50,36 @@ internal static AnalyzeTextResult DeserializeAnalyzeTextResult(JsonElement eleme categoriesAnalysis = array; continue; } + if (property.NameEquals("incidentMatches"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(IncidentMatch.DeserializeIncidentMatch(item)); + } + incidentMatches = array; + continue; + } + if (property.NameEquals("citation"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + citation = array; + continue; + } } - return new AnalyzeTextResult(Optional.ToList(blocklistsMatch), categoriesAnalysis); + return new AnalyzeTextResult(Optional.ToList(blocklistsMatch), categoriesAnalysis, Optional.ToList(incidentMatches), Optional.ToList(citation)); } /// Deserializes the model from a raw response. diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs index d0786b5f8526..942b28c5e30b 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs @@ -24,20 +24,30 @@ internal AnalyzeTextResult(IEnumerable categoriesAnalysi BlocklistsMatch = new ChangeTrackingList(); CategoriesAnalysis = categoriesAnalysis.ToList(); + IncidentMatches = new ChangeTrackingList(); + Citation = new ChangeTrackingList(); } /// Initializes a new instance of . /// The blocklist match details. /// Analysis result for categories. - internal AnalyzeTextResult(IReadOnlyList blocklistsMatch, IReadOnlyList categoriesAnalysis) + /// The incident match details. + /// Chunks in the original text detected as harmful content. Analysis result and scores are caused by these. + internal AnalyzeTextResult(IReadOnlyList blocklistsMatch, IReadOnlyList categoriesAnalysis, IReadOnlyList incidentMatches, IReadOnlyList citation) { BlocklistsMatch = blocklistsMatch; CategoriesAnalysis = categoriesAnalysis; + IncidentMatches = incidentMatches; + Citation = citation; } /// The blocklist match details. public IReadOnlyList BlocklistsMatch { get; } /// Analysis result for categories. public IReadOnlyList CategoriesAnalysis { get; } + /// The incident match details. + public IReadOnlyList IncidentMatches { get; } + /// Chunks in the original text detected as harmful content. Analysis result and scores are caused by these. + public IReadOnlyList Citation { get; } } } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClient.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClient.cs index f3ea0d7f4ca5..6a46a5cac331 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClient.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClient.cs @@ -321,6 +321,226 @@ public virtual Response AnalyzeImage(RequestContent content, RequestContext cont } } + /// Analyze Text Jailbreak. + /// The text jailbreak analysis request. + /// The cancellation token to use. + /// is null. + /// A synchronous API for the analysis of text jailbreak. + /// + public virtual async Task> DetectTextJailbreakAsync(AnalyzeTextJailbreakOptions options, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(options, nameof(options)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = options.ToRequestContent(); + Response response = await DetectTextJailbreakAsync(content, context).ConfigureAwait(false); + return Response.FromValue(AnalyzeTextJailbreakResult.FromResponse(response), response); + } + + /// Analyze Text Jailbreak. + /// The text jailbreak analysis request. + /// The cancellation token to use. + /// is null. + /// A synchronous API for the analysis of text jailbreak. + /// + public virtual Response DetectTextJailbreak(AnalyzeTextJailbreakOptions options, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(options, nameof(options)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = options.ToRequestContent(); + Response response = DetectTextJailbreak(content, context); + return Response.FromValue(AnalyzeTextJailbreakResult.FromResponse(response), response); + } + + /// + /// [Protocol Method] Analyze Text Jailbreak + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task DetectTextJailbreakAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("ContentSafetyClient.DetectTextJailbreak"); + scope.Start(); + try + { + using HttpMessage message = CreateDetectTextJailbreakRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Analyze Text Jailbreak + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response DetectTextJailbreak(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("ContentSafetyClient.DetectTextJailbreak"); + scope.Start(); + try + { + using HttpMessage message = CreateDetectTextJailbreakRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Analyze Protected Material. + /// The text protected material analysis request. + /// The cancellation token to use. + /// is null. + /// A synchronous API for the analysis of protected material. + /// + public virtual async Task> DetectTextProtectedMaterialAsync(AnalyzeTextProtectedMaterialOptions options, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(options, nameof(options)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = options.ToRequestContent(); + Response response = await DetectTextProtectedMaterialAsync(content, context).ConfigureAwait(false); + return Response.FromValue(AnalyzeTextProtectedMaterialResult.FromResponse(response), response); + } + + /// Analyze Protected Material. + /// The text protected material analysis request. + /// The cancellation token to use. + /// is null. + /// A synchronous API for the analysis of protected material. + /// + public virtual Response DetectTextProtectedMaterial(AnalyzeTextProtectedMaterialOptions options, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(options, nameof(options)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = options.ToRequestContent(); + Response response = DetectTextProtectedMaterial(content, context); + return Response.FromValue(AnalyzeTextProtectedMaterialResult.FromResponse(response), response); + } + + /// + /// [Protocol Method] Analyze Protected Material + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task DetectTextProtectedMaterialAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("ContentSafetyClient.DetectTextProtectedMaterial"); + scope.Start(); + try + { + using HttpMessage message = CreateDetectTextProtectedMaterialRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Analyze Protected Material + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response DetectTextProtectedMaterial(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("ContentSafetyClient.DetectTextProtectedMaterial"); + scope.Start(); + try + { + using HttpMessage message = CreateDetectTextProtectedMaterialRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + internal HttpMessage CreateAnalyzeTextRequest(RequestContent content, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier200); @@ -355,6 +575,40 @@ internal HttpMessage CreateAnalyzeImageRequest(RequestContent content, RequestCo return message; } + internal HttpMessage CreateDetectTextJailbreakRequest(RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendRaw("/contentsafety", false); + uri.AppendPath("/text:detectJailbreak", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateDetectTextProtectedMaterialRequest(RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendRaw("/contentsafety", false); + uri.AppendPath("/text:detectProtectedMaterial", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClientOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClientOptions.cs index a827f8bbab37..f965c6da5427 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClientOptions.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClientOptions.cs @@ -13,13 +13,19 @@ namespace Azure.AI.ContentSafety /// Client options for Azure.AI.ContentSafety library clients. public partial class ContentSafetyClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V2023_10_01; + private const ServiceVersion LatestVersion = ServiceVersion.V2024_01_30_Preview; /// The version of the service to use. public enum ServiceVersion { /// Service version "2023-10-01". V2023_10_01 = 1, + /// Service version "2023-10-15-preview". + V2023_10_15_Preview = 2, + /// Service version "2023-10-30-preview". + V2023_10_30_Preview = 3, + /// Service version "2024-01-30-preview". + V2024_01_30_Preview = 4, } internal string Version { get; } @@ -30,6 +36,9 @@ public ContentSafetyClientOptions(ServiceVersion version = LatestVersion) Version = version switch { ServiceVersion.V2023_10_01 => "2023-10-01", + ServiceVersion.V2023_10_15_Preview => "2023-10-15-preview", + ServiceVersion.V2023_10_30_Preview => "2023-10-30-preview", + ServiceVersion.V2024_01_30_Preview => "2024-01-30-preview", _ => throw new NotSupportedException() }; } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyModelFactory.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyModelFactory.cs index 7a23c5776a0b..1467423ad353 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyModelFactory.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyModelFactory.cs @@ -17,13 +17,17 @@ public static partial class ContentSafetyModelFactory /// Initializes a new instance of . /// The blocklist match details. /// Analysis result for categories. + /// The incident match details. + /// Chunks in the original text detected as harmful content. Analysis result and scores are caused by these. /// A new instance for mocking. - public static AnalyzeTextResult AnalyzeTextResult(IEnumerable blocklistsMatch = null, IEnumerable categoriesAnalysis = null) + public static AnalyzeTextResult AnalyzeTextResult(IEnumerable blocklistsMatch = null, IEnumerable categoriesAnalysis = null, IEnumerable incidentMatches = null, IEnumerable citation = null) { blocklistsMatch ??= new List(); categoriesAnalysis ??= new List(); + incidentMatches ??= new List(); + citation ??= new List(); - return new AnalyzeTextResult(blocklistsMatch?.ToList(), categoriesAnalysis?.ToList()); + return new AnalyzeTextResult(blocklistsMatch?.ToList(), categoriesAnalysis?.ToList(), incidentMatches?.ToList(), citation?.ToList()); } /// Initializes a new instance of . @@ -59,14 +63,30 @@ public static TextCategoriesAnalysis TextCategoriesAnalysis(TextCategory categor return new TextCategoriesAnalysis(category, severity); } + /// Initializes a new instance of . + /// The name of the matched incident. + /// is null. + /// A new instance for mocking. + public static IncidentMatch IncidentMatch(string incidentName = null) + { + if (incidentName == null) + { + throw new ArgumentNullException(nameof(incidentName)); + } + + return new IncidentMatch(incidentName); + } + /// Initializes a new instance of . /// Analysis result for categories. + /// The incident match details. /// A new instance for mocking. - public static AnalyzeImageResult AnalyzeImageResult(IEnumerable categoriesAnalysis = null) + public static AnalyzeImageResult AnalyzeImageResult(IEnumerable categoriesAnalysis = null, IEnumerable incidentMatches = null) { categoriesAnalysis ??= new List(); + incidentMatches ??= new List(); - return new AnalyzeImageResult(categoriesAnalysis?.ToList()); + return new AnalyzeImageResult(categoriesAnalysis?.ToList(), incidentMatches?.ToList()); } /// Initializes a new instance of . @@ -78,6 +98,50 @@ public static ImageCategoriesAnalysis ImageCategoriesAnalysis(ImageCategory cate return new ImageCategoriesAnalysis(category, severity); } + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// is null. + /// A new instance for mocking. + public static AnalyzeTextJailbreakResult AnalyzeTextJailbreakResult(JailbreakAnalysisResult jailbreakAnalysis = null) + { + if (jailbreakAnalysis == null) + { + throw new ArgumentNullException(nameof(jailbreakAnalysis)); + } + + return new AnalyzeTextJailbreakResult(jailbreakAnalysis); + } + + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// A new instance for mocking. + public static JailbreakAnalysisResult JailbreakAnalysisResult(bool detected = default) + { + return new JailbreakAnalysisResult(detected); + } + + /// Initializes a new instance of . + /// Analysis result for protected material. + /// is null. + /// A new instance for mocking. + public static AnalyzeTextProtectedMaterialResult AnalyzeTextProtectedMaterialResult(ProtectedMaterialAnalysisResult protectedMaterialAnalysis = null) + { + if (protectedMaterialAnalysis == null) + { + throw new ArgumentNullException(nameof(protectedMaterialAnalysis)); + } + + return new AnalyzeTextProtectedMaterialResult(protectedMaterialAnalysis); + } + + /// Initializes a new instance of . + /// Analysis result for protected material.. + /// A new instance for mocking. + public static ProtectedMaterialAnalysisResult ProtectedMaterialAnalysisResult(bool detected = default) + { + return new ProtectedMaterialAnalysisResult(detected); + } + /// Initializes a new instance of . /// The service will generate a BlocklistItemId, which will be a UUID. /// BlocklistItem description. diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/Docs/ContentSafetyClient.xml b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/Docs/ContentSafetyClient.xml index f5ffab408d37..c544313e2919 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/Docs/ContentSafetyClient.xml +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/Docs/ContentSafetyClient.xml @@ -24,6 +24,11 @@ AnalyzeTextOptions options = new AnalyzeTextOptions("") BlocklistNames = { "" }, HaltOnBlocklistHit = true, OutputType = AnalyzeTextOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = await client.AnalyzeTextAsync(options); ]]> @@ -51,6 +56,11 @@ AnalyzeTextOptions options = new AnalyzeTextOptions("") BlocklistNames = { "" }, HaltOnBlocklistHit = true, OutputType = AnalyzeTextOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = client.AnalyzeText(options); ]]> @@ -91,6 +101,14 @@ using RequestContent content = RequestContent.Create(new }, haltOnBlocklistHit = true, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { + "" + }, + haltOnIncidentHit = true, + }, }); Response response = await client.AnalyzeTextAsync(content); @@ -100,6 +118,8 @@ Console.WriteLine(result.GetProperty("blocklistsMatch")[0].GetProperty("blocklis Console.WriteLine(result.GetProperty("blocklistsMatch")[0].GetProperty("blocklistItemText").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); +Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); +Console.WriteLine(result.GetProperty("citation")[0].ToString()); ]]> @@ -138,6 +158,14 @@ using RequestContent content = RequestContent.Create(new }, haltOnBlocklistHit = true, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { + "" + }, + haltOnIncidentHit = true, + }, }); Response response = client.AnalyzeText(content); @@ -147,6 +175,8 @@ Console.WriteLine(result.GetProperty("blocklistsMatch")[0].GetProperty("blocklis Console.WriteLine(result.GetProperty("blocklistsMatch")[0].GetProperty("blocklistItemText").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); +Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); +Console.WriteLine(result.GetProperty("citation")[0].ToString()); ]]> @@ -170,6 +200,11 @@ AnalyzeImageOptions options = new AnalyzeImageOptions(new ContentSafetyImageData { Categories = { ImageCategory.Hate }, OutputType = AnalyzeImageOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = await client.AnalyzeImageAsync(options); ]]> @@ -195,6 +230,11 @@ AnalyzeImageOptions options = new AnalyzeImageOptions(new ContentSafetyImageData { Categories = { ImageCategory.Hate }, OutputType = AnalyzeImageOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = client.AnalyzeImage(options); ]]> @@ -234,12 +274,21 @@ using RequestContent content = RequestContent.Create(new "Hate" }, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { + "" + }, + haltOnIncidentHit = true, + }, }); Response response = await client.AnalyzeImageAsync(content); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); +Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); ]]> @@ -277,12 +326,237 @@ using RequestContent content = RequestContent.Create(new "Hate" }, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { + "" + }, + haltOnIncidentHit = true, + }, }); Response response = client.AnalyzeImage(content); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); +Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); +]]> + + + +This sample shows how to call DetectTextJailbreakAsync. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); +Response response = await client.DetectTextJailbreakAsync(options); +]]> +This sample shows how to call DetectTextJailbreakAsync with all parameters. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); +Response response = await client.DetectTextJailbreakAsync(options); +]]> + + + +This sample shows how to call DetectTextJailbreak. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); +Response response = client.DetectTextJailbreak(options); +]]> +This sample shows how to call DetectTextJailbreak with all parameters. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); +Response response = client.DetectTextJailbreak(options); +]]> + + + +This sample shows how to call DetectTextJailbreakAsync and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = await client.DetectTextJailbreakAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); +]]> +This sample shows how to call DetectTextJailbreakAsync with all request content and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = await client.DetectTextJailbreakAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); +]]> + + + +This sample shows how to call DetectTextJailbreak and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = client.DetectTextJailbreak(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); +]]> +This sample shows how to call DetectTextJailbreak with all request content and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = client.DetectTextJailbreak(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); +]]> + + + +This sample shows how to call DetectTextProtectedMaterialAsync. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); +Response response = await client.DetectTextProtectedMaterialAsync(options); +]]> +This sample shows how to call DetectTextProtectedMaterialAsync with all parameters. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); +Response response = await client.DetectTextProtectedMaterialAsync(options); +]]> + + + +This sample shows how to call DetectTextProtectedMaterial. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); +Response response = client.DetectTextProtectedMaterial(options); +]]> +This sample shows how to call DetectTextProtectedMaterial with all parameters. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); +Response response = client.DetectTextProtectedMaterial(options); +]]> + + + +This sample shows how to call DetectTextProtectedMaterialAsync and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = await client.DetectTextProtectedMaterialAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); +]]> +This sample shows how to call DetectTextProtectedMaterialAsync with all request content and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = await client.DetectTextProtectedMaterialAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); +]]> + + + +This sample shows how to call DetectTextProtectedMaterial and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = client.DetectTextProtectedMaterial(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); +]]> +This sample shows how to call DetectTextProtectedMaterial with all request content and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new +{ + text = "", +}); +Response response = client.DetectTextProtectedMaterial(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); ]]> diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.Serialization.cs new file mode 100644 index 000000000000..a12815d304f7 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.ContentSafety +{ + public partial class IncidentMatch + { + internal static IncidentMatch DeserializeIncidentMatch(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string incidentName = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("incidentName"u8)) + { + incidentName = property.Value.GetString(); + continue; + } + } + return new IncidentMatch(incidentName); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static IncidentMatch FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeIncidentMatch(document.RootElement); + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.cs new file mode 100644 index 000000000000..47cb1eb50f72 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The result of text incident match. + public partial class IncidentMatch + { + /// Initializes a new instance of . + /// The name of the matched incident. + /// is null. + internal IncidentMatch(string incidentName) + { + Argument.AssertNotNull(incidentName, nameof(incidentName)); + + IncidentName = incidentName; + } + + /// The name of the matched incident. + public string IncidentName { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.Serialization.cs new file mode 100644 index 000000000000..8182a427b9ac --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.Serialization.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class IncidentOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsCollectionDefined(IncidentNames)) + { + writer.WritePropertyName("incidentNames"u8); + writer.WriteStartArray(); + foreach (var item in IncidentNames) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(HaltOnIncidentHit)) + { + writer.WritePropertyName("haltOnIncidentHit"u8); + writer.WriteBooleanValue(HaltOnIncidentHit.Value); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.cs new file mode 100644 index 000000000000..f1bb538684c5 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The text analysis request. + public partial class IncidentOptions + { + /// Initializes a new instance of . + public IncidentOptions() + { + IncidentNames = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The accept decision made by service. + /// When set to true, further analyses of harmful content will not be performed in cases where incidents are hit. When set to false, all analyses of harmful content will be performed, whether or not incidents are hit. + internal IncidentOptions(IList incidentNames, bool? haltOnIncidentHit) + { + IncidentNames = incidentNames; + HaltOnIncidentHit = haltOnIncidentHit; + } + + /// The accept decision made by service. + public IList IncidentNames { get; } + /// When set to true, further analyses of harmful content will not be performed in cases where incidents are hit. When set to false, all analyses of harmful content will be performed, whether or not incidents are hit. + public bool? HaltOnIncidentHit { get; set; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.Serialization.cs new file mode 100644 index 000000000000..b2f6928f5dd7 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.ContentSafety +{ + public partial class JailbreakAnalysisResult + { + internal static JailbreakAnalysisResult DeserializeJailbreakAnalysisResult(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool detected = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("detected"u8)) + { + detected = property.Value.GetBoolean(); + continue; + } + } + return new JailbreakAnalysisResult(detected); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static JailbreakAnalysisResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeJailbreakAnalysisResult(document.RootElement); + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.cs new file mode 100644 index 000000000000..7b1437d81d14 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.ContentSafety +{ + /// The text jailbreak analysis response. + public partial class JailbreakAnalysisResult + { + /// Initializes a new instance of . + /// Analysis result for jailbreak. + internal JailbreakAnalysisResult(bool detected) + { + Detected = detected; + } + + /// Analysis result for jailbreak. + public bool Detected { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.Serialization.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.Serialization.cs new file mode 100644 index 000000000000..c81084c21765 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.ContentSafety +{ + public partial class ProtectedMaterialAnalysisResult + { + internal static ProtectedMaterialAnalysisResult DeserializeProtectedMaterialAnalysisResult(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool detected = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("detected"u8)) + { + detected = property.Value.GetBoolean(); + continue; + } + } + return new ProtectedMaterialAnalysisResult(detected); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ProtectedMaterialAnalysisResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeProtectedMaterialAnalysisResult(document.RootElement); + } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.cs new file mode 100644 index 000000000000..b3d504ac5c1d --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.ContentSafety +{ + /// The text protected material analysis response. + public partial class ProtectedMaterialAnalysisResult + { + /// Initializes a new instance of . + /// Analysis result for protected material.. + internal ProtectedMaterialAnalysisResult(bool detected) + { + Detected = detected; + } + + /// Analysis result for protected material.. + public bool Detected { get; } + } +} diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/tests/Generated/Samples/Samples_ContentSafetyClient.cs b/sdk/contentsafety/Azure.AI.ContentSafety/tests/Generated/Samples/Samples_ContentSafetyClient.cs index 4b8c65fcecd0..08c222afc13c 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/tests/Generated/Samples/Samples_ContentSafetyClient.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/tests/Generated/Samples/Samples_ContentSafetyClient.cs @@ -99,6 +99,14 @@ public void Example_ContentSafetyClient_AnalyzeText_AllParameters() }, haltOnBlocklistHit = true, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { +"" + }, + haltOnIncidentHit = true, + }, }); Response response = client.AnalyzeText(content); @@ -108,6 +116,8 @@ public void Example_ContentSafetyClient_AnalyzeText_AllParameters() Console.WriteLine(result.GetProperty("blocklistsMatch")[0].GetProperty("blocklistItemText").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); + Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); + Console.WriteLine(result.GetProperty("citation")[0].ToString()); } [Test] @@ -131,6 +141,14 @@ public async Task Example_ContentSafetyClient_AnalyzeText_AllParameters_Async() }, haltOnBlocklistHit = true, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { +"" + }, + haltOnIncidentHit = true, + }, }); Response response = await client.AnalyzeTextAsync(content); @@ -140,6 +158,8 @@ public async Task Example_ContentSafetyClient_AnalyzeText_AllParameters_Async() Console.WriteLine(result.GetProperty("blocklistsMatch")[0].GetProperty("blocklistItemText").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); + Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); + Console.WriteLine(result.GetProperty("citation")[0].ToString()); } [Test] @@ -156,6 +176,11 @@ public void Example_ContentSafetyClient_AnalyzeText_AllParameters_Convenience() BlocklistNames = { "" }, HaltOnBlocklistHit = true, OutputType = AnalyzeTextOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = client.AnalyzeText(options); } @@ -174,6 +199,11 @@ public async Task Example_ContentSafetyClient_AnalyzeText_AllParameters_Convenie BlocklistNames = { "" }, HaltOnBlocklistHit = true, OutputType = AnalyzeTextOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = await client.AnalyzeTextAsync(options); } @@ -258,12 +288,21 @@ public void Example_ContentSafetyClient_AnalyzeImage_AllParameters() "Hate" }, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { +"" + }, + haltOnIncidentHit = true, + }, }); Response response = client.AnalyzeImage(content); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); + Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); } [Test] @@ -286,12 +325,21 @@ public async Task Example_ContentSafetyClient_AnalyzeImage_AllParameters_Async() "Hate" }, outputType = "FourSeverityLevels", + incidents = new + { + incidentNames = new object[] + { +"" + }, + haltOnIncidentHit = true, + }, }); Response response = await client.AnalyzeImageAsync(content); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString()); Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString()); + Console.WriteLine(result.GetProperty("incidentMatches")[0].GetProperty("incidentName").ToString()); } [Test] @@ -306,6 +354,11 @@ public void Example_ContentSafetyClient_AnalyzeImage_AllParameters_Convenience() { Categories = { ImageCategory.Hate }, OutputType = AnalyzeImageOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = client.AnalyzeImage(options); } @@ -322,8 +375,253 @@ public async Task Example_ContentSafetyClient_AnalyzeImage_AllParameters_Conveni { Categories = { ImageCategory.Hate }, OutputType = AnalyzeImageOutputType.FourSeverityLevels, + Incidents = new IncidentOptions + { + IncidentNames = { "" }, + HaltOnIncidentHit = true, + }, }; Response response = await client.AnalyzeImageAsync(options); } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextJailbreak_ShortVersion() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = client.DetectTextJailbreak(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextJailbreak_ShortVersion_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = await client.DetectTextJailbreakAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextJailbreak_ShortVersion_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); + Response response = client.DetectTextJailbreak(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextJailbreak_ShortVersion_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); + Response response = await client.DetectTextJailbreakAsync(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextJailbreak_AllParameters() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = client.DetectTextJailbreak(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextJailbreak_AllParameters_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = await client.DetectTextJailbreakAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("jailbreakAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextJailbreak_AllParameters_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); + Response response = client.DetectTextJailbreak(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextJailbreak_AllParameters_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextJailbreakOptions options = new AnalyzeTextJailbreakOptions(""); + Response response = await client.DetectTextJailbreakAsync(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextProtectedMaterial_ShortVersion() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = client.DetectTextProtectedMaterial(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextProtectedMaterial_ShortVersion_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = await client.DetectTextProtectedMaterialAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextProtectedMaterial_ShortVersion_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); + Response response = client.DetectTextProtectedMaterial(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextProtectedMaterial_ShortVersion_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); + Response response = await client.DetectTextProtectedMaterialAsync(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextProtectedMaterial_AllParameters() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = client.DetectTextProtectedMaterial(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextProtectedMaterial_AllParameters_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new + { + text = "", + }); + Response response = await client.DetectTextProtectedMaterialAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("protectedMaterialAnalysis").GetProperty("detected").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ContentSafetyClient_DetectTextProtectedMaterial_AllParameters_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); + Response response = client.DetectTextProtectedMaterial(options); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ContentSafetyClient_DetectTextProtectedMaterial_AllParameters_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + ContentSafetyClient client = new ContentSafetyClient(endpoint, credential); + + AnalyzeTextProtectedMaterialOptions options = new AnalyzeTextProtectedMaterialOptions(""); + Response response = await client.DetectTextProtectedMaterialAsync(options); + } } } diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/tsp-location.yaml b/sdk/contentsafety/Azure.AI.ContentSafety/tsp-location.yaml index 24a2f85d3f08..f25cddb053d8 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/tsp-location.yaml +++ b/sdk/contentsafety/Azure.AI.ContentSafety/tsp-location.yaml @@ -1,5 +1,5 @@ -commit: 164375e67a1bffb207bcf603772c289dbe42d7b5 -additionalDirectories: [] repo: Azure/azure-rest-api-specs +commit: 1c291a85cb9f25c6c3dc67d151b4e2ab75581f5d +additionalDirectories: [] directory: specification/cognitiveservices/ContentSafety