/// <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; }
public MultiSlotEventsClient(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 MultiSlotEventsRestClient(_clientDiagnostics, _pipeline, endpoint); }
public MultiSlotEventsClient(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 MultiSlotEventsRestClient(_clientDiagnostics, _pipeline, endpoint); }
/// <summary> Report that the specified event was actually used or displayed to the user and a rewards should be expected for it. </summary> /// <param name="eventId"> The event ID this activation applies to. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual Response ActivateMultiSlot(string eventId, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("PersonalizerClient.ActivateMultiSlot"); scope.Start(); try { if (useLocalInference) { validateAndUpdateLiveModelConfig(); return(rlNetProcessor.Value.Activate(eventId)); } else { return(MultiSlotEventsRestClient.Activate(eventId, cancellationToken)); } } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> Report reward that resulted from using the action specified in rewardActionId for the slot. </summary> /// <param name="eventId"> The event id this reward applies to. </param> /// <param name="options"> List of slot id and reward values. The reward should be a floating point number, typically between 0 and 1. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual async Task <Response> RewardMultiSlotAsync(string eventId, PersonalizerRewardMultiSlotOptions options, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("PersonalizerClient.RewardMultiSlot"); scope.Start(); try { if (useLocalInference) { validateAndUpdateLiveModelConfig(); return(rlNetProcessor.Value.RewardMultiSlot(eventId, options.Reward)); } else { return(await MultiSlotEventsRestClient.RewardAsync(eventId, options, cancellationToken).ConfigureAwait(false)); } } catch (Exception e) { scope.Failed(e); throw; } }
internal MultiSlotEventsClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) { RestClient = new MultiSlotEventsRestClient(clientDiagnostics, pipeline, endpoint); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; }