Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.26k stars 4.61k forks source link

[BUG] Content filter unexpectedly jumps in #38820

Open MarcosCobena opened 1 year ago

MarcosCobena commented 1 year ago

Library name and version

Azure.AI.OpenAI 1.0.0-beta.5 & beta.7

Describe the bug

If you query for chat completions with just an user prompt with value "violín" (the musical instrument, in Spanish), the content filter jumps in and the request fails. If you do exactly the same through the Playground at Azure, you get a valid response from the assistant, as expected.

Expected behavior

A successful response with any message related with the musical instrument.

Actual behavior

Azure.RequestFailedException
  HResult=0x80131500
  Message=The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766
Status: 400 (model_error)
ErrorCode: content_filter

Content:
{"error":{"message":"The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766","type":null,"param":"prompt","code":"content_filter","status":400}}

Headers:
X-Request-ID: REDACTED
ms-azureml-model-error-reason: REDACTED
ms-azureml-model-error-statuscode: REDACTED
x-ms-client-request-id: 0fa58af4-9371-4532-86bb-efdd1159a8df
apim-request-id: REDACTED
azureml-model-session: REDACTED
azureml-model-group: REDACTED
OpenAI-Processing-Ms: REDACTED
Strict-Transport-Security: REDACTED
X-Content-Type-Options: REDACTED
x-ms-region: REDACTED
Date: Tue, 19 Sep 2023 09:39:24 GMT
Content-Length: 355
Content-Type: application/json

  Source=Azure.AI.OpenAI
  StackTrace:
   at Azure.Core.HttpPipelineExtensions.<ProcessMessageAsync>d__0.MoveNext() in /_1/microsoft.azure.autorest.csharp/3.0.0-beta.20230321.1/content/Generator.Shared/HttpPipelineExtensions.cs:line 32
   at Azure.AI.OpenAI.OpenAIClient.<GetChatCompletionsAsync>d__17.MoveNext() in /_/sdk/openai/Azure.AI.OpenAI/src/Custom/OpenAIClient.cs:line 407
   at Program.<<Main>$>d__0.MoveNext() in C:\Temporal\ConsoleApp1\ConsoleApp1\Program.cs:line 21
   at Program.<Main>(String[] args)

Reproduction Steps

Replace every TODO before running. We are using GPT-3.5 Turbo.

using Azure;
using Azure.AI.OpenAI;

OpenAIClient client = new OpenAIClient(
    new Uri("TODO"),
    new AzureKeyCredential("TODO"));
Response<ChatCompletions> responseWithoutStream = await client.GetChatCompletionsAsync(
    "TODO",
    new ChatCompletionsOptions()
    {
        Messages =
        {
            new ChatMessage(ChatRole.User, "violín"),
        },
        Temperature = (float)0.3,
        MaxTokens = 500,
        NucleusSamplingFactor = (float)0.95,
        FrequencyPenalty = 0,
        PresencePenalty = 0,
    });
ChatCompletions completions = responseWithoutStream.Value;

Environment

Microsoft Visual Studio Professional 2022 Version 17.6.0 VisualStudio.17.Release/17.6.0+33712.159 Microsoft .NET Framework Version 4.8.09032

Installed Version: Professional

Visual C++ 2022 00476-80000-00000-AA890 Microsoft Visual C++ 2022

ASP.NET and Web Tools 17.6.326.62524 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.6.326.62524 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.6.326.62524 Azure Functions and Web Jobs Tools

C# Tools 4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

CleanBinAndObjCommand Extension 1.2.58 CleanBinAndObjCommand Visual Studio Extension Detailed Info

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Edit Project 1.7.72 An open source Visual Studio extension to add the context menu for editing project/solution file.

Extensibility Message Bus 1.4.21 (main@8f226a8) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fine Code Coverage fcc-f339fe606-9d51-4fca-895c-d50375137b62 Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)

ILSpy.AddIn 1.0 Integration of the ILSpy Decompiler into Visual Studio.

Markdown Editor v2 2.0.143 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.6.41 (790a401) Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.5.50201.1 Commit Hash:0a76e2b03608f2fdee0e7d2e38e83d7721149b5f Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 6.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.6.0.2326105+37f2727000f6a964584cafb86e69cf0b39baecb7 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.6.13.0 Microsoft SQL Server Data Tools

StylerPackage Extension 1.0 StylerPackage Visual Stuido Extension Detailed Info

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 17.0.20329.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.6.0-beta.23174.5+0207bea1afae48d9351ac26fb51afc8260de0a97 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.6.0.251 (d17-6@318364c) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.6.6.0 (remotes/origin/d17-6@cb430751d1) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.0.6 (d17-5/a200af1) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 6dd9def Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@9f02d77

MarcosCobena commented 1 year ago

If you replace "violín" with "violin" (notice the lack of accent), it works as expected.

MarcosCobena commented 1 year ago

The same test with Python SDK also works as expected.

MarcosCobena commented 1 year ago

Fiddler showed some light:

{"messages":[{"role":"user","content":"viol\u00EDn"}],"max_tokens":500,"temperature":0.3,"top_p":0.95,"presence_penalty":0,"frequency_penalty":0}