/// <summary> Initializes a new instance of PersonalizerClient. </summary> /// <param name="endpoint"> Supported Cognitive Services endpoint. </param> /// <param name="credential"> A credential used to authenticate to an Azure Service. </param> /// <param name="options"> The options for configuring the client. </param> public PersonalizerClient(Uri endpoint, TokenCredential credential, PersonalizerClientOptions options = null) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } options ??= new PersonalizerClientOptions(); clientDiagnostics = new ClientDiagnostics(options); pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, scopes)); stringEndpoint = endpoint.AbsoluteUri; RankRestClient = new RankRestClient(clientDiagnostics, pipeline, stringEndpoint); EventsRestClient = new EventsRestClient(clientDiagnostics, pipeline, stringEndpoint); MultiSlotRestClient = new MultiSlotRestClient(clientDiagnostics, pipeline, stringEndpoint); MultiSlotEventsRestClient = new MultiSlotEventsRestClient(clientDiagnostics, pipeline, stringEndpoint); ServiceConfigurationRestClient = new ServiceConfigurationRestClient(clientDiagnostics, pipeline, stringEndpoint); PolicyRestClient = new PolicyRestClient(clientDiagnostics, pipeline, stringEndpoint); tokenCredential = credential; this.useLocalInference = options.UseLocalInference; if (useLocalInference) { validateAndAssignSampleRate(options.SubsampleRate); //lazy load Rankprocessor rlNetProcessor = new Lazy <RlNetProcessor>(() => GetConfigurationForRankProcessor()); } }
/// <summary> Initializes a new instance of MultiSlotEventsClient. </summary> /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> /// <param name="endpoint"> Supported Cognitive Services endpoint. </param> internal PersonalizerClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint) { string stringEndpoint = endpoint.AbsoluteUri; RankRestClient = new RankRestClient(clientDiagnostics, pipeline, stringEndpoint); EventsRestClient = new EventsRestClient(clientDiagnostics, pipeline, stringEndpoint); MultiSlotRestClient = new MultiSlotRestClient(clientDiagnostics, pipeline, stringEndpoint); MultiSlotEventsRestClient = new MultiSlotEventsRestClient(clientDiagnostics, pipeline, stringEndpoint); this.clientDiagnostics = clientDiagnostics; this.pipeline = pipeline; }
/// <summary> Submit a Personalizer rank request. Receives a context and a list of actions. Returns which of the provided actions should be used by your application, in rewardActionId. </summary> /// <param name="options"> A Personalizer Rank request. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual Response <PersonalizerRankResult> Rank(PersonalizerRankOptions options, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("PersonalizerClient.Rank"); scope.Start(); try { return(RankRestClient.Rank(options, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> Submit a Personalizer rank request. Receives a context and a list of actions. Returns which of the provided actions should be used by your application, in rewardActionId. </summary> /// <param name="options"> A Personalizer Rank request. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual async Task <Response <PersonalizerRankResult> > RankAsync(PersonalizerRankOptions options, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("PersonalizerClient.Rank"); scope.Start(); try { return(await RankRestClient.RankAsync(options, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public RankClient(string endpoint, AzureKeyCredential credential, PersonalizerClientOptions options = null) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } options ??= new PersonalizerClientOptions(); _clientDiagnostics = new ClientDiagnostics(options); _pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, "Ocp-Apim-Subscription-Key")); RestClient = new RankRestClient(_clientDiagnostics, _pipeline, endpoint); }
public RankClient(string endpoint, TokenCredential credential, PersonalizerClientOptions options = null) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } options ??= new PersonalizerClientOptions(); _clientDiagnostics = new ClientDiagnostics(options); string[] scopes = { "https://cognitiveservices.azure.com/.default" }; _pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, scopes)); RestClient = new RankRestClient(_clientDiagnostics, _pipeline, endpoint); }
/// <summary> Initializes a new instance of PersonalizerClient. </summary> /// <param name="endpoint"> Supported Cognitive Services endpoint. </param> /// <param name="credential"> A credential used to authenticate to an Azure Service. </param> /// <param name="options"> The options for configuring the client. </param> public PersonalizerClient(Uri endpoint, AzureKeyCredential credential, PersonalizerClientOptions options = null) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } options ??= new PersonalizerClientOptions(); _clientDiagnostics = new ClientDiagnostics(options); _pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, "Ocp-Apim-Subscription-Key")); string stringEndpoint = endpoint.AbsoluteUri; RankRestClient = new RankRestClient(_clientDiagnostics, _pipeline, stringEndpoint); EventsRestClient = new EventsRestClient(_clientDiagnostics, _pipeline, stringEndpoint); MultiSlotRestClient = new MultiSlotRestClient(_clientDiagnostics, _pipeline, stringEndpoint); MultiSlotEventsRestClient = new MultiSlotEventsRestClient(_clientDiagnostics, _pipeline, stringEndpoint); }
/// <summary> Submit a Personalizer rank request. Receives a context and a list of actions. Returns which of the provided actions should be used by your application, in rewardActionId. </summary> /// <param name="options"> A Personalizer Rank request. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual Response <PersonalizerRankResult> Rank(PersonalizerRankOptions options, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("PersonalizerClient.Rank"); scope.Start(); try { if (useLocalInference) { validateAndUpdateLiveModelConfig(); return(rlNetProcessor.Value.Rank(options)); } else { return(RankRestClient.Rank(options, cancellationToken)); } } catch (Exception e) { scope.Failed(e); throw; } }
internal RankClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) { RestClient = new RankRestClient(clientDiagnostics, pipeline, endpoint); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; }