/// <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> Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be expected for it. </summary> /// <param name="eventId"> The event ID to be activated. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual Response Activate(string eventId, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("PersonalizerClient.Activate"); scope.Start(); try { return(EventsRestClient.Activate(eventId, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be expected for it. </summary> /// <param name="eventId"> The event ID to be activated. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual async Task <Response> ActivateAsync(string eventId, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("PersonalizerClient.Activate"); scope.Start(); try { return(await EventsRestClient.ActivateAsync(eventId, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the specified event. </summary> /// <param name="eventId"> The event id this reward applies to. </param> /// <param name="reward"> 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 Response Reward(string eventId, float reward, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("PersonalizerClient.Reward"); scope.Start(); try { PersonalizerRewardOptions rewardOptions = new PersonalizerRewardOptions(reward); return(EventsRestClient.Reward(eventId, rewardOptions, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the specified event. </summary> /// <param name="eventId"> The event id this reward applies to. </param> /// <param name="reward"> 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> RewardAsync(string eventId, float reward, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("PersonalizerClient.Reward"); scope.Start(); try { PersonalizerRewardOptions rewardOptions = new PersonalizerRewardOptions(reward); return(await EventsRestClient.RewardAsync(eventId, rewardOptions, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public EventsClient(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 EventsRestClient(_clientDiagnostics, _pipeline, endpoint); }
public EventsClient(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 EventsRestClient(_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> Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be expected for it. </summary> /// <param name="eventId"> The event ID to be activated. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual Response Activate(string eventId, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("PersonalizerClient.Activate"); scope.Start(); try { if (useLocalInference) { validateAndUpdateLiveModelConfig(); return(rlNetProcessor.Value.Activate(eventId)); } else { return(EventsRestClient.Activate(eventId, cancellationToken)); } } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the specified event. </summary> /// <param name="eventId"> The event id this reward applies to. </param> /// <param name="reward"> 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> RewardAsync(string eventId, float reward, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("PersonalizerClient.Reward"); scope.Start(); try { PersonalizerRewardOptions rewardOptions = new PersonalizerRewardOptions(reward); if (useLocalInference) { validateAndUpdateLiveModelConfig(); return(rlNetProcessor.Value.Reward(eventId, reward)); } else { return(await EventsRestClient.RewardAsync(eventId, rewardOptions, cancellationToken).ConfigureAwait(false)); } } catch (Exception e) { scope.Failed(e); throw; } }
internal EventsClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) { RestClient = new EventsRestClient(clientDiagnostics, pipeline, endpoint); _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; }