Skip to content

Commit

Permalink
Simplified policy. The new azure-openai-... policies should only be…
Browse files Browse the repository at this point in the history
… applied when the payload only contains text messages.
  • Loading branch information
rliberoff committed Jun 6, 2024
1 parent 2ac583f commit 5766fa2
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions infra/modules/apim/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,7 @@ resource "azurerm_api_management_api_policy" "policy" {
</validate-jwt>
<choose>
<when condition="@(
// Parse the request body as a JObject
context.Request.Body.As<JObject>(preserveContent: true)["messages"]
// Check that all messages...
?.All(message =>
message["content"]
// ...have all content...
.All(content =>
// ...that is either not a JObject...
!(content is JObject)
// ...or is a JObject with a 'type' property that equals 'text'
|| (content is JObject && ((JObject)content).ContainsKey("type") && content["type"].Value<string>() == "text")
)
) == true
)">
<when condition="@(context.Request.Body.As<JObject>(preserveContent: true)["messages"]?.All(message => message["content"].All(content => !(content is JObject))) == true)">
<!-- If all type properties are 'text' or there are no type properties, apply the new Azure OpenAI policies -->
Expand Down

0 comments on commit 5766fa2

Please sign in to comment.