-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cognitive Services RaiPolicy sending invalid content according to the ARM API response #3022
Comments
The request the provider generates looks identical to the example (as it should). Could the problem be that the |
@thomas11 asked the customer, and you have to apply to disable the content filter but not to modify it. Both me and them can create the resource manually. |
@pierskarsenbarg manually in what way - Azure portal, |
@thomas11 Azure portal It looks like we might be missing an input in our resource. The ARM docs reference a I can see it in the version of the spec that we're referencing: https://github.com/Azure/azure-rest-api-specs/blob/8b5aae78857c5f3cc4ecd41a4c084c884816e964/specification/cognitiveservices/resource-manager/Microsoft.CognitiveServices/preview/2023-10-01-preview/cognitiveservices.json#L5485 But it's not in our SDKs (node for example: https://github.com/pulumi/pulumi-azure-native/blob/master/sdk/nodejs/cognitiveservices/v20231001preview/raiPolicy.ts) We do reference it as an output (docs and here in the .NET SDK since the nodejs outputs file is too big to show in github) So I think we're missing a property |
Thanks for digging into this, @pierskarsenbarg. The |
@thomas11 Terraform uses the property in their implementation: hashicorp/terraform-provider-azurerm#22822. |
@smcmanis that's a good find, although the issue you linked is still open so it doesn't seem Terraform supports this yet. One of the commenters managed to do it via I don't understand how they're using API version 2023-06-01-preview - it doesn't exist in the API spec. Independent of that, I used the payload @pierskarsenbarg captured to make requests directly using the REST API I also tried the above with API version 2023-06-01-preview, which does indeed exist although undocumented. Made no difference for me, though. |
Hey @pierskarsenbarg and @smcmanis! After much trial and error with the woefully under-documented Cognitive Services API, I think I found the problem. It's a bug (or two) in the Azure spec for this endpoint, but fortunately, you can work around it on your end. First issue: the contentFilters: [
{
name: "hate",
allowedContentLevel: AllowedContentLevel.Low,
blocking: true,
source: RaiPolicyContentSource.Completion,
},
{
name: "sexual",
allowedContentLevel: AllowedContentLevel.Low,
blocking: false,
source: RaiPolicyContentSource.Completion,
},
{
name: "violence",
enabled: false,
blocking: false,
source: RaiPolicyContentSource.Completion,
},
{
name: "DefaultHateSpeechBlockList",
enabled: false,
blocking: false,
source: RaiPolicyContentSource.Prompt,
}
], The second issue is with the base policy. I don't think the "112" policy from the sample actually exists, although I could be wrong - I couldn't find any docs on base policies. I found other examples that used A third issue I found is that the I filed bugs against the Azure spec: |
Hi @thomas11, First off, thank you for the in-depth analysis and for pinpointing the potential causes behind the issues we've been facing with the Cognitive Services API. Your effort in experimenting and documenting your findings is appreciated. Upon reviewing your workaround suggestions, it seems that the approaches you've outlined (specifying blocking and source properties in content filters, addressing the base policy confusion, and the Account.kind annotation) align closely with the configuration we've already implemented on our end. To ensure clarity and to aid in further troubleshooting, here are the relevant parts of our Pulumi code reflecting this: import * as resources from "@pulumi/azure-native/resources";
import {
Account,
AllowedContentLevel,
RaiPolicy,
RaiPolicyContentSource,
RaiPolicyMode,
} from '@pulumi/azure-native/cognitiveservices';
const resourceGroup = new resources.ResourceGroup("pk-cognitiveservices-rg");
const account = new Account('cs-account', {
accountName: 'pk-test',
// identity: {},
kind: 'OpenAI',
location: 'westus',
properties: {
customSubDomainName: 'test-subdomain',
networkAcls: {
defaultAction: 'Allow',
ipRules: [],
virtualNetworkRules: [],
},
publicNetworkAccess: 'Enabled',
},
resourceGroupName: resourceGroup.name,
sku: {
name: 'S0',
},
});
new RaiPolicy(`raipolicy-pk`, {
accountName: account.name,
properties: {
basePolicyName: 'Microsoft.Default',
mode: RaiPolicyMode.Default,
contentFilters: [
{
policyName: 'hate',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Prompt,
},
{
policyName: 'sexual',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Prompt,
},
{
policyName: 'violence',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Prompt,
},
{
policyName: 'selfharm',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Prompt,
},
{
policyName: 'hate',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Completion,
},
{
policyName: 'sexual',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Completion,
},
{
policyName: 'violence',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Completion,
},
{
policyName: 'selfharm',
allowedContentLevel: AllowedContentLevel.High,
blocking: true,
enabled: true,
source: RaiPolicyContentSource.Completion,
},
],
},
raiPolicyName: 'pkraipolicyname',
resourceGroupName: resourceGroup.name,
}); Running
I'm curious if there were any specific nuances or additional configurations in your successful deployment that might not have been captured in the initial summary. Could you confirm you were able to successfully deploy RaiPolicy using Pulumi without encountering the issues mentioned? Thank you again for your assistance and for filing the bugs against the Azure spec. |
Hi @smcmanis, yes, I was able to successfully a RaiPolicy. In fact, just now I was even able to deploy your above program, verbatim! I see the policy in the portal, too. I'm currently puzzled as to what the difference might be. The Pulumi program is the same, your provider version is very recent as well. What's the output of |
FWIW - I just tried the code in #3022 (comment) as well, and was able to deploy it succesfully. I did have to change |
Thanks @lukehoban and @thomas11. I managed to get it working by upgrading |
I'm glad this worked for you. Yes, the change of |
What happened?
Trying to create a RaiPolicy resource . Using the same properties as in the example on the resource documentation (which is also in the Azure docs.
Getting error message:
Example
Output of
pulumi about
Additional context
I have a log file. Here's a snippet including the PUT request:
and the response:
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: