diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/PromptBox.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/PromptBox.xaml.cs index 334d23ebd390..01e4db575f4d 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/PromptBox.xaml.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/PromptBox.xaml.cs @@ -78,8 +78,6 @@ private void GenerateCustom() { Logger.LogTrace(); - PowerToysTelemetry.Log.WriteEvent(new Telemetry.AdvancedPasteGenerateCustomFormatEvent()); - VisualStateManager.GoToState(this, "LoadingState", true); string inputInstructions = InputTxtBox.Text; ViewModel.SaveQuery(inputInstructions); diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs index 8926cb1820f1..94e81c2add26 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs @@ -231,6 +231,7 @@ private async void ClipboardHistory_ItemClick(object sender, ItemClickEventArgs var item = e.ClickedItem as ClipboardItem; if (item is not null) { + PowerToysTelemetry.Log.WriteEvent(new Telemetry.AdvancedPasteClipboardItemClicked()); if (!string.IsNullOrEmpty(item.Content)) { ClipboardHelper.SetClipboardTextContent(item.Content); diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AICompletionsHelper.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AICompletionsHelper.cs index 11c69ff120a7..2dfa803d24fb 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AICompletionsHelper.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AICompletionsHelper.cs @@ -33,6 +33,8 @@ public AICompletionsResponse(string response, int apiRequestStatus) private string _openAIKey; + private string _modelName = "gpt-3.5-turbo-instruct"; + public bool IsAIEnabled => !string.IsNullOrEmpty(this._openAIKey); public AICompletionsHelper() @@ -69,14 +71,14 @@ public static string LoadOpenAIKey() return string.Empty; } - public string GetAICompletion(string systemInstructions, string userMessage) + private Response GetAICompletion(string systemInstructions, string userMessage) { OpenAIClient azureAIClient = new OpenAIClient(_openAIKey); var response = azureAIClient.GetCompletions( new CompletionsOptions() { - DeploymentName = "gpt-3.5-turbo-instruct", + DeploymentName = _modelName, Prompts = { systemInstructions + "\n\n" + userMessage, @@ -90,7 +92,7 @@ public string GetAICompletion(string systemInstructions, string userMessage) Console.WriteLine("Cut off due to length constraints"); } - return response.Value.Choices[0].Text; + return response; } public AICompletionsResponse AIFormatString(string inputInstructions, string inputString) @@ -109,10 +111,16 @@ public AICompletionsResponse AIFormatString(string inputInstructions, string inp "; string aiResponse = null; + Response rawAIResponse = null; int apiRequestStatus = (int)HttpStatusCode.OK; try { - aiResponse = this.GetAICompletion(systemInstructions, userMessage); + rawAIResponse = this.GetAICompletion(systemInstructions, userMessage); + aiResponse = rawAIResponse.Value.Choices[0].Text; + + int promptTokens = rawAIResponse.Value.Usage.PromptTokens; + int completionTokens = rawAIResponse.Value.Usage.CompletionTokens; + PowerToysTelemetry.Log.WriteEvent(new Telemetry.AdvancedPasteGenerateCustomFormatEvent(promptTokens, completionTokens, _modelName)); } catch (Azure.RequestFailedException error) { diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteClipboardItemClicked.cs b/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteClipboardItemClicked.cs new file mode 100644 index 000000000000..3c5b63083770 --- /dev/null +++ b/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteClipboardItemClicked.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics.Tracing; +using Microsoft.PowerToys.Telemetry; +using Microsoft.PowerToys.Telemetry.Events; + +namespace AdvancedPaste.Telemetry +{ + [EventData] + public class AdvancedPasteClipboardItemClicked : EventBase, IEvent + { + public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage; + } +} diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteGenerateCustomFormatEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteGenerateCustomFormatEvent.cs index a3e874f1f81d..d6f9fed41229 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteGenerateCustomFormatEvent.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Telemetry/AdvancedPasteGenerateCustomFormatEvent.cs @@ -11,6 +11,19 @@ namespace AdvancedPaste.Telemetry [EventData] public class AdvancedPasteGenerateCustomFormatEvent : EventBase, IEvent { + public int PromptTokens { get; set; } + + public int CompletionTokens { get; set; } + + public string ModelName { get; set; } + + public AdvancedPasteGenerateCustomFormatEvent(int promptTokens, int completionTokens, string modelName) + { + this.PromptTokens = promptTokens; + this.CompletionTokens = completionTokens; + ModelName = modelName; + } + public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage; } }