From ee1dba515f98f06fc94156de045e7607e1081c1f Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Wed, 11 Dec 2024 14:16:47 +0800 Subject: [PATCH 01/14] init --- Directory.Packages.props | 20 +++++++++---------- .../AdvancedPaste/AdvancedPaste.csproj | 11 +++++----- .../AdvancedPaste/Helpers/NativeMethods.cs | 2 +- .../AdvancedPaste/Helpers/UserSettings.cs | 2 +- .../AdvancedPasteJsonSerializerContext.cs | 13 ++++++++++++ .../AdvancedPaste/Models/CustomQuery.cs | 6 +++--- 6 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 src/modules/AdvancedPaste/AdvancedPaste/Models/AdvancedPasteJsonSerializerContext.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 8430646b54eb..6b803f8aaa1f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,15 +5,15 @@ - - - - - - - - - + + + + + + + + + @@ -57,7 +57,7 @@ - + diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPaste.csproj b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPaste.csproj index c8ea965a4d7a..cec0fa7baaa3 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPaste.csproj +++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPaste.csproj @@ -2,6 +2,7 @@ + WinExe @@ -50,10 +51,10 @@ - - - - + + + + @@ -74,7 +75,7 @@ - VSTHRD002;VSTHRD110;VSTHRD100;VSTHRD200;VSTHRD101 + VSTHRD002;VSTHRD110;VSTHRD100;VSTHRD200;VSTHRD101;IL2059 @@ -75,7 +75,7 @@ - VSTHRD002;VSTHRD110;VSTHRD100;VSTHRD200;VSTHRD101;IL2059 + VSTHRD002;VSTHRD110;VSTHRD100;VSTHRD200;VSTHRD101 - WinExe From ff532d07720578645a6106e683604c6b9d0ca936 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Thu, 19 Dec 2024 13:39:20 +0800 Subject: [PATCH 07/14] Merge main and clean up new AOT build issue --- .../AdvancedPasteJsonSerializerContext.cs | 15 +++++++++++++ .../AdvancedPaste/Helpers/LogEvent.cs | 21 +++++++++++++++++++ .../AdvancedPasteJsonSerializerContext.cs | 13 ------------ .../Models/KernelQueryCache/PersistedCache.cs | 12 ++--------- .../Services/KernelServiceBase.cs | 5 ++--- .../OpenAI/CustomTextTransformService.cs | 4 ++-- 6 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs create mode 100644 src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs delete mode 100644 src/modules/AdvancedPaste/AdvancedPaste/Models/AdvancedPasteJsonSerializerContext.cs diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs new file mode 100644 index 000000000000..1593c1014d52 --- /dev/null +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs @@ -0,0 +1,15 @@ +// 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.Text.Json.Serialization; +using AdvancedPaste.Models.KernelQueryCache; + +namespace AdvancedPaste.Helpers; + +[JsonSerializable(typeof(PersistedCache))] +[JsonSerializable(typeof(LogEvent))] +[JsonSourceGenerationOptions(UseStringEnumConverter = true)] +public sealed partial class AdvancedPasteJsonSerializerContext : JsonSerializerContext +{ +} diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs new file mode 100644 index 000000000000..768f2466e0bf --- /dev/null +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs @@ -0,0 +1,21 @@ +// 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.Text.Json; +using AdvancedPaste.Models.KernelQueryCache; + +namespace AdvancedPaste.Helpers +{ + public class LogEvent + { + public LogEvent(object message) + { + this.message = message; + } + + private object message; + + public string ToJsonString() => JsonSerializer.Serialize(this, AdvancedPasteJsonSerializerContext.Default.PersistedCache); + } +} diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Models/AdvancedPasteJsonSerializerContext.cs b/src/modules/AdvancedPaste/AdvancedPaste/Models/AdvancedPasteJsonSerializerContext.cs deleted file mode 100644 index f17233d53f14..000000000000 --- a/src/modules/AdvancedPaste/AdvancedPaste/Models/AdvancedPasteJsonSerializerContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -// 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.Text.Json.Serialization; - -namespace AdvancedPaste.Models -{ - [JsonSerializable(typeof(CustomQuery))] - internal sealed partial class AdvancedPasteJsonSerializerContext : JsonSerializerContext - { - } -} diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs b/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs index 928ba7ab3751..6a20e663f1ba 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs @@ -15,15 +15,7 @@ public sealed class PersistedCache : ISettingsConfig { public record class CacheItem(CacheKey CacheKey, CacheValue CacheValue); - private static readonly JsonSerializerOptions SerializerOptions = new() - { - Converters = - { - new JsonStringEnumConverter(), - }, - }; - - public static PersistedCache FromJsonString(string json) => JsonSerializer.Deserialize(json, SerializerOptions); + public static PersistedCache FromJsonString(string json) => JsonSerializer.Deserialize(json, AdvancedPasteJsonSerializerContext.Default.PersistedCache); public string Version { get; init; } @@ -31,7 +23,7 @@ public record class CacheItem(CacheKey CacheKey, CacheValue CacheValue); public string GetModuleName() => Constants.AdvancedPasteModuleName; - public string ToJsonString() => JsonSerializer.Serialize(this, SerializerOptions); + public string ToJsonString() => JsonSerializer.Serialize(this, AdvancedPasteJsonSerializerContext.Default.PersistedCache); public override string ToString() => ToJsonString(); diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs b/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs index 08526d0b0cc7..cb5c0ee1da63 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs @@ -174,9 +174,8 @@ private void LogResult(bool cacheUsed, bool isSavedQuery, IEnumerable TransformTextAsync(string prompt, string inputText) AdvancedPasteGenerateCustomFormatEvent telemetryEvent = new(usage.PromptTokens, usage.CompletionTokens, ModelName); PowerToysTelemetry.Log.WriteEvent(telemetryEvent); - var logEvent = new { telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName }; - Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {JsonSerializer.Serialize(logEvent)}"); + var logEvent = new LogEvent(new { telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName }); + Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {logEvent.ToJsonString()}"); return response.Choices[0].Text; } From dcd9603110b431cbe1bfdfe33b3cf15d77a28118 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Tue, 24 Dec 2024 16:52:16 +0800 Subject: [PATCH 08/14] Update LogEvent define. --- .../AdvancedPaste/Helpers/LogEvent.cs | 39 +++++++++++++++++-- .../Services/KernelServiceBase.cs | 2 +- .../OpenAI/CustomTextTransformService.cs | 2 +- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs index 768f2466e0bf..011615f76fb0 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs @@ -4,17 +4,50 @@ using System.Text.Json; using AdvancedPaste.Models.KernelQueryCache; +using AdvancedPaste.Telemetry; namespace AdvancedPaste.Helpers { public class LogEvent { - public LogEvent(object message) + public LogEvent(bool cacheUsed, bool isSavedQuery, int promptTokens, int completionTokens, string modelName, string actionChain) { - this.message = message; + CacheUsed = cacheUsed; + IsSavedQuery = isSavedQuery; + PromptTokens = promptTokens; + CompletionTokens = completionTokens; + ModelName = modelName; + ActionChain = actionChain; } - private object message; + public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernalFormatEvent) + { + CacheUsed = semanticKernalFormatEvent.CacheUsed; + IsSavedQuery = semanticKernalFormatEvent.IsSavedQuery; + PromptTokens = semanticKernalFormatEvent.PromptTokens; + CompletionTokens = semanticKernalFormatEvent.CompletionTokens; + ModelName = semanticKernalFormatEvent.ModelName; + ActionChain = semanticKernalFormatEvent.ActionChain; + } + + public LogEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent) + { + PromptTokens = generateCustomFormatEvent.PromptTokens; + CompletionTokens = generateCustomFormatEvent.CompletionTokens; + ModelName = generateCustomFormatEvent.ModelName; + } + + public bool IsSavedQuery { get; set; } + + public bool CacheUsed { get; set; } + + public int PromptTokens { get; set; } + + public int CompletionTokens { get; set; } + + public string ModelName { get; set; } + + public string ActionChain { get; set; } public string ToJsonString() => JsonSerializer.Serialize(this, AdvancedPasteJsonSerializerContext.Default.PersistedCache); } diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs b/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs index cb5c0ee1da63..f4094e169586 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs @@ -174,7 +174,7 @@ private void LogResult(bool cacheUsed, bool isSavedQuery, IEnumerable TransformTextAsync(string prompt, string inputText) var usage = response.Usage; AdvancedPasteGenerateCustomFormatEvent telemetryEvent = new(usage.PromptTokens, usage.CompletionTokens, ModelName); PowerToysTelemetry.Log.WriteEvent(telemetryEvent); + var logEvent = new LogEvent(telemetryEvent); - var logEvent = new LogEvent(new { telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName }); Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {logEvent.ToJsonString()}"); return response.Choices[0].Text; From fbef3272e5c58ec4b6623ab77cb0f5658f3fb33b Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Tue, 24 Dec 2024 17:00:17 +0800 Subject: [PATCH 09/14] Add Kernal to spell check allow list. --- .github/actions/spell-check/allow/code.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/spell-check/allow/code.txt b/.github/actions/spell-check/allow/code.txt index 8c53e5282757..25f8ab6057f9 100644 --- a/.github/actions/spell-check/allow/code.txt +++ b/.github/actions/spell-check/allow/code.txt @@ -262,3 +262,6 @@ leilzh #Tools OIP + +# SemanticKernal +Kernal From eddcb1c19bb8dc045248e532a7c6541f9cb704f3 Mon Sep 17 00:00:00 2001 From: moooyo <42196638+moooyo@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:38:04 +0800 Subject: [PATCH 10/14] Update src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs Co-authored-by: Jeremy Sinclair <4016293+snickler@users.noreply.github.com> --- src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs index 011615f76fb0..e1234136861f 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs @@ -20,7 +20,7 @@ public LogEvent(bool cacheUsed, bool isSavedQuery, int promptTokens, int complet ActionChain = actionChain; } - public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernalFormatEvent) + public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernelFormatEvent) { CacheUsed = semanticKernalFormatEvent.CacheUsed; IsSavedQuery = semanticKernalFormatEvent.IsSavedQuery; From 1aca55fd30420895bc1cf288bdfa0b0ab0366c68 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Mon, 30 Dec 2024 14:22:04 +0800 Subject: [PATCH 11/14] update typo bug --- .../AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs index e1234136861f..afddbf5dc3e4 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs @@ -22,12 +22,12 @@ public LogEvent(bool cacheUsed, bool isSavedQuery, int promptTokens, int complet public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernelFormatEvent) { - CacheUsed = semanticKernalFormatEvent.CacheUsed; - IsSavedQuery = semanticKernalFormatEvent.IsSavedQuery; - PromptTokens = semanticKernalFormatEvent.PromptTokens; - CompletionTokens = semanticKernalFormatEvent.CompletionTokens; - ModelName = semanticKernalFormatEvent.ModelName; - ActionChain = semanticKernalFormatEvent.ActionChain; + CacheUsed = semanticKernelFormatEvent.CacheUsed; + IsSavedQuery = semanticKernelFormatEvent.IsSavedQuery; + PromptTokens = semanticKernelFormatEvent.PromptTokens; + CompletionTokens = semanticKernelFormatEvent.CompletionTokens; + ModelName = semanticKernelFormatEvent.ModelName; + ActionChain = semanticKernelFormatEvent.ActionChain; } public LogEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent) From a362d3305045af7aeb6c1c74cd97373096ea9895 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Mon, 30 Dec 2024 14:23:50 +0800 Subject: [PATCH 12/14] Remove unused allow list item --- .github/actions/spell-check/allow/code.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/actions/spell-check/allow/code.txt b/.github/actions/spell-check/allow/code.txt index 25f8ab6057f9..f9a22162a98c 100644 --- a/.github/actions/spell-check/allow/code.txt +++ b/.github/actions/spell-check/allow/code.txt @@ -261,7 +261,4 @@ onefuzz leilzh #Tools -OIP - -# SemanticKernal -Kernal +OIP \ No newline at end of file From 699df28ef95972894aad7565ce300acb2a6fedde Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Wed, 8 Jan 2025 17:06:58 +0800 Subject: [PATCH 13/14] Create a new folder to place source generation context --- src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs | 3 ++- .../AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs | 5 +++-- .../SourceGenerationContext.cs} | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) rename src/modules/AdvancedPaste/AdvancedPaste/{Helpers/AdvancedPasteJsonSerializerContext.cs => SerializationContext/SourceGenerationContext.cs} (73%) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs index afddbf5dc3e4..61f528a3acc1 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs @@ -4,6 +4,7 @@ using System.Text.Json; using AdvancedPaste.Models.KernelQueryCache; +using AdvancedPaste.SerializationContext; using AdvancedPaste.Telemetry; namespace AdvancedPaste.Helpers @@ -49,6 +50,6 @@ public LogEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent public string ActionChain { get; set; } - public string ToJsonString() => JsonSerializer.Serialize(this, AdvancedPasteJsonSerializerContext.Default.PersistedCache); + public string ToJsonString() => JsonSerializer.Serialize(this, SourceGenerationContext.Default.PersistedCache); } } diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs b/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs index 6a20e663f1ba..721d9a24ed55 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Models/KernelQueryCache/PersistedCache.cs @@ -7,6 +7,7 @@ using System.Text.Json.Serialization; using AdvancedPaste.Helpers; +using AdvancedPaste.SerializationContext; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; namespace AdvancedPaste.Models.KernelQueryCache; @@ -15,7 +16,7 @@ public sealed class PersistedCache : ISettingsConfig { public record class CacheItem(CacheKey CacheKey, CacheValue CacheValue); - public static PersistedCache FromJsonString(string json) => JsonSerializer.Deserialize(json, AdvancedPasteJsonSerializerContext.Default.PersistedCache); + public static PersistedCache FromJsonString(string json) => JsonSerializer.Deserialize(json, SourceGenerationContext.Default.PersistedCache); public string Version { get; init; } @@ -23,7 +24,7 @@ public record class CacheItem(CacheKey CacheKey, CacheValue CacheValue); public string GetModuleName() => Constants.AdvancedPasteModuleName; - public string ToJsonString() => JsonSerializer.Serialize(this, AdvancedPasteJsonSerializerContext.Default.PersistedCache); + public string ToJsonString() => JsonSerializer.Serialize(this, SourceGenerationContext.Default.PersistedCache); public override string ToString() => ToJsonString(); diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs b/src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs similarity index 73% rename from src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs rename to src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs index 1593c1014d52..9e420abd1c62 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AdvancedPasteJsonSerializerContext.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs @@ -3,13 +3,14 @@ // See the LICENSE file in the project root for more information. using System.Text.Json.Serialization; +using AdvancedPaste.Helpers; using AdvancedPaste.Models.KernelQueryCache; -namespace AdvancedPaste.Helpers; +namespace AdvancedPaste.SerializationContext; [JsonSerializable(typeof(PersistedCache))] [JsonSerializable(typeof(LogEvent))] [JsonSourceGenerationOptions(UseStringEnumConverter = true)] -public sealed partial class AdvancedPasteJsonSerializerContext : JsonSerializerContext +public sealed partial class SourceGenerationContext : JsonSerializerContext { } From 31ad8f1c12aa013f8c813232b870692dbbf1291f Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Mon, 20 Jan 2025 17:25:57 +0800 Subject: [PATCH 14/14] Merge main and rename LogEvent to AIServiceFormatEvent --- .../{LogEvent.cs => AIServiceFormatEvent.cs} | 18 ++++-------------- .../SourceGenerationContext.cs | 2 +- .../Services/KernelServiceBase.cs | 2 +- .../OpenAI/CustomTextTransformService.cs | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) rename src/modules/AdvancedPaste/AdvancedPaste/Helpers/{LogEvent.cs => AIServiceFormatEvent.cs} (67%) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AIServiceFormatEvent.cs similarity index 67% rename from src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs rename to src/modules/AdvancedPaste/AdvancedPaste/Helpers/AIServiceFormatEvent.cs index 61f528a3acc1..1ab58bf26943 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Helpers/AIServiceFormatEvent.cs @@ -9,19 +9,9 @@ namespace AdvancedPaste.Helpers { - public class LogEvent + public class AIServiceFormatEvent { - public LogEvent(bool cacheUsed, bool isSavedQuery, int promptTokens, int completionTokens, string modelName, string actionChain) - { - CacheUsed = cacheUsed; - IsSavedQuery = isSavedQuery; - PromptTokens = promptTokens; - CompletionTokens = completionTokens; - ModelName = modelName; - ActionChain = actionChain; - } - - public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernelFormatEvent) + public AIServiceFormatEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernelFormatEvent) { CacheUsed = semanticKernelFormatEvent.CacheUsed; IsSavedQuery = semanticKernelFormatEvent.IsSavedQuery; @@ -31,7 +21,7 @@ public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernelFormatEvent ActionChain = semanticKernelFormatEvent.ActionChain; } - public LogEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent) + public AIServiceFormatEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent) { PromptTokens = generateCustomFormatEvent.PromptTokens; CompletionTokens = generateCustomFormatEvent.CompletionTokens; @@ -50,6 +40,6 @@ public LogEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent public string ActionChain { get; set; } - public string ToJsonString() => JsonSerializer.Serialize(this, SourceGenerationContext.Default.PersistedCache); + public string ToJsonString() => JsonSerializer.Serialize(this, SourceGenerationContext.Default.AIServiceFormatEvent); } } diff --git a/src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs b/src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs index 9e420abd1c62..dadb2d80c112 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/SerializationContext/SourceGenerationContext.cs @@ -9,7 +9,7 @@ namespace AdvancedPaste.SerializationContext; [JsonSerializable(typeof(PersistedCache))] -[JsonSerializable(typeof(LogEvent))] +[JsonSerializable(typeof(AIServiceFormatEvent))] [JsonSourceGenerationOptions(UseStringEnumConverter = true)] public sealed partial class SourceGenerationContext : JsonSerializerContext { diff --git a/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs b/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs index f4094e169586..c988d2f8ced8 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs @@ -174,7 +174,7 @@ private void LogResult(bool cacheUsed, bool isSavedQuery, IEnumerable TransformTextAsync(string prompt, string inputText) var usage = response.Usage; AdvancedPasteGenerateCustomFormatEvent telemetryEvent = new(usage.PromptTokens, usage.CompletionTokens, ModelName); PowerToysTelemetry.Log.WriteEvent(telemetryEvent); - var logEvent = new LogEvent(telemetryEvent); + var logEvent = new AIServiceFormatEvent(telemetryEvent); Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {logEvent.ToJsonString()}");