@@ -22,6 +22,9 @@ namespace Microsoft.Extensions.AI.Evaluation.Safety;
2222
2323internal sealed partial class ContentSafetyService ( ContentSafetyServiceConfiguration serviceConfiguration )
2424{
25+ private const string APIVersionForServiceDiscoveryInHubBasedProjects = "?api-version=2023-08-01-preview" ;
26+ private const string APIVersionForNonHubBasedProjects = "?api-version=2025-05-15-preview" ;
27+
2528 private static HttpClient ? _sharedHttpClient ;
2629 private static HttpClient SharedHttpClient
2730 {
@@ -168,20 +171,27 @@ private async ValueTask<string> GetServiceUrlAsync(
168171 return _serviceUrl ;
169172 }
170173
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+ }
179189
180190 await EnsureServiceAvailabilityAsync (
181- serviceUrl ,
182- capability : annotationTask ,
183- evaluatorName ,
184- cancellationToken ) . ConfigureAwait ( false ) ;
191+ serviceUrl ,
192+ capability : annotationTask ,
193+ evaluatorName ,
194+ cancellationToken ) . ConfigureAwait ( false ) ;
185195
186196 _ = _serviceUrlCache . TryAdd ( key , serviceUrl ) ;
187197 _serviceUrl = serviceUrl ;
@@ -196,7 +206,7 @@ private async ValueTask<string> GetServiceDiscoveryUrlAsync(
196206 $ "https://management.azure.com/subscriptions/{ serviceConfiguration . SubscriptionId } " +
197207 $ "/resourceGroups/{ serviceConfiguration . ResourceGroupName } " +
198208 $ "/providers/Microsoft.MachineLearningServices/workspaces/{ serviceConfiguration . ProjectName } " +
199- $ "?api-version=2023-08-01-preview ";
209+ $ "{ APIVersionForServiceDiscoveryInHubBasedProjects } ";
200210
201211 HttpResponseMessage response =
202212 await GetResponseAsync (
@@ -244,7 +254,10 @@ private async ValueTask EnsureServiceAvailabilityAsync(
244254 string evaluatorName ,
245255 CancellationToken cancellationToken )
246256 {
247- string serviceAvailabilityUrl = $ "{ serviceUrl } /checkannotation";
257+ string serviceAvailabilityUrl =
258+ serviceConfiguration . IsHubBasedProject
259+ ? $ "{ serviceUrl } /checkannotation"
260+ : $ "{ serviceUrl } /checkannotation{ APIVersionForNonHubBasedProjects } ";
248261
249262 HttpResponseMessage response =
250263 await GetResponseAsync (
@@ -297,7 +310,10 @@ private async ValueTask<string> SubmitAnnotationRequestAsync(
297310 string evaluatorName ,
298311 CancellationToken cancellationToken )
299312 {
300- string annotationUrl = $ "{ serviceUrl } /submitannotation";
313+ string annotationUrl =
314+ serviceConfiguration . IsHubBasedProject
315+ ? $ "{ serviceUrl } /submitannotation"
316+ : $ "{ serviceUrl } /submitannotation{ APIVersionForNonHubBasedProjects } ";
301317
302318 HttpResponseMessage response =
303319 await GetResponseAsync (
@@ -426,10 +442,13 @@ private async ValueTask AddHeadersAsync(
426442
427443 httpRequestMessage . Headers . Add ( "User-Agent" , userAgent ) ;
428444
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+
429450 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 ) ;
433452
434453 httpRequestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , token . Token ) ;
435454
0 commit comments