-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathastaieus-policy.xml
More file actions
70 lines (70 loc) · 7.7 KB
/
Copy pathastaieus-policy.xml
File metadata and controls
70 lines (70 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<policies>
<inbound>
<base />
<set-backend-service id="apim-generated-policy" backend-id="astai-pool" />
<choose>
<when condition="@(context.Variables.ContainsKey("tokenlimit-"+(string)context.Request.Foundry.Deployment) || context.Variables.ContainsKey("tokenquota-"+(string)context.Request.Foundry.Deployment))">
<set-variable name="deploymentName" value="@((string)context.Request.Foundry.Deployment)" />
<set-variable name="counterKey" value="@("product/"+ context.Product?.Id + "/deployment/" + (string)context.Variables["deploymentName"])" />
<set-variable name="limitVariableName" value="@("tokenlimit-"+(string)context.Variables["deploymentName"])" />
<set-variable name="quotaVariableName" value="@("tokenquota-"+(string)context.Variables["deploymentName"])" />
<set-variable name="tokenLimitValue" value="@(context.Variables.ContainsKey((string)context.Variables["limitVariableName"]) ? (string)context.Variables[(string)context.Variables["limitVariableName"]] : null)" />
<set-variable name="tokenQuotaValue" value="@(context.Variables.ContainsKey((string)context.Variables["quotaVariableName"]) ? ((string)context.Variables[(string)context.Variables["quotaVariableName"]]).Split('|')[0] : null)" />
<set-variable name="tokenQuotaPeriod" value="@(context.Variables.ContainsKey((string)context.Variables["quotaVariableName"]) ? (((string)context.Variables[(string)context.Variables["quotaVariableName"]]).Split('|').Length > 1 ? ((string)context.Variables[(string)context.Variables["quotaVariableName"]]).Split('|')[1] : null) : null)" />
<choose>
<when condition="@(context.Variables.ContainsKey((string)context.Variables["limitVariableName"]) && context.Variables.ContainsKey((string)context.Variables["quotaVariableName"]))">
<choose>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Hourly")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" tokens-per-minute="@(int.Parse((context.Variables["tokenLimitValue"] as string) ?? "0"))" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Hourly" estimate-prompt-tokens="false" />
</when>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Daily")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" tokens-per-minute="@(int.Parse((context.Variables["tokenLimitValue"] as string) ?? "0"))" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Daily" estimate-prompt-tokens="false" />
</when>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Weekly")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" tokens-per-minute="@(int.Parse((context.Variables["tokenLimitValue"] as string) ?? "0"))" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Weekly" estimate-prompt-tokens="false" />
</when>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Monthly")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" tokens-per-minute="@(int.Parse((context.Variables["tokenLimitValue"] as string) ?? "0"))" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Monthly" estimate-prompt-tokens="false" />
</when>
<otherwise>
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" tokens-per-minute="@(int.Parse((context.Variables["tokenLimitValue"] as string) ?? "0"))" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Yearly" estimate-prompt-tokens="false" />
</otherwise>
</choose>
</when>
<when condition="@(context.Variables.ContainsKey((string)context.Variables["limitVariableName"]))">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" tokens-per-minute="@(int.Parse((context.Variables["tokenLimitValue"] as string) ?? "0"))" estimate-prompt-tokens="false" />
</when>
<otherwise>
<choose>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Hourly")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Hourly" estimate-prompt-tokens="false" />
</when>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Daily")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Daily" estimate-prompt-tokens="false" />
</when>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Weekly")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Weekly" estimate-prompt-tokens="false" />
</when>
<when condition="@(((string)context.Variables["tokenQuotaPeriod"]) == "Monthly")">
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Monthly" estimate-prompt-tokens="false" />
</when>
<otherwise>
<llm-token-limit counter-key="@((string)context.Variables["counterKey"])" token-quota="@(long.Parse((context.Variables["tokenQuotaValue"] as string) ?? "0"))" token-quota-period="Yearly" estimate-prompt-tokens="false" />
</otherwise>
</choose>
</otherwise>
</choose>
</when>
<otherwise />
</choose>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>