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 66828782b6204..cc4335921949b 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 @@ -25,6 +25,7 @@ public partial class AnalyzeImageOptions : System.ClientModel.Primitives.IJsonMo 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 { } } Azure.AI.ContentSafety.AnalyzeImageOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } @@ -53,18 +54,40 @@ public partial class AnalyzeImageResult : System.ClientModel.Primitives.IJsonMod { internal AnalyzeImageResult() { } public System.Collections.Generic.IReadOnlyList CategoriesAnalysis { get { throw null; } } + public System.Collections.Generic.IReadOnlyList IncidentMatches { get { throw null; } } Azure.AI.ContentSafety.AnalyzeImageResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.AI.ContentSafety.AnalyzeImageResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } + public partial class AnalyzeTextJailbreakOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public AnalyzeTextJailbreakOptions(string text) { } + public string Text { get { throw null; } } + Azure.AI.ContentSafety.AnalyzeTextJailbreakOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.AnalyzeTextJailbreakOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class AnalyzeTextJailbreakResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal AnalyzeTextJailbreakResult() { } + public Azure.AI.ContentSafety.JailbreakAnalysisResult JailbreakAnalysis { get { throw null; } } + Azure.AI.ContentSafety.AnalyzeTextJailbreakResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.AnalyzeTextJailbreakResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class AnalyzeTextOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { 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; } } Azure.AI.ContentSafety.AnalyzeTextOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -91,11 +114,33 @@ 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 : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public AnalyzeTextProtectedMaterialOptions(string text) { } + public string Text { get { throw null; } } + Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class AnalyzeTextProtectedMaterialResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal AnalyzeTextProtectedMaterialResult() { } + public Azure.AI.ContentSafety.ProtectedMaterialAnalysisResult ProtectedMaterialAnalysis { get { throw null; } } + Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.AnalyzeTextProtectedMaterialResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class AnalyzeTextResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { 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; } } Azure.AI.ContentSafety.AnalyzeTextResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.AI.ContentSafety.AnalyzeTextResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -161,13 +206,23 @@ 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.V2023_10_30_Preview) { } public enum ServiceVersion { V2023_10_01 = 1, + V2023_10_15_Preview = 2, + V2023_10_30_Preview = 3, } } public partial class ContentSafetyImageData : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel @@ -184,11 +239,16 @@ 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.AnalyzeImageOptions AnalyzeImageOptions(Azure.AI.ContentSafety.ContentSafetyImageData image = null, System.Collections.Generic.IEnumerable categories = null, Azure.AI.ContentSafety.AnalyzeImageOutputType? outputType = default(Azure.AI.ContentSafety.AnalyzeImageOutputType?)) { throw null; } - public static Azure.AI.ContentSafety.AnalyzeImageResult AnalyzeImageResult(System.Collections.Generic.IEnumerable categoriesAnalysis = null) { throw null; } - public static Azure.AI.ContentSafety.AnalyzeTextOptions AnalyzeTextOptions(string text = null, System.Collections.Generic.IEnumerable categories = null, System.Collections.Generic.IEnumerable blocklistNames = null, bool? haltOnBlocklistHit = default(bool?), Azure.AI.ContentSafety.AnalyzeTextOutputType? outputType = default(Azure.AI.ContentSafety.AnalyzeTextOutputType?)) { 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.AnalyzeImageOptions AnalyzeImageOptions(Azure.AI.ContentSafety.ContentSafetyImageData image = null, System.Collections.Generic.IEnumerable categories = null, Azure.AI.ContentSafety.AnalyzeImageOutputType? outputType = default(Azure.AI.ContentSafety.AnalyzeImageOutputType?), Azure.AI.ContentSafety.IncidentOptions incidents = 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.AnalyzeTextOptions AnalyzeTextOptions(string text = null, System.Collections.Generic.IEnumerable categories = null, System.Collections.Generic.IEnumerable blocklistNames = null, bool? haltOnBlocklistHit = default(bool?), Azure.AI.ContentSafety.AnalyzeTextOutputType? outputType = default(Azure.AI.ContentSafety.AnalyzeTextOutputType?), Azure.AI.ContentSafety.IncidentOptions incidents = 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; } @@ -225,6 +285,47 @@ 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 : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal IncidentMatch() { } + public string IncidentName { get { throw null; } } + Azure.AI.ContentSafety.IncidentMatch System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.IncidentMatch System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class IncidentOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public IncidentOptions() { } + public bool? HaltOnIncidentHit { get { throw null; } set { } } + public System.Collections.Generic.IList IncidentNames { get { throw null; } } + Azure.AI.ContentSafety.IncidentOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.IncidentOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class JailbreakAnalysisResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal JailbreakAnalysisResult() { } + public bool Detected { get { throw null; } } + Azure.AI.ContentSafety.JailbreakAnalysisResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.JailbreakAnalysisResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class ProtectedMaterialAnalysisResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal ProtectedMaterialAnalysisResult() { } + public bool Detected { get { throw null; } } + Azure.AI.ContentSafety.ProtectedMaterialAnalysisResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.ContentSafety.ProtectedMaterialAnalysisResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class RemoveTextBlocklistItemsOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { 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 11f27620b1d1e..cb0b3ff2460bd 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.Serialization.cs @@ -44,6 +44,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri writer.WritePropertyName("outputType"u8); writer.WriteStringValue(OutputType.Value.ToString()); } + if (Optional.IsDefined(Incidents)) + { + writer.WritePropertyName("incidents"u8); + writer.WriteObjectValue(Incidents); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -85,6 +90,7 @@ internal static AnalyzeImageOptions DeserializeAnalyzeImageOptions(JsonElement e ContentSafetyImageData image = default; Optional> categories = default; Optional outputType = default; + Optional incidents = default; IDictionary serializedAdditionalRawData = default; Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -117,13 +123,22 @@ internal static AnalyzeImageOptions DeserializeAnalyzeImageOptions(JsonElement e outputType = new AnalyzeImageOutputType(property.Value.GetString()); continue; } + if (property.NameEquals("incidents"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + incidents = IncidentOptions.DeserializeIncidentOptions(property.Value); + continue; + } if (options.Format != "W") { additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = additionalPropertiesDictionary; - return new AnalyzeImageOptions(image, Optional.ToList(categories), Optional.ToNullable(outputType), serializedAdditionalRawData); + return new AnalyzeImageOptions(image, Optional.ToList(categories), Optional.ToNullable(outputType), incidents.Value, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs index 7628af5caf26e..5f8d6377d4fec 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageOptions.cs @@ -61,12 +61,14 @@ 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". + /// The incidents to detect. /// Keeps track of any properties unknown to the library. - internal AnalyzeImageOptions(ContentSafetyImageData image, IList categories, AnalyzeImageOutputType? outputType, IDictionary serializedAdditionalRawData) + internal AnalyzeImageOptions(ContentSafetyImageData image, IList categories, AnalyzeImageOutputType? outputType, IncidentOptions incidents, IDictionary serializedAdditionalRawData) { Image = image; Categories = categories; OutputType = outputType; + Incidents = incidents; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -81,5 +83,7 @@ internal AnalyzeImageOptions() 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 1ddf0c6350261..05f496799c993 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.Serialization.cs @@ -34,6 +34,16 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrit writer.WriteObjectValue(item); } writer.WriteEndArray(); + if (Optional.IsCollectionDefined(IncidentMatches)) + { + writer.WritePropertyName("incidentMatches"u8); + writer.WriteStartArray(); + foreach (var item in IncidentMatches) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -73,6 +83,7 @@ internal static AnalyzeImageResult DeserializeAnalyzeImageResult(JsonElement ele return null; } IReadOnlyList categoriesAnalysis = default; + Optional> incidentMatches = default; IDictionary serializedAdditionalRawData = default; Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -87,13 +98,27 @@ 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; + } if (options.Format != "W") { additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = additionalPropertiesDictionary; - return new AnalyzeImageResult(categoriesAnalysis, serializedAdditionalRawData); + return new AnalyzeImageResult(categoriesAnalysis, Optional.ToList(incidentMatches), serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs index 4b1cda8f32597..217b241c69486 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeImageResult.cs @@ -55,14 +55,17 @@ internal AnalyzeImageResult(IEnumerable categoriesAnaly Argument.AssertNotNull(categoriesAnalysis, nameof(categoriesAnalysis)); CategoriesAnalysis = categoriesAnalysis.ToList(); + IncidentMatches = new ChangeTrackingList(); } /// Initializes a new instance of . /// Analysis result for categories. + /// The incident match details. /// Keeps track of any properties unknown to the library. - internal AnalyzeImageResult(IReadOnlyList categoriesAnalysis, IDictionary serializedAdditionalRawData) + internal AnalyzeImageResult(IReadOnlyList categoriesAnalysis, IReadOnlyList incidentMatches, IDictionary serializedAdditionalRawData) { CategoriesAnalysis = categoriesAnalysis; + IncidentMatches = incidentMatches; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -73,5 +76,7 @@ internal AnalyzeImageResult() /// 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 0000000000000..99631a6b4287d --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextJailbreakOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakOptions)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AnalyzeTextJailbreakOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAnalyzeTextJailbreakOptions(document.RootElement, options); + } + + internal static AnalyzeTextJailbreakOptions DeserializeAnalyzeTextJailbreakOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string text = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AnalyzeTextJailbreakOptions(text, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakOptions)} does not support '{options.Format}' format."); + } + } + + AnalyzeTextJailbreakOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAnalyzeTextJailbreakOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AnalyzeTextJailbreakOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAnalyzeTextJailbreakOptions(document.RootElement); + } + + /// 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 0000000000000..89fafd6689441 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakOptions.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The text jailbreak analysis request. + public partial class AnalyzeTextJailbreakOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// 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; + } + + /// 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. + /// Keeps track of any properties unknown to the library. + internal AnalyzeTextJailbreakOptions(string text, IDictionary serializedAdditionalRawData) + { + Text = text; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AnalyzeTextJailbreakOptions() + { + } + + /// 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 0000000000000..272862bf43f16 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextJailbreakResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("jailbreakAnalysis"u8); + writer.WriteObjectValue(JailbreakAnalysis); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AnalyzeTextJailbreakResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAnalyzeTextJailbreakResult(document.RootElement, options); + } + + internal static AnalyzeTextJailbreakResult DeserializeAnalyzeTextJailbreakResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + JailbreakAnalysisResult jailbreakAnalysis = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("jailbreakAnalysis"u8)) + { + jailbreakAnalysis = JailbreakAnalysisResult.DeserializeJailbreakAnalysisResult(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AnalyzeTextJailbreakResult(jailbreakAnalysis, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakResult)} does not support '{options.Format}' format."); + } + } + + AnalyzeTextJailbreakResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAnalyzeTextJailbreakResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AnalyzeTextJailbreakResult)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// 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); + } + + /// 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/AnalyzeTextJailbreakResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.cs new file mode 100644 index 0000000000000..b79d7812b4762 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextJailbreakResult.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The text jailbreak analysis request. + public partial class AnalyzeTextJailbreakResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// is null. + internal AnalyzeTextJailbreakResult(JailbreakAnalysisResult jailbreakAnalysis) + { + Argument.AssertNotNull(jailbreakAnalysis, nameof(jailbreakAnalysis)); + + JailbreakAnalysis = jailbreakAnalysis; + } + + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// Keeps track of any properties unknown to the library. + internal AnalyzeTextJailbreakResult(JailbreakAnalysisResult jailbreakAnalysis, IDictionary serializedAdditionalRawData) + { + JailbreakAnalysis = jailbreakAnalysis; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AnalyzeTextJailbreakResult() + { + } + + /// 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 a4c8082e96843..752bc871bd0e4 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.Serialization.cs @@ -59,6 +59,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("outputType"u8); writer.WriteStringValue(OutputType.Value.ToString()); } + if (Optional.IsDefined(Incidents)) + { + writer.WritePropertyName("incidents"u8); + writer.WriteObjectValue(Incidents); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -102,6 +107,7 @@ internal static AnalyzeTextOptions DeserializeAnalyzeTextOptions(JsonElement ele Optional> blocklistNames = default; Optional haltOnBlocklistHit = default; Optional outputType = default; + Optional incidents = default; IDictionary serializedAdditionalRawData = default; Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -157,13 +163,22 @@ internal static AnalyzeTextOptions DeserializeAnalyzeTextOptions(JsonElement ele outputType = new AnalyzeTextOutputType(property.Value.GetString()); continue; } + if (property.NameEquals("incidents"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + incidents = IncidentOptions.DeserializeIncidentOptions(property.Value); + continue; + } if (options.Format != "W") { additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = additionalPropertiesDictionary; - return new AnalyzeTextOptions(text, Optional.ToList(categories), Optional.ToList(blocklistNames), Optional.ToNullable(haltOnBlocklistHit), Optional.ToNullable(outputType), serializedAdditionalRawData); + return new AnalyzeTextOptions(text, Optional.ToList(categories), Optional.ToList(blocklistNames), Optional.ToNullable(haltOnBlocklistHit), Optional.ToNullable(outputType), incidents.Value, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs index 84d6e57310374..2dbcd29b3bf21 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextOptions.cs @@ -64,14 +64,16 @@ 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". + /// The incidents to detect. /// Keeps track of any properties unknown to the library. - internal AnalyzeTextOptions(string text, IList categories, IList blocklistNames, bool? haltOnBlocklistHit, AnalyzeTextOutputType? outputType, IDictionary serializedAdditionalRawData) + internal AnalyzeTextOptions(string text, IList categories, IList blocklistNames, bool? haltOnBlocklistHit, AnalyzeTextOutputType? outputType, IncidentOptions incidents, IDictionary serializedAdditionalRawData) { Text = text; Categories = categories; BlocklistNames = blocklistNames; HaltOnBlocklistHit = haltOnBlocklistHit; OutputType = outputType; + Incidents = incidents; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -90,5 +92,7 @@ internal AnalyzeTextOptions() public bool? HaltOnBlocklistHit { get; set; } /// 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 0000000000000..91d2116db0389 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextProtectedMaterialOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialOptions)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AnalyzeTextProtectedMaterialOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAnalyzeTextProtectedMaterialOptions(document.RootElement, options); + } + + internal static AnalyzeTextProtectedMaterialOptions DeserializeAnalyzeTextProtectedMaterialOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string text = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AnalyzeTextProtectedMaterialOptions(text, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialOptions)} does not support '{options.Format}' format."); + } + } + + AnalyzeTextProtectedMaterialOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAnalyzeTextProtectedMaterialOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AnalyzeTextProtectedMaterialOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAnalyzeTextProtectedMaterialOptions(document.RootElement); + } + + /// 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 0000000000000..95597080c8e3c --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialOptions.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The protected material analysis request. + public partial class AnalyzeTextProtectedMaterialOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// 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; + } + + /// 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. + /// Keeps track of any properties unknown to the library. + internal AnalyzeTextProtectedMaterialOptions(string text, IDictionary serializedAdditionalRawData) + { + Text = text; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AnalyzeTextProtectedMaterialOptions() + { + } + + /// 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 0000000000000..3752c41f89aea --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class AnalyzeTextProtectedMaterialResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("protectedMaterialAnalysis"u8); + writer.WriteObjectValue(ProtectedMaterialAnalysis); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AnalyzeTextProtectedMaterialResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAnalyzeTextProtectedMaterialResult(document.RootElement, options); + } + + internal static AnalyzeTextProtectedMaterialResult DeserializeAnalyzeTextProtectedMaterialResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ProtectedMaterialAnalysisResult protectedMaterialAnalysis = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("protectedMaterialAnalysis"u8)) + { + protectedMaterialAnalysis = ProtectedMaterialAnalysisResult.DeserializeProtectedMaterialAnalysisResult(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AnalyzeTextProtectedMaterialResult(protectedMaterialAnalysis, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialResult)} does not support '{options.Format}' format."); + } + } + + AnalyzeTextProtectedMaterialResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAnalyzeTextProtectedMaterialResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AnalyzeTextProtectedMaterialResult)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// 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); + } + + /// 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/AnalyzeTextProtectedMaterialResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.cs new file mode 100644 index 0000000000000..436a65a413fc9 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextProtectedMaterialResult.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The protected material analysis response. + public partial class AnalyzeTextProtectedMaterialResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Analysis result for protected material. + /// is null. + internal AnalyzeTextProtectedMaterialResult(ProtectedMaterialAnalysisResult protectedMaterialAnalysis) + { + Argument.AssertNotNull(protectedMaterialAnalysis, nameof(protectedMaterialAnalysis)); + + ProtectedMaterialAnalysis = protectedMaterialAnalysis; + } + + /// Initializes a new instance of . + /// Analysis result for protected material. + /// Keeps track of any properties unknown to the library. + internal AnalyzeTextProtectedMaterialResult(ProtectedMaterialAnalysisResult protectedMaterialAnalysis, IDictionary serializedAdditionalRawData) + { + ProtectedMaterialAnalysis = protectedMaterialAnalysis; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AnalyzeTextProtectedMaterialResult() + { + } + + /// 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 b958c2cb695ab..936e95f3cb2b7 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.Serialization.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.Serialization.cs @@ -44,6 +44,26 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrite writer.WriteObjectValue(item); } writer.WriteEndArray(); + if (Optional.IsCollectionDefined(IncidentMatches)) + { + writer.WritePropertyName("incidentMatches"u8); + writer.WriteStartArray(); + foreach (var item in IncidentMatches) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Citation)) + { + writer.WritePropertyName("citation"u8); + writer.WriteStartArray(); + foreach (var item in Citation) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -84,6 +104,8 @@ internal static AnalyzeTextResult DeserializeAnalyzeTextResult(JsonElement eleme } Optional> blocklistsMatch = default; IReadOnlyList categoriesAnalysis = default; + Optional> incidentMatches = default; + Optional> citation = default; IDictionary serializedAdditionalRawData = default; Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -112,13 +134,41 @@ 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; + } if (options.Format != "W") { additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = additionalPropertiesDictionary; - return new AnalyzeTextResult(Optional.ToList(blocklistsMatch), categoriesAnalysis, serializedAdditionalRawData); + return new AnalyzeTextResult(Optional.ToList(blocklistsMatch), categoriesAnalysis, Optional.ToList(incidentMatches), Optional.ToList(citation), serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs index 0a3d8d9d59008..7eb14b5211b49 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/AnalyzeTextResult.cs @@ -56,16 +56,22 @@ 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. + /// The incident match details. + /// Chunks in the original text detected as harmful content. Analysis result and scores are caused by these. /// Keeps track of any properties unknown to the library. - internal AnalyzeTextResult(IReadOnlyList blocklistsMatch, IReadOnlyList categoriesAnalysis, IDictionary serializedAdditionalRawData) + internal AnalyzeTextResult(IReadOnlyList blocklistsMatch, IReadOnlyList categoriesAnalysis, IReadOnlyList incidentMatches, IReadOnlyList citation, IDictionary serializedAdditionalRawData) { BlocklistsMatch = blocklistsMatch; CategoriesAnalysis = categoriesAnalysis; + IncidentMatches = incidentMatches; + Citation = citation; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -78,5 +84,9 @@ internal AnalyzeTextResult() 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 f3ea0d7f4ca50..6a46a5cac3319 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 a827f8bbab376..620315d9e0425 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClientOptions.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyClientOptions.cs @@ -13,13 +13,17 @@ 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.V2023_10_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, } internal string Version { get; } @@ -30,6 +34,8 @@ 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", _ => 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 e5590524ead29..1d68d15345c46 100644 --- a/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyModelFactory.cs +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ContentSafetyModelFactory.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Azure; namespace Azure.AI.ContentSafety { @@ -20,25 +21,30 @@ public static partial class ContentSafetyModelFactory /// 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". + /// The incidents to detect. /// A new instance for mocking. - public static AnalyzeTextOptions AnalyzeTextOptions(string text = null, IEnumerable categories = null, IEnumerable blocklistNames = null, bool? haltOnBlocklistHit = null, AnalyzeTextOutputType? outputType = null) + public static AnalyzeTextOptions AnalyzeTextOptions(string text = null, IEnumerable categories = null, IEnumerable blocklistNames = null, bool? haltOnBlocklistHit = null, AnalyzeTextOutputType? outputType = null, IncidentOptions incidents = null) { categories ??= new List(); blocklistNames ??= new List(); - return new AnalyzeTextOptions(text, categories?.ToList(), blocklistNames?.ToList(), haltOnBlocklistHit, outputType, serializedAdditionalRawData: null); + return new AnalyzeTextOptions(text, categories?.ToList(), blocklistNames?.ToList(), haltOnBlocklistHit, outputType, incidents, serializedAdditionalRawData: null); } /// 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(), serializedAdditionalRawData: null); + return new AnalyzeTextResult(blocklistsMatch?.ToList(), categoriesAnalysis?.ToList(), incidentMatches?.ToList(), citation?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -60,26 +66,37 @@ public static TextCategoriesAnalysis TextCategoriesAnalysis(TextCategory categor return new TextCategoriesAnalysis(category, severity, serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// The name of the matched incident. + /// A new instance for mocking. + public static IncidentMatch IncidentMatch(string incidentName = null) + { + return new IncidentMatch(incidentName, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// 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". + /// The incidents to detect. /// A new instance for mocking. - public static AnalyzeImageOptions AnalyzeImageOptions(ContentSafetyImageData image = null, IEnumerable categories = null, AnalyzeImageOutputType? outputType = null) + public static AnalyzeImageOptions AnalyzeImageOptions(ContentSafetyImageData image = null, IEnumerable categories = null, AnalyzeImageOutputType? outputType = null, IncidentOptions incidents = null) { categories ??= new List(); - return new AnalyzeImageOptions(image, categories?.ToList(), outputType, serializedAdditionalRawData: null); + return new AnalyzeImageOptions(image, categories?.ToList(), outputType, incidents, serializedAdditionalRawData: null); } /// 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(), serializedAdditionalRawData: null); + return new AnalyzeImageResult(categoriesAnalysis?.ToList(), incidentMatches?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -91,6 +108,38 @@ public static ImageCategoriesAnalysis ImageCategoriesAnalysis(ImageCategory cate return new ImageCategoriesAnalysis(category, severity, serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// A new instance for mocking. + public static AnalyzeTextJailbreakResult AnalyzeTextJailbreakResult(JailbreakAnalysisResult jailbreakAnalysis = null) + { + return new AnalyzeTextJailbreakResult(jailbreakAnalysis, serializedAdditionalRawData: null); + } + + /// 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, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Analysis result for protected material. + /// A new instance for mocking. + public static AnalyzeTextProtectedMaterialResult AnalyzeTextProtectedMaterialResult(ProtectedMaterialAnalysisResult protectedMaterialAnalysis = null) + { + return new AnalyzeTextProtectedMaterialResult(protectedMaterialAnalysis, serializedAdditionalRawData: null); + } + + /// 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, serializedAdditionalRawData: null); + } + /// 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 f5ffab408d372..c544313e29196 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 0000000000000..db54c4bf43ca9 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class IncidentMatch : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(IncidentMatch)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("incidentName"u8); + writer.WriteStringValue(IncidentName); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + IncidentMatch IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(IncidentMatch)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeIncidentMatch(document.RootElement, options); + } + + internal static IncidentMatch DeserializeIncidentMatch(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string incidentName = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("incidentName"u8)) + { + incidentName = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new IncidentMatch(incidentName, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(IncidentMatch)} does not support '{options.Format}' format."); + } + } + + IncidentMatch IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeIncidentMatch(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(IncidentMatch)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// 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); + } + + /// 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/IncidentMatch.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.cs new file mode 100644 index 0000000000000..ba71d5fba7210 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentMatch.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The result of text incident match. + public partial class IncidentMatch + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The name of the matched incident. + /// is null. + internal IncidentMatch(string incidentName) + { + Argument.AssertNotNull(incidentName, nameof(incidentName)); + + IncidentName = incidentName; + } + + /// Initializes a new instance of . + /// The name of the matched incident. + /// Keeps track of any properties unknown to the library. + internal IncidentMatch(string incidentName, IDictionary serializedAdditionalRawData) + { + IncidentName = incidentName; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal IncidentMatch() + { + } + + /// 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 0000000000000..95cd5ea393607 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.Serialization.cs @@ -0,0 +1,168 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class IncidentOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(IncidentOptions)} does not support '{format}' format."); + } + + 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); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + IncidentOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(IncidentOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeIncidentOptions(document.RootElement, options); + } + + internal static IncidentOptions DeserializeIncidentOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional> incidentNames = default; + Optional haltOnIncidentHit = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("incidentNames"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + incidentNames = array; + continue; + } + if (property.NameEquals("haltOnIncidentHit"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + haltOnIncidentHit = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new IncidentOptions(Optional.ToList(incidentNames), Optional.ToNullable(haltOnIncidentHit), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(IncidentOptions)} does not support '{options.Format}' format."); + } + } + + IncidentOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeIncidentOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(IncidentOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static IncidentOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeIncidentOptions(document.RootElement); + } + + /// 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 0000000000000..0b2c025ea8573 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/IncidentOptions.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + /// The text analysis request. + public partial class IncidentOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// 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. + /// Keeps track of any properties unknown to the library. + internal IncidentOptions(IList incidentNames, bool? haltOnIncidentHit, IDictionary serializedAdditionalRawData) + { + IncidentNames = incidentNames; + HaltOnIncidentHit = haltOnIncidentHit; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// 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 0000000000000..81fa864979739 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class JailbreakAnalysisResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(JailbreakAnalysisResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("detected"u8); + writer.WriteBooleanValue(Detected); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + JailbreakAnalysisResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(JailbreakAnalysisResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeJailbreakAnalysisResult(document.RootElement, options); + } + + internal static JailbreakAnalysisResult DeserializeJailbreakAnalysisResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool detected = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("detected"u8)) + { + detected = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new JailbreakAnalysisResult(detected, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(JailbreakAnalysisResult)} does not support '{options.Format}' format."); + } + } + + JailbreakAnalysisResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeJailbreakAnalysisResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(JailbreakAnalysisResult)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// 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); + } + + /// 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/JailbreakAnalysisResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.cs new file mode 100644 index 0000000000000..4268d91abf894 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/JailbreakAnalysisResult.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.ContentSafety +{ + /// The text jailbreak analysis response. + public partial class JailbreakAnalysisResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Analysis result for jailbreak. + internal JailbreakAnalysisResult(bool detected) + { + Detected = detected; + } + + /// Initializes a new instance of . + /// Analysis result for jailbreak. + /// Keeps track of any properties unknown to the library. + internal JailbreakAnalysisResult(bool detected, IDictionary serializedAdditionalRawData) + { + Detected = detected; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal JailbreakAnalysisResult() + { + } + + /// 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 0000000000000..6f4a05caaabd3 --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.ContentSafety +{ + public partial class ProtectedMaterialAnalysisResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ProtectedMaterialAnalysisResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("detected"u8); + writer.WriteBooleanValue(Detected); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ProtectedMaterialAnalysisResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ProtectedMaterialAnalysisResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeProtectedMaterialAnalysisResult(document.RootElement, options); + } + + internal static ProtectedMaterialAnalysisResult DeserializeProtectedMaterialAnalysisResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool detected = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("detected"u8)) + { + detected = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ProtectedMaterialAnalysisResult(detected, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ProtectedMaterialAnalysisResult)} does not support '{options.Format}' format."); + } + } + + ProtectedMaterialAnalysisResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeProtectedMaterialAnalysisResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ProtectedMaterialAnalysisResult)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// 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); + } + + /// 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/ProtectedMaterialAnalysisResult.cs b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.cs new file mode 100644 index 0000000000000..012cf4201ebae --- /dev/null +++ b/sdk/contentsafety/Azure.AI.ContentSafety/src/Generated/ProtectedMaterialAnalysisResult.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.ContentSafety +{ + /// The text protected material analysis response. + public partial class ProtectedMaterialAnalysisResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Analysis result for protected material.. + internal ProtectedMaterialAnalysisResult(bool detected) + { + Detected = detected; + } + + /// Initializes a new instance of . + /// Analysis result for protected material.. + /// Keeps track of any properties unknown to the library. + internal ProtectedMaterialAnalysisResult(bool detected, IDictionary serializedAdditionalRawData) + { + Detected = detected; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ProtectedMaterialAnalysisResult() + { + } + + /// 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 4b8c65fcecd01..08c222afc13cb 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 24a2f85d3f089..3259ebf003c68 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 +directory: specification/cognitiveservices/ContentSafety additionalDirectories: [] repo: Azure/azure-rest-api-specs -directory: specification/cognitiveservices/ContentSafety +commit: a8e35f0892cf9b18ff92af939504c20636d23371