@@ -22,6 +22,9 @@ namespace Microsoft.Extensions.AI.Evaluation.Safety;
22
22
23
23
internal sealed partial class ContentSafetyService ( ContentSafetyServiceConfiguration serviceConfiguration )
24
24
{
25
+ private const string APIVersionForServiceDiscoveryInHubBasedProjects = "?api-version=2023-08-01-preview" ;
26
+ private const string APIVersionForNonHubBasedProjects = "?api-version=2025-05-15-preview" ;
27
+
25
28
private static HttpClient ? _sharedHttpClient ;
26
29
private static HttpClient SharedHttpClient
27
30
{
@@ -168,20 +171,27 @@ private async ValueTask<string> GetServiceUrlAsync(
168
171
return _serviceUrl ;
169
172
}
170
173
171
- string discoveryUrl =
172
- await GetServiceDiscoveryUrlAsync ( evaluatorName , cancellationToken ) . ConfigureAwait ( false ) ;
173
-
174
- serviceUrl =
175
- $ "{ discoveryUrl } /raisvc/v1.0" +
176
- $ "/subscriptions/{ serviceConfiguration . SubscriptionId } " +
177
- $ "/resourceGroups/{ serviceConfiguration . ResourceGroupName } " +
178
- $ "/providers/Microsoft.MachineLearningServices/workspaces/{ serviceConfiguration . ProjectName } ";
174
+ if ( serviceConfiguration . IsHubBasedProject )
175
+ {
176
+ string discoveryUrl =
177
+ await GetServiceDiscoveryUrlAsync ( evaluatorName , cancellationToken ) . ConfigureAwait ( false ) ;
178
+
179
+ serviceUrl =
180
+ $ "{ discoveryUrl } /raisvc/v1.0" +
181
+ $ "/subscriptions/{ serviceConfiguration . SubscriptionId } " +
182
+ $ "/resourceGroups/{ serviceConfiguration . ResourceGroupName } " +
183
+ $ "/providers/Microsoft.MachineLearningServices/workspaces/{ serviceConfiguration . ProjectName } ";
184
+ }
185
+ else
186
+ {
187
+ serviceUrl = $ "{ serviceConfiguration . Endpoint . AbsoluteUri } /evaluations";
188
+ }
179
189
180
190
await EnsureServiceAvailabilityAsync (
181
- serviceUrl ,
182
- capability : annotationTask ,
183
- evaluatorName ,
184
- cancellationToken ) . ConfigureAwait ( false ) ;
191
+ serviceUrl ,
192
+ capability : annotationTask ,
193
+ evaluatorName ,
194
+ cancellationToken ) . ConfigureAwait ( false ) ;
185
195
186
196
_ = _serviceUrlCache . TryAdd ( key , serviceUrl ) ;
187
197
_serviceUrl = serviceUrl ;
@@ -196,7 +206,7 @@ private async ValueTask<string> GetServiceDiscoveryUrlAsync(
196
206
$ "https://management.azure.com/subscriptions/{ serviceConfiguration . SubscriptionId } " +
197
207
$ "/resourceGroups/{ serviceConfiguration . ResourceGroupName } " +
198
208
$ "/providers/Microsoft.MachineLearningServices/workspaces/{ serviceConfiguration . ProjectName } " +
199
- $ "?api-version=2023-08-01-preview ";
209
+ $ "{ APIVersionForServiceDiscoveryInHubBasedProjects } ";
200
210
201
211
HttpResponseMessage response =
202
212
await GetResponseAsync (
@@ -244,7 +254,10 @@ private async ValueTask EnsureServiceAvailabilityAsync(
244
254
string evaluatorName ,
245
255
CancellationToken cancellationToken )
246
256
{
247
- string serviceAvailabilityUrl = $ "{ serviceUrl } /checkannotation";
257
+ string serviceAvailabilityUrl =
258
+ serviceConfiguration . IsHubBasedProject
259
+ ? $ "{ serviceUrl } /checkannotation"
260
+ : $ "{ serviceUrl } /checkannotation{ APIVersionForNonHubBasedProjects } ";
248
261
249
262
HttpResponseMessage response =
250
263
await GetResponseAsync (
@@ -297,7 +310,10 @@ private async ValueTask<string> SubmitAnnotationRequestAsync(
297
310
string evaluatorName ,
298
311
CancellationToken cancellationToken )
299
312
{
300
- string annotationUrl = $ "{ serviceUrl } /submitannotation";
313
+ string annotationUrl =
314
+ serviceConfiguration . IsHubBasedProject
315
+ ? $ "{ serviceUrl } /submitannotation"
316
+ : $ "{ serviceUrl } /submitannotation{ APIVersionForNonHubBasedProjects } ";
301
317
302
318
HttpResponseMessage response =
303
319
await GetResponseAsync (
@@ -426,10 +442,13 @@ private async ValueTask AddHeadersAsync(
426
442
427
443
httpRequestMessage . Headers . Add ( "User-Agent" , userAgent ) ;
428
444
445
+ TokenRequestContext context =
446
+ serviceConfiguration . IsHubBasedProject
447
+ ? new TokenRequestContext ( scopes : [ "https://management.azure.com/.default" ] )
448
+ : new TokenRequestContext ( scopes : [ "https://ai.azure.com/.default" ] ) ;
449
+
429
450
AccessToken token =
430
- await serviceConfiguration . Credential . GetTokenAsync (
431
- new TokenRequestContext ( scopes : [ "https://management.azure.com/.default" ] ) ,
432
- cancellationToken ) . ConfigureAwait ( false ) ;
451
+ await serviceConfiguration . Credential . GetTokenAsync ( context , cancellationToken ) . ConfigureAwait ( false ) ;
433
452
434
453
httpRequestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , token . Token ) ;
435
454
0 commit comments